Advertisement
Guest User

DrGeo.sh

a guest
Oct 8th, 2014
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.59 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. DIR_LOCAL="$HOME/.drgeo"
  4. DIR_SHARE="/usr/share/drgeo2"
  5.  
  6. # usage function
  7. usage (){
  8.     cat <<EOF
  9. usage $0 options :
  10.  
  11. This script run drgeo2 after copying all needed files in \$HOME/.drgeo
  12.  
  13. OPTIONS :
  14.  
  15. -h : print this help
  16. -c : remove all files in your $HOME/.drgeo directory
  17. -f : do a clean start (same as a --clear start and a second one)
  18. -p : launch drgeo2 with a new image file, change won't be saved
  19.  
  20. EOF
  21. }
  22.  
  23. # launching function
  24. launch (){
  25.     cd "$DIR_LOCAL"
  26.     VM="$DIR_LOCAL/Contents/Linux"
  27.     RESOURCES="$DIR_LOCAL/Contents/Resources"
  28.     image="$RESOURCES/drgeo.image"
  29.     # icon (note: gvfs-set-attribute is found in gvfs-bin on Ubuntu
  30.     # systems and it seems to require an absolute filename)
  31.     gvfs-set-attribute \
  32.     "$0" \
  33.     "metadata::custom-icon" \
  34.     "file://$RESOURCES/drgeo.png" \
  35.     2> /dev/null  
  36.    
  37.     # execute
  38.     "$VM/pharo" \
  39.     --plugins "$VM" \
  40.     --encoding utf-8 \
  41.     -vm-display-X11 \
  42.         -title "Dr. Geo" \
  43.         "$image"  
  44. }
  45.  
  46. pre-launch () {
  47.     DIR_SHARE_RC="$DIR_SHARE/Contents/Resources"
  48.     DIR_LOCAL_RC="$DIR_LOCAL/Contents/Resources"
  49.  
  50.     mkdir -p "$DIR_LOCAL/Contents"
  51.     mkdir -p "$DIR_LOCAL/MyExports"
  52.     mkdir -p "$DIR_LOCAL/MySketches"
  53.     mkdir -p "$DIR_LOCAL_RC"
  54.    
  55.     [ -f "$DIR_LOCAL_RC/drgeo.image" ]   || cp "$DIR_SHARE_RC/drgeo.image"   "$DIR_LOCAL_RC/drgeo.image"
  56.     [ -f "$DIR_LOCAL_RC/drgeo.changes" ] || cp "$DIR_SHARE_RC/drgeo.changes" "$DIR_LOCAL_RC/drgeo.changes"
  57.    
  58.     pushd "$DIR_SHARE_RC"
  59.     for file in ./*; do
  60.     [ -f "$DIR_LOCAL_RC/$file" ] || ln -s "$DIR_SHARE_RC/$file" "$DIR_LOCAL_RC/$file"
  61.     done
  62.     popd
  63.    
  64.     [ -f "$DIR_LOCAL/splash.bmp" ]     || ln -s "$DIR_SHARE/splash.bmp"     "$DIR_LOCAL/splash.bmp"
  65.     [ -f "$DIR_LOCAL/Contents/Linux" ] || ln -s "$DIR_SHARE/Contents/Linux" "$DIR_LOCAL/Contents/Linux"
  66.     [ -f "$DIR_LOCAL/locale" ]         || ln -s "$DIR_SHARE/locale"         "$DIR_LOCAL/locale"
  67. }
  68.  
  69. cleanup() {
  70.     read -p "Do you really want to remove your $DIR_LOCAL directory ? (y/N)" -n 1 -r
  71.     if [[ $REPLY =~ ^[Yy]$ ]]; then
  72.         rm -Rf "$DIR_LOCAL"
  73.     else
  74.         exit 1
  75.     fi
  76. }
  77.  
  78. if [ $# -eq 0 ]; then
  79.     pre-launch
  80.     launch
  81. fi
  82.  
  83. while getopts "hcfp" opt;
  84. do
  85.     case "$opt" in
  86.     h)
  87.         usage
  88.         exit 0
  89.         ;;
  90.     c)
  91.         cleanup
  92.         exit 0
  93.         ;;
  94.     f)
  95.         cleanup
  96.         pre-launch
  97.         launch
  98.         ;;
  99.     p)
  100.         DIR_LOCAL="/tmp/.drgeo"
  101.         rm -Rf "$DIR_LOCAL"
  102.         pre-launch
  103.         launch
  104.         rm -Rf "$DIR_LOCAL"
  105.         ;;
  106.     esac
  107. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement