WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: ondemand script (unsupported)  (Read 3153 times)

Offline jls

  • Hero Member
  • *****
  • Posts: 2135
ondemand script (unsupported)
« on: April 15, 2010, 08:31:39 PM »
this modified version of the ondemand script includes:
  • the extension is dowloaded from the net  if it's not present in local
  • the eventual argument passed to the ondemand item will be passed to the actual program
  • the eventual <extension>.desktop file is modified to launch the ondemand item instead of the actual program
Code: [Select]
#!/bin/sh
# (c) Robert Shingledecker 2009,2010
. /etc/init.d/tc-functions

parseLabel() {
[ -z "$1" ] && exit 1
busybox awk '
{
  startpos=index($0,"Program label=")
  if ( startpos > 0 )
  {
  startpos += 15
  tmpstr = substr($0,startpos)
  endpos = index(tmpstr,">")-2
  label = substr(tmpstr,0,endpos)
  gsub(" ","_",label)
  gsub("([()])","",label)
  print label
  }
} ' "$1"
}

parseBinary() {
[ -z "$1" ] && exit 1
busybox awk '
{
  startpos=index($0,"Program label=")
  if ( startpos > 0 )
  {
  startpos += 15
  tmpstr = substr($0,startpos)
  startpos = index(tmpstr,">")+1
  newstr = substr(tmpstr,startpos)
  endpos = index(newstr,"<")-1
  program = substr(newstr,0,endpos)
  print program
  }
} ' "$1"
}

[ "$DESKTOP" == "flwm" ] || [ "$DESKTOP" == "flwm_topside" ] || exit 1
[ -d /home/"$USER"/.wmx ] || exit 1
[ -s /opt/.tce_dir ] || exit 1
TCEDIR="$(cat /opt/.tce_dir)"
TMP=/tmp/ondemand.$$.tmp
for F in `ls "$TCEDIR"/optional/ | grep -E .tcz$`; do
  [ ! -e /usr/local/tce.installed/${F%.*} ] && echo "$F" >> "$TMP"
done
select "OnDemand Tool for FLWM" "$TMP"
EXTN="$(cat /tmp/select.ans)"
rm "$TMP"
[ "$EXTN" == "" ] && exit
APPNAME="${EXTN%.*}"

[ -d /mnt/test ] || sudo mkdir -p /mnt/test
sudo mount "$TCEDIR"/optional/"$EXTN" /mnt/test -t squashfs -o loop,ro,bs=4096
if [ "$?" == 0 ]; then
   TITLE=""; BINARY=""
   if [ -e /mnt/test/usr/local/tce.menu/${APPNAME} ]; then
      CNT="$(grep 'Program label' /mnt/test/usr/local/tce.menu/${APPNAME}|wc -l)"
      if [ $CNT -eq 1 ]; then
        TITLE="$(parseLabel /mnt/test/usr/local/tce.menu/${APPNAME})"
        BINARY="$(parseBinary /mnt/test/usr/local/tce.menu/${APPNAME})"
      fi
   fi
   #jls_legalize start
   [ -d /mnt/test/usr/local/share/applications ] && APPDESKTOP="$(ls  /mnt/test/usr/local/share/applications | tail -n 1)"
   #jls_legalize end

   busybox umount -d /mnt/test
   if [ "$TITLE" == "" ] || [ "$BINARY" == "" ]; then
#     echo
#     echo "No menu or menu too complex for loading on demand."
#     echo "Please enter TITLE and BINARY, if any: "
#     echo
#     prompt
      [ "$TITLE" == "" ] && TITLE="$APPNAME"
      [ "$BINARY" == "" ] && BINARY="none"
   fi
fi

[ -d /home/"$USER"/.wmx/OnDemand ] || mkdir -p /home/"$USER"/.wmx/OnDemand
FILE=/home/"$USER"/.wmx/OnDemand/"$TITLE"
#jls_legalize start
cat <<EOF> "$FILE"
#bin/sh
[ -e /opt/.tce_dir ] || exit 1
read TCEDIR < /opt/.tce_dir
if [ ! -e /usr/local/tce.installed/$APPNAME ];then
[ -e "\$TCEDIR"/optional/$EXTN ] || tce-load -w "\$TCEDIR"/optional/$EXTN
tce-load -i "\$TCEDIR"/optional/"$EXTN"
if [ ${APPDESKTOP} ]; then
TMP=/tmp/ondemand.\$\$.tmp
sed -n '/^Exec=/!p' /usr/local/share/applications/${APPDESKTOP} > \$TMP
echo "Exec=/home/$USER/.wmx/OnDemand/$TITLE" >> \$TMP
sudo mv -f \$TMP /usr/local/share/applications/${APPDESKTOP}  
fi
fi
if [ "$BINARY" != "none" ]; then
if [ "\${1}" ]; then
"$BINARY" "\${1}" &
else
"$BINARY" &
fi
fi  
EOF
#jls_legalize end
chmod +x "$FILE"
/usr/bin/${DESKTOP}_restart
« Last Edit: April 17, 2010, 07:37:53 PM by roberts »
dCore user

Offline jls

  • Hero Member
  • *****
  • Posts: 2135
Re: ondemand script improved
« Reply #1 on: April 16, 2010, 07:52:11 AM »
second version of the script, changelog;
  • the extension is uninstalled (only if it has a desktop entry and it's mounted) when the app is closed, but the .desktop file remains
  • the .desktop is added to filetool
look in the attachments: there is also the tcz-uninstall script
Code: [Select]
#!/bin/sh
# (c) Robert Shingledecker 2009,2010
# jls_legalize (unsenpopiu@tin.it)
. /etc/init.d/tc-functions

parseLabel() {
[ -z "$1" ] && exit 1
busybox awk '
{
  startpos=index($0,"Program label=")
  if ( startpos > 0 )
  {
  startpos += 15
  tmpstr = substr($0,startpos)
  endpos = index(tmpstr,">")-2
  label = substr(tmpstr,0,endpos)
  gsub(" ","_",label)
  gsub("([()])","",label)
  print label
  }
} ' "$1"
}

parseBinary() {
[ -z "$1" ] && exit 1
busybox awk '
{
  startpos=index($0,"Program label=")
  if ( startpos > 0 )
  {
  startpos += 15
  tmpstr = substr($0,startpos)
  startpos = index(tmpstr,">")+1
  newstr = substr(tmpstr,startpos)
  endpos = index(newstr,"<")-1
  program = substr(newstr,0,endpos)
  print program
  }
} ' "$1"
}

[ "$DESKTOP" == "flwm" ] || [ "$DESKTOP" == "flwm_topside" ] || exit 1
[ -d /home/"$USER"/.wmx ] || exit 1
[ -s /opt/.tce_dir ] || exit 1
TCEDIR="$(cat /opt/.tce_dir)"
TMP=/tmp/ondemand.$$.tmp
for F in `ls "$TCEDIR"/optional/ | grep -E .tcz$`; do
  [ ! -e /usr/local/tce.installed/${F%.*} ] && echo "$F" >> "$TMP"
done
select "OnDemand Tool for FLWM" "$TMP"
EXTN="$(cat /tmp/select.ans)"
rm "$TMP"
[ "$EXTN" == "" ] && exit
APPNAME="${EXTN%.*}"

[ -d /mnt/test ] || sudo mkdir -p /mnt/test
sudo mount "$TCEDIR"/optional/"$EXTN" /mnt/test -t squashfs -o loop,ro,bs=4096
if [ "$?" == 0 ]; then
   TITLE=""; BINARY=""
   if [ -e /mnt/test/usr/local/tce.menu/${APPNAME} ]; then
      CNT="$(grep 'Program label' /mnt/test/usr/local/tce.menu/${APPNAME}|wc -l)"
      if [ $CNT -eq 1 ]; then
        TITLE="$(parseLabel /mnt/test/usr/local/tce.menu/${APPNAME})"
        BINARY="$(parseBinary /mnt/test/usr/local/tce.menu/${APPNAME})"
      fi
   fi
   #jls_legalize start
   [ -d /mnt/test/usr/local/share/applications ] && APPDESKTOP="$(ls  /mnt/test/usr/local/share/applications | tail -n 1)"
   #jls_legalize end

   busybox umount -d /mnt/test
   if [ "$TITLE" == "" ] || [ "$BINARY" == "" ]; then
#     echo
#     echo "No menu or menu too complex for loading on demand."
#     echo "Please enter TITLE and BINARY, if any: "
#     echo
#     prompt
      [ "$TITLE" == "" ] && TITLE="$APPNAME"
      [ "$BINARY" == "" ] && BINARY="none"
   fi
fi

[ -d /home/"$USER"/.wmx/OnDemand ] || mkdir -p /home/"$USER"/.wmx/OnDemand
FILE=/home/"$USER"/.wmx/OnDemand/"$TITLE"
#jls_legalize start
cat <<EOF> "$FILE"
#!/bin/sh
[ -e /opt/.tce_dir ] || exit 1
read TCEDIR < /opt/.tce_dir
if [ ! -e /usr/local/tce.installed/$APPNAME ];then
[ -e "\$TCEDIR"/optional/$EXTN ] || tce-load -w "\$TCEDIR"/optional/$EXTN
tce-load -i "\$TCEDIR"/optional/"$EXTN"

fi
if [ "$BINARY" != "none" ]; then
EOF
if [ $APPDESKTOP ];then
cat <<EOF>> "$FILE"
TMP=/tmp/ondemand.\$\$.tmp
sed -n '/^Exec=/!p' /usr/local/share/applications/${APPDESKTOP} > \$TMP
echo "Exec=/home/$USER/.wmx/OnDemand/$TITLE" >> \$TMP
sudo cp \$TMP /usr/local/share/applications/${APPDESKTOP}  
[ \`grep -E ^usr/local/share/applications/${APPDESKTOP} /opt/.filetool.lst | tail -n 1\` ] || echo usr/local/share/applications/${APPDESKTOP} >> /opt/.filetool.lst
EOF
fi
cat <<EOF>> "$FILE"
if [ "\${1}" ]; then
"$BINARY" "\${1}"
else
"$BINARY"
fi
EOF
if [ $APPDESKTOP ];then
cat <<EOF>> "$FILE"
tcz-uninstall $APPNAME
sudo mv \$TMP /usr/local/share/applications/${APPDESKTOP}  
EOF
fi  
echo fi >> "$FILE"
#jls_legalize end
chmod +x "$FILE"
/usr/bin/${DESKTOP}_restart
« Last Edit: April 17, 2010, 07:36:15 PM by roberts »
dCore user

Offline jls

  • Hero Member
  • *****
  • Posts: 2135
Re: ondemand script (unsupported)
« Reply #2 on: April 16, 2010, 02:09:52 PM »
modified again
dCore user

Offline jls

  • Hero Member
  • *****
  • Posts: 2135
Re: ondemand script (unsupported)
« Reply #3 on: April 17, 2010, 03:41:11 PM »
other changes:
  • if jwn menu entry doesn't exists, the script checks if there is the .desktop in order 2 know the binary name
  • after the app is used  also the eventual corrsponding locale extension is unmounted ( doesn't work if the extension was copied 2 the file system)
note that the tcz-uninstall script is attached in the second post
Code: [Select]
#!/bin/sh
# (c) Robert Shingledecker 2009,2010
# jls_legalize (unsenpopiu@tin.it)
. /etc/init.d/tc-functions

parseLabel() {
[ -z "$1" ] && exit 1
busybox awk '
{
  startpos=index($0,"Program label=")
  if ( startpos > 0 )
  {
  startpos += 15
  tmpstr = substr($0,startpos)
  endpos = index(tmpstr,">")-2
  label = substr(tmpstr,0,endpos)
  gsub(" ","_",label)
  gsub("([()])","",label)
  print label
  }
} ' "$1"
}

parseBinary() {
[ -z "$1" ] && exit 1
busybox awk '
{
  startpos=index($0,"Program label=")
  if ( startpos > 0 )
  {
  startpos += 15
  tmpstr = substr($0,startpos)
  startpos = index(tmpstr,">")+1
  newstr = substr(tmpstr,startpos)
  endpos = index(newstr,"<")-1
  program = substr(newstr,0,endpos)
  print program
  }
} ' "$1"
}

[ "$DESKTOP" == "flwm" ] || [ "$DESKTOP" == "flwm_topside" ] || exit 1
[ -d /home/"$USER"/.wmx ] || exit 1
[ -s /opt/.tce_dir ] || exit 1
TCEDIR="$(cat /opt/.tce_dir)"
TMP=/tmp/ondemand.$$.tmp
for F in `ls "$TCEDIR"/optional/ | grep -E .tcz$`; do
  [ ! -e /usr/local/tce.installed/${F%.*} ] && echo "$F" >> "$TMP"
done
select "OnDemand x FLWM" "$TMP"
EXTN="$(cat /tmp/select.ans)"
rm "$TMP"
[ "$EXTN" == "" ] && exit
APPNAME="${EXTN%.*}"

[ -d /mnt/test ] || sudo mkdir -p /mnt/test
sudo mount "$TCEDIR"/optional/"$EXTN" /mnt/test -t squashfs -o loop,ro,bs=4096
if [ "$?" == 0 ]; then
   TITLE=""; BINARY=""
   if [ -e /mnt/test/usr/local/tce.menu/${APPNAME} ]; then
      CNT="$(grep 'Program label' /mnt/test/usr/local/tce.menu/${APPNAME}|wc -l)"
      if [ $CNT -eq 1 ]; then
        TITLE="$(parseLabel /mnt/test/usr/local/tce.menu/${APPNAME})"
        BINARY="$(parseBinary /mnt/test/usr/local/tce.menu/${APPNAME})"
      fi
   fi
   #jls_legalize start
   if [ -d /mnt/test/usr/local/share/applications ];then
  APPDESKTOP="$(ls  /mnt/test/usr/local/share/applications | tail -n 1)"
  [ "$BINARY" == "" ] && [ "${APPDESKTOP}" ] && BINARY=`awk -F"=" '/Exec/ { print$2 }' "/mnt/test/usr/local/share/applications/${APPDESKTOP}"`
   fi
   #jls_legalize end

   busybox umount -d /mnt/test

   if [ "$TITLE" == "" ] || [ "$BINARY" == "" ]; then
#     echo
#     echo "No menu or menu too complex for loading on demand."
#     echo "Please enter TITLE and BINARY, if any: "
#     echo
#     prompt
      [ "$TITLE" == "" ] && TITLE="$APPNAME"
      [ "$BINARY" == "" ] && BINARY="none"
   fi
fi

[ -d /home/"$USER"/.wmx/OnDemand ] || mkdir -p /home/"$USER"/.wmx/OnDemand
FILE=/home/"$USER"/.wmx/OnDemand/"$TITLE"
#jls_legalize start
cat <<EOF> "$FILE"
#!/bin/sh
[ -e /opt/.tce_dir ] || exit 1
read TCEDIR < /opt/.tce_dir
if [ ! -e /usr/local/tce.installed/$APPNAME ];then
[ -e "\$TCEDIR"/optional/$EXTN ] || tce-load -w "\$TCEDIR"/optional/$EXTN
tce-load -i "\$TCEDIR"/optional/"$EXTN"

fi
if [ "$BINARY" != "none" ]; then
EOF
if [ $APPDESKTOP ];then
cat <<EOF>> "$FILE"
TMP=/tmp/ondemand.\$\$.tmp
sed -n '/^Exec=/!p' /usr/local/share/applications/${APPDESKTOP} > \$TMP
echo "Exec=/home/$USER/.wmx/OnDemand/$TITLE" >> \$TMP
sudo cp \$TMP /usr/local/share/applications/${APPDESKTOP}  
[ \`grep -E ^usr/local/share/applications/${APPDESKTOP} /opt/.filetool.lst | tail -n 1\` ] || echo usr/local/share/applications/${APPDESKTOP} >> /opt/.filetool.lst
EOF
fi
cat <<EOF>> "$FILE"
if [ "\${1}" ]; then
"$BINARY" "\${1}"
else
"$BINARY"
fi
EOF
if [ $APPDESKTOP ];then
cat <<EOF>> "$FILE"
[ /usr/local/tce.installed/$APPNAME-locale ] && tcz-uninstall $APPNAME-locale
tcz-uninstall $APPNAME
sudo mv \$TMP /usr/local/share/applications/${APPDESKTOP}  
EOF
fi  
echo fi >> "$FILE"
#jls_legalize end
chmod +x "$FILE"
/usr/bin/${DESKTOP}_restart
« Last Edit: April 17, 2010, 07:37:07 PM by roberts »
dCore user

Offline jls

  • Hero Member
  • *****
  • Posts: 2135
Re: ondemand script (unsupported)
« Reply #4 on: January 20, 2011, 03:45:18 AM »
I modified again this script:
if an icon is found in the tcz, yaht is placed in ~/.local/share/pixmaps  and the Icon field in the .desktop has the name of the icon.
If the tcz is not found locally is downloaded from the net.
Optional dep: flnotify (a message is shown while dowloading from the net the extension).
A diff file is attached to this message
dCore user