View Single Post
santiago's Avatar
Posts: 518 | Thanked: 334 times | Joined on Mar 2010 @ italy
#228
i'll post a new script this evening i did it, but i didnt save it!

then later i'll finish it

edit:

@DavyP

The script name is excalibur, just becouse it's fast, and powerfull, also easy to remember.. I added more features like

- use the right midlet name in the shortcut
- use the right icon name for the shortcut
- call to gtk-update-icon-cache to see immediately the icon on the shortcut (*** minor maybe fix at the end of this message)
- possibility to remove all files after installation of the midlet, expecially:

$SH file
$JAD file
$JAR file
$DESKTOP shortcut

After the installation, without closing the shell, the excalibur script (for newbies must be on /usr/bin/ with chmod +rwx or 775) will ask you to go on the menu, and to try the midlet.. (maybe you want an auto test that run it with final question about the result?) By now, if you will answer with Y, it will keep the midlet, else it will remove it..


####### Excalibur Script ########

Code:
#!/bin/sh

run-standalone.sh dbus-send --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteInfoprint string:"Welcome to Excalibur Script!"
sleep 2
JAR=$1
if [ ! -f "${JAR}" ]; then
  run-standalone.sh dbus-send --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteInfoprint string:"JAR file does not exist!" && sleep 3
  echo "Usage: excalibur JAR file";
  exit 1
fi

JAD="${JAR%.*}.jad"
if [ -f "${JAD}" ]; then
  echo -n "${JAD} already exists, overwrite the file? (Y/N) "
  read midlet
  answer=$(echo "$midlet" | tr '[:upper:]' '[:lower:]')
  if [ "$answer" != "y" ] && [ "$answer" != "Y" ]; then
    echo "Not overwriting ${JAD} file!"
  else
    rm -f "${JAD}"
  fi
fi

if [ ! -f "${JAD}" ]; then
  unzip -aa -j -p ${JAR} "META-INF/MANIFEST.MF" | sed -e '/^[ \t]*$/d' > "${JAD}"
  echo "MIDlet-Jar-URL: ${JAR}" >> "${JAD}"
  echo "MIDlet-Info-URL: http://" >> "${JAD}"

  FILESIZE=$(stat "${JAR}")
  echo "MIDlet-Jar-Size: ${FILESIZE}" >> "${JAD}"

  echo "${JAD} file created!"
  # find png file
  MIDLET_ICON=`grep "MIDlet-Icon: " $JAD  | sed "s/\MIDlet-Icon://g" | sed 's/\///g' | sed 's/^[ \t]*//'`
  # use the correct name of the icon file
  MIDLET_NAME=`grep "MIDlet-Name: " $JAD | sed /MIDlet-Name:/s/// | sed  's/^[a \t]*//' | sed 's/ .*//'`
  # extract the icon
  UNZIP_ICON=`unzip "$JAR" "$MIDLET_ICON" -d /usr/share/icons/hicolor/scalable/hildon/`
  # rename the icon using the midlet name
  RENAME_ICON=`mv "/usr/share/icons/hicolor/scalable/hildon/$MIDLET_ICON" "/usr/share/icons/hicolor/scalable/hildon/$MIDLET_NAME.png"`
fi

SH="${JAR%.*}.sh"
if [ -f "${SH}" ]; then
  echo -n "${SH} Already exists, overwrite the file? (Y/N) "
  read midlet
  answer=$(echo "$midlet" | tr '[:upper:]' '[:lower:]')
  if [ "$answer" != "y" ] && [ "$answer" != "Y" ]; then
    echo "Not overwriting ${SH} file!"
  else
    rm -f "${SH}"
  fi
fi

if [ ! -f "${SH}" ]; then
  MAINCLASS=`cat $JAD | grep 'MIDlet-1:' | cut -d ',' -f 3`
  READLINKJAR=`readlink -f $JAR`
  echo '#!/bin/sh' > $SH
  echo '' >> $SH
  echo '/opt/phoneme/bin/cvm -Xmx12m -Dmicroedition.profiles=MIDP-2.1 -Dsun.midp.library.name=midp -Dsun.midp.home.path=/opt/phoneme/midp/midp_linux_fb_gcc -Dcom.sun.midp.mainClass.name=com.sun.midp.main.CdcMIDletSuiteLoader sun.misc.MIDPLauncher -suitepath' $READLINKJAR '-jadpath' $JAD -1 $MAINCLASS >> $SH
  chmod a+x $SH
  echo "${SH} file created!"
  READLINK=`readlink -f $SH`
  MIDLET_NAME=`grep "MIDlet-Name: " $JAD | sed /MIDlet-Name:/s/// | sed  's/^[a \t]*//' | sed 's/ .*//'`
  MIDLET_VERSION=`grep "MIDlet-Version: " $JAD  | sed /MIDlet-Version:/s///` 
  echo -e "[Desktop Entry]
Encoding=UTF-8
Version=$MIDLET_VERSION
Type=Application
Name=$MIDLET_NAME
Exec=.$READLINK
Comment=`readlink -f $JAD`
Comment=`readlink -f $JAR`
X-Osso-Type=application/x-executable
Terminal=true
Icon=$MIDLET_NAME" | sudo tee /usr/share/applications/hildon/"$MIDLET_NAME".desktop
  sleep 6
  echo "$MIDLET_NAME added as a desktop shortcut"
  sleep 4
fi

  echo "Does the midlet work fine? Run it and and come back here to say (Y/N)"
  read test
  ICONS_PATH=/usr/share/icons/hicolor/scalable/hildon/
  DESKTOP_PATH=/usr/share/applications/hildon
  answer0=$(echo "$test" | tr '[:upper:]' '[:lower:]')
  if [ "$answer0" != "n" ] && [ "$answer0" != "N" ]; then
  run-standalone.sh dbus-send --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteInfoprint string:"Thanks for using Excalibur Script!" && sleep 3
  exit 1; else
  echo "Write the Midlet Name here: "
  read input_name
  DESKTOP_FILE=`grep "$input_name" $DESKTOP_PATH/* | sed -e 's/[^:]*$//g' | sed -e 's/[:^]//g'`
  SH_FILE=`cat $DESKTOP_FILE | grep "Exec=." | sed /Exec=./s///`
  JAR_FILE=`cat $DESKTOP_FILE | grep ".jar" | sed /Comment=/s///`
  JAD_FILE=`cat $DESKTOP_FILE | grep ".jad" | sed /Comment=/s///`
  ICON_FILE=`cat $DESKTOP_FILE | grep "MIDlet-Name: " | sed /MIDlet-Name:/s/// | sed 's/^[ \t]*//' | sed 's/ //g'`
  echo "Do you want to remove $input_name? (Y/N)"
  read answer
  if [ "$answer" != "y" ] && [ "$answer" != "Y" ]; then
    echo "$input_name not removed!"; else
    echo "Removing all $input_name files . ."
    echo "Remoing $SH_FILE . ."
    sudo rm -rf $SH_FILE
    echo "Removed!"
    echo "Removing $JAR_FILE . ."
    sudo rm -rf $JAR_FILE
    echo "Removed!"
    echo "Removing $JAD_FILE . ."
    sudo rm -rf $JAD_FILE
    echo "Removed!"
    echo "Removing $ICON_FILE . ."
    sudo rm -rf $ICONS_PATH$ICON_FILE*
    echo "Removed!"
    echo "Removing $DESKTOP_FILE . ."
    sudo rm -rf $DESKTOP_FILE
    echo "Removed!"
    echo "All files Removed! Midlet is removed!"
  run-standalone.sh dbus-send --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteInfoprint string:"Thanks for using Excalibur Script!" && sleep 3  fi
  fi
fi

exec /usr/bin/gtk-update-icon-cache

***gtk-update-icon-cache fix***
cause of some strange reason, my device is an example about it, the /usr/bin/gtk-update-icon-cache doesn't work as well, then i searched on this Amazing Talk foundig the Bug Report about /usr/bin/gtk-update-icon-cache. Seems to be that /usr/bin/gtk-update-icon-cache just has one line in:
Code:
#!/bin/sh -e
nothing more, someone fixed it in

Code:
#!/bin/sh -e

     [ -d "$1" ] && touch "$1"
then you just have to edit it and to save it to refresh the Maemo Icon Cache and to see immediately the icons without rebooting maemo. Excalibur script creates a desktop file but if you don't fix it with the method i found you will not see an icon on the created shortcut untill a device reboot

Ciao you all,

Cristian

Last edited by santiago; 2012-02-15 at 21:41.
 

The Following 2 Users Say Thank You to santiago For This Useful Post: