Tiny Core Linux

General TC => Programming & Scripting - Unofficial => Topic started by: jls on April 15, 2010, 11:31:39 PM

Title: ondemand script (unsupported)
Post by: jls on April 15, 2010, 11:31:39 PM
this modified version of the ondemand script includes:
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
Title: Re: ondemand script improved
Post by: jls on April 16, 2010, 10:52:11 AM
second version of the script, changelog;
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
Title: Re: ondemand script (unsupported)
Post by: jls on April 16, 2010, 05:09:52 PM
modified again
Title: Re: ondemand script (unsupported)
Post by: jls on April 17, 2010, 06:41:11 PM
other changes:
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
Title: Re: ondemand script (unsupported)
Post by: jls on January 20, 2011, 06: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