Don't like ads? PRO users don't see any ads ;-)
Guest

MIT Scratch auto-installer script for Linux

By: hilltop on Dec 22nd, 2011  |  syntax: Bash  |  size: 10.29 KB  |  hits: 157  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #!/bin/bash
  2.  
  3. # Install script for MIT Scratch running under Linux, version 0.4 2012/01/18
  4. # PASTE THIS SCRIPT INTO AN EDITOR, AND SAVE AS scratch-install.sh INTO
  5. # YOUR WORKING DIRECTORY, THEN FOLLOW THE INSTRUCTIONS BELOW...
  6.  
  7. # Syntax: sudo bash scratch_install.sh [OPTION..] source_dir | -r | -h
  8. # where OPTION is: '-v squeak_vm_dir' -- path of Squeak executable and plugins
  9. #                  '-a audio_driver' -- override script query
  10. #                  '-f' -- include optional non-X framebuffer support
  11. #                  '-h' -- display help message
  12. #                  '-r' -- uninstall a previous installation
  13. # See: http://my-svn.assembla.com/svn/scratchonlinux/scratch/README
  14.  
  15. # Prerequisites (Debian/Ubuntu/Mint, possibly other .deb based distros):
  16. #  sudo apt-get install build-essential pkg-config squeak-vm  # see note 1
  17. #  sudo apt-get install libglib2.0-dev libpango1.0-dev libcairo2-dev libv4l-dev
  18. # Prerequisites (Fedora/openSUSE [zypper install]):
  19. #  sudo yum install wget gcc make pkgconfig pango-devel cairo-devel libv4l-devel
  20. #  sudo yum install squeak-vm  # or see note 1 below for alternative
  21. # Suggested usage:
  22. #  wget http://info.scratch.mit.edu/sites/infoscratch.media.mit.edu/files/file/source-package/scratch-1.4.0.1.tar.gz
  23. #  tar -zxf scratch-1.4.0.1.tar.gz  # (decompresses to directory 'scratch')
  24. #  make -C scratch/
  25. #  sudo bash scratch_install.sh -a ALSA scratch/  # omit '-a ALSA' for list
  26. # Run 'scratch' in terminal, or from 'Development' sub-menu, and 'scratchfb'
  27. # outside of X if option '-f' was selected
  28.  
  29. # Notes:
  30. # 1 Squeak VM version 4.4 (current) does not work with the Scratch version
  31. #   above.  A solution is to manually install a 4.0.3 .deb from an earlier
  32. #   distro version (eg. Natty/Squeeze).  Alternatively see:
  33. #   http://squeakvm.org/unix/release/ for binary and source downloads.
  34. # 2 Package 'squeak-plugins-scratch' is available in Precise (Ubuntu) and
  35. #   Wheezy (Debian), and removes the need for 'make' above, and also the
  36. #   dev packages, but needs libcairo2, libglib2.0-0 and libpango1.0-0.
  37. # 3 Framebuffer support is experimental at present. For x86/x86_64 the
  38. #   module uvesafb must be loaded ('sudo modprobe uvesafb') and the 'v86d'
  39. #   package is needed.  The 'fbset' package is also needed and 'scratchfb'
  40. #   must be started in a 1024x768 mode or higher ('fbset 1024x768-75').
  41. #   If you wish to start in a hi-res mode by default, use vga=xyz at boot.
  42. #   Also, the user must be a member of group 'video', and permissions
  43. #   on /dev/psaux or /dev/input/mice or /dev/adbmouse must be set to 0666
  44. #   ('sudo adduser <username> video' and 'sudo chmod 0666 /dev/xyz').
  45. #   Running 'scratchfb' as superuser is not recommended.
  46.  
  47. SCRATCH_SRC=""
  48. SCRATCH_SND=""
  49. SCRATCH_INI="/usr/bin/scratch"
  50. SCRATCH_INI_FB="/usr/bin/scratchfb"
  51. SCRATCH_LIB="/usr/lib/scratch"
  52. SCRATCH_DAT="/usr/share/scratch"
  53. SCRATCH_PLG="$SCRATCH_LIB/plugins"
  54. SCRATCH_PLG_OLD="$SCRATCH_LIB/Plugins"
  55. SCRATCH_APP="/usr/share/applications/scratch.desktop"
  56. SCRATCH_ICN="/usr/share/icons/hicolor/48x48/apps/scratch.png"
  57. SCRATCH_TYP="/usr/share/icons/hicolor/48x48/mimetypes/gnome-mime-application-x-scratch-project.png"
  58. SCRATCH_ICH="/usr/share/icons/hicolor/128x128/apps/scratch.png"
  59. SCRATCH_TYH="/usr/share/icons/hicolor/128x128/mimetypes/gnome-mime-application-x-scratch-project.png"
  60. SQUEAK_DIR="/usr/lib/squeak"
  61.  
  62. scratch_framebuffer=""
  63. squeak_plugins_scratch=""
  64. if [ -n "`which dpkg 2>/dev/null`" ] ; then
  65. # echo -n "Looking for squeak-plugins-scratch... "
  66. # if [ -n "`dpkg --list | grep squeak-plugins-scratch`" ] ; then
  67.   if [ -d "/usr/share/doc/squeak-plugins-scratch/" ] ; then
  68.     squeak_plugins_scratch="y"
  69.     echo "Found package 'squeak-plugins-scratch'."
  70.   fi
  71. # else
  72. # echo "This does not appear to be a .deb based distro."
  73. fi
  74.  
  75. while [ "$1" != "" ] ; do
  76.   case $1 in
  77.     -r)
  78.       echo "Removing MIT Scratch..."
  79.       rm $SCRATCH_INI $SCRATCH_INI_FB $SCRATCH_APP
  80.       rm $SCRATCH_ICN $SCRATCH_TYP $SCRATCH_ICH $SCRATCH_TYH
  81.       if [ -d "$SCRATCH_PLG_OLD" ] ; then
  82.         rm -rf $SCRATCH_PLG_OLD
  83.       fi
  84.       if [ -z "$squeak_plugins_scratch" ] ; then
  85.         rm -rf $SCRATCH_LIB
  86.       fi
  87.       rm -rf $SCRATCH_DAT
  88.       exit 0
  89.       ;;
  90.     -h)
  91.       echo "Usage: sudo bash scratch_install.sh [-v squeak_vm_dir] [-a audio_driver] [-f]"
  92.       echo "       -h|-r|source_dir"
  93.       exit 0
  94.       ;;
  95.     -f)
  96.       scratch_framebuffer="y"
  97.       shift
  98.       ;;
  99.     -v)
  100.       if [ -n "$2" ] ; then
  101.         SQUEAK_DIR="$2"
  102.         shift 2
  103.         else
  104.         echo "Error: Option '-v' requires an argument."
  105.         exit 1
  106.       fi
  107.       ;;
  108.     -a)
  109.       if [ -n "$2" ] ; then
  110.         SCRATCH_SND="$2"
  111.         shift 2
  112.         else
  113.         echo "Error: Option '-a' requires an argument."
  114.         exit 1
  115.       fi
  116.       ;;
  117.     -*)
  118.       echo "Error: Unknown option '$1'."
  119.       exit 1
  120.       ;;
  121.     *)
  122.       break
  123.       ;;
  124.   esac
  125. done
  126.  
  127. if [ -n "$1" ] ; then
  128.   SCRATCH_SRC="$1"
  129.   else
  130.   echo "Error: Scratch source directory must be specified."
  131.   exit 1
  132. fi
  133.  
  134. shift
  135. if [ -n "$*" ] ; then
  136.   echo "Error: Trailing arguments not understood: '$*'"
  137.   exit 1
  138. fi
  139.  
  140. if [ -z "$squeak_plugins_scratch" ] ; then
  141.   SCRATCH_MISSING=""
  142.   if [ ! -f "$SCRATCH_SRC/Plugins/ScratchPlugin" ] ; then
  143.     SCRATCH_MISSING="$SCRATCH_MISSING ScratchPlugin"
  144.   fi
  145.   if [ ! -f "$SCRATCH_SRC/Plugins/CameraPlugin" ] ; then
  146.     SCRATCH_MISSING="$SCRATCH_MISSING CameraPlugin"
  147.   fi
  148.   if [ ! -f "$SCRATCH_SRC/Plugins/UnicodePlugin" ] ; then
  149.     SCRATCH_MISSING="$SCRATCH_MISSING UnicodePlugin"
  150.   fi
  151.   if [ -n "$SCRATCH_MISSING" ] ; then
  152.     echo "Error: Missing in $SCRATCH_SRC/Plugins/:$SCRATCH_MISSING"
  153.     echo "       Please check for development headers and run:"
  154.     echo "       make -C $SCRATCH_SRC"
  155.     exit 1
  156.   fi
  157. fi
  158.  
  159. SCRATCH_VM=`find "$SQUEAK_DIR" -name "squeakvm"`
  160. if [ -z "$SCRATCH_VM" ] ; then
  161.   echo "Error: Squeak Virtual Machine binary not found."
  162.   echo "       Expecting an executable or link named 'squeakvm' in the same"
  163.   echo "       directory as the plugins in: $SQUEAK_DIR."
  164.   echo "       Please set option -v and retry."
  165.   exit 1
  166. fi
  167.  
  168. SCRATCH_X11=`find "$SQUEAK_DIR" -name "*vm-display-X11*"`
  169. if [ -z "$SCRATCH_X11" ] ; then
  170.   echo "Error: Squeak X11 plugin not found."
  171.   exit 1
  172. fi
  173.  
  174. SCRATCH_FB=""
  175. if [ -n "$scratch_framebuffer" ] ; then
  176.   SCRATCH_FB=`find "$SQUEAK_DIR" -name "*vm-display-fbdev*"`
  177.   if [ -z "$SCRATCH_FB" ] ; then
  178.     echo "Error: Squeak framebuffer plugin not found (option '-f' specified)."
  179.     exit 1
  180.   fi
  181. fi
  182.  
  183. SCRATCH_MPEG3=`find "$SQUEAK_DIR" -name "*Mpeg3Plugin*"`
  184. if [ -z "$SCRATCH_MPEG3" ] ; then
  185.   echo "Warning: Squeak MPEG3 plugin not found."
  186. fi
  187.  
  188. SCRATCH_MIDI=`find "$SQUEAK_DIR" -name "*MIDIPlugin*"`
  189. if [ -z "$SCRATCH_MIDI" ] ; then
  190.   echo "Warning: Squeak MIDI plugin not found."
  191. fi
  192.  
  193. SCRATCH_X11_LEAFNAME="${SCRATCH_X11##*\/}"
  194. SCRATCH_MODULE_PREFIX="${SCRATCH_X11_LEAFNAME%%vm-display-X11*}"
  195. SCRATCH_MODULE_SUFFIX="${SCRATCH_X11_LEAFNAME##*vm-display-X11}"
  196.  
  197. if [ -z "$SCRATCH_SND" ] ; then
  198.   declare -a SCRATCH_SND_LIST
  199.   declare -i SCRATCH_SND_INDEX=0
  200.   echo "Please choose a sound driver from the following list:"
  201.   SCRATCH_SND=`find "$SQUEAK_DIR" -name "*vm-sound-*"`
  202.   for SND in $SCRATCH_SND ; do
  203.     SCRATCH_SND_INDEX=1+$SCRATCH_SND_INDEX
  204.     SCRATCH_SND_LIST[$SCRATCH_SND_INDEX]="$SND"
  205.     echo -n "        $SCRATCH_SND_INDEX) "
  206.     SCRATCH_SND_ITEM="${SND##*vm-sound-}"
  207.     SCRATCH_SND_ITEM="${SCRATCH_SND_ITEM%%$SCRATCH_MODULE_SUFFIX}"
  208.     echo "$SCRATCH_SND_ITEM"
  209.   done
  210.   echo -n "Enter your choice [1-$SCRATCH_SND_INDEX]: "
  211.   read
  212.   while [ -z "$REPLY" ] ; do
  213.     read
  214.   done
  215.   SCRATCH_SND="${SCRATCH_SND_LIST[$REPLY]}"
  216.   else
  217.   SCRATCH_SND=`find "$SQUEAK_DIR" -name "*vm-sound-$SCRATCH_SND*"`
  218.   if [ -z "$SCRATCH_SND" ] ; then
  219.     echo "Error: Squeak sound driver not found: $SCRATCH_SND"
  220.     exit 1
  221.   fi
  222. fi
  223. SCRATCH_SND_LEAFNAME="${SCRATCH_SND##*\/}"
  224. SCRATCH_SND_SELECT="${SCRATCH_SND_LEAFNAME%%$SCRATCH_MODULE_SUFFIX}"
  225. SCRATCH_SND_SELECT="${SCRATCH_SND_SELECT##$SCRATCH_MODULE_PREFIX}"
  226.  
  227. echo "Creating: $SCRATCH_INI"
  228. # Possibly use package run-script in future?
  229. #if [ -n "$squeak_plugins_scratch" ] ; then
  230. # cp -f /usr/share/doc/squeak-plugins-scratch/scripts/run-scratch $SCRATCH_INI
  231. # else
  232.   echo "#!/bin/sh" >$SCRATCH_INI
  233.   echo "# This file was created by scratch-install.sh" >>$SCRATCH_INI
  234.   echo "" >>$SCRATCH_INI
  235.   echo "$SCRATCH_VM \\" >>$SCRATCH_INI
  236.  echo "-plugins $SCRATCH_PLG:${SCRATCH_VM%/*} \\" >>$SCRATCH_INI
  237.   echo "-$SCRATCH_SND_SELECT -vm-display-X11 \\" >>$SCRATCH_INI
  238.  echo "$SCRATCH_DAT/Scratch.image \"\${@}\"" >>$SCRATCH_INI
  239. #fi
  240. chmod a+x $SCRATCH_INI
  241.  
  242. if [ -n "$scratch_framebuffer" ] ; then
  243.  echo "Creating: $SCRATCH_INI_FB"
  244.  sed -e 's/vm-display-X11/vm-display-fbdev/' <$SCRATCH_INI >$SCRATCH_INI_FB
  245.  chmod a+x $SCRATCH_INI_FB
  246. fi
  247.  
  248. #echo "Creating symlinks in: $SCRATCH_PLG"
  249. mkdir -p "$SCRATCH_PLG"
  250. #ln -sf "$SCRATCH_X11" "$SCRATCH_PLG/$SCRATCH_X11_LEAFNAME"
  251. #if [ -n "$SCRATCH_FB" ] ; then
  252. #  ln -sf "$SCRATCH_FB" "$SCRATCH_PLG/${SCRATCH_FB##*\/}"
  253. #fi
  254. #ln -sf "$SCRATCH_SND" "$SCRATCH_PLG/$SCRATCH_SND_LEAFNAME"
  255. #if [ -n "$SCRATCH_MPEG3" ] ; then
  256. #  ln -sf "$SCRATCH_MPEG3" "$SCRATCH_PLG/${SCRATCH_MPEG3##*\/}"
  257. #fi
  258. #if [ -n "$SCRATCH_MIDI" ] ; then
  259. #  ln -sf "$SCRATCH_MIDI" "$SCRATCH_PLG/${SCRATCH_MIDI##*\/}"
  260. #fi
  261.  
  262. if [ -z "$squeak_plugins_scratch" ] ; then
  263.  echo "Copying plugins to: $SCRATCH_PLG"
  264.  for SCRATCH_MODULE in "ScratchPlugin" "CameraPlugin" "UnicodePlugin" ; do
  265.    cp -f "$SCRATCH_SRC/Plugins/$SCRATCH_MODULE" "$SCRATCH_PLG/$SCRATCH_MODULE_PREFIX$SCRATCH_MODULE$SCRATCH_MODULE_SUFFIX"
  266.  done
  267. fi
  268.  
  269. echo "Creating desktop shortcut and icons"
  270. cp -f "$SCRATCH_SRC/src/scratch.desktop" "$SCRATCH_APP"
  271. cp -f "$SCRATCH_SRC/src/icons/48x48/scratch.png" "$SCRATCH_ICN"
  272. cp -f "$SCRATCH_SRC/src/icons/48x48/gnome-mime-application-x-scratch-project.png" "$SCRATCH_TYP"
  273. cp -f "$SCRATCH_SRC/src/icons/128x128/scratch.png" "$SCRATCH_ICH"
  274. cp -f "$SCRATCH_SRC/src/icons/128x128/gnome-mime-application-x-scratch-project.png" "$SCRATCH_TYH"
  275. gtk-update-icon-cache "${SCRATCH_ICN%%/48x48*}"
  276.  
  277. echo -n "Copying Scratch data files..."
  278. mkdir -p "$SCRATCH_DAT"
  279. for SCRATCH_DATA in "Scratch.image" "Help" "locale" "Media" "Projects" ; do
  280.  echo -n " $SCRATCH_DATA"
  281.  cp -r -f "$SCRATCH_SRC/$SCRATCH_DATA" "$SCRATCH_DAT/"
  282. done
  283.  
  284. echo ""
  285. echo "Scratch installation complete!"