#!/bin/bash
# Install script for MIT Scratch running under Linux, version 0.4 2012/01/18
# PASTE THIS SCRIPT INTO AN EDITOR, AND SAVE AS scratch-install.sh INTO
# YOUR WORKING DIRECTORY, THEN FOLLOW THE INSTRUCTIONS BELOW...
# Syntax: sudo bash scratch_install.sh [OPTION..] source_dir | -r | -h
# where OPTION is: '-v squeak_vm_dir' -- path of Squeak executable and plugins
# '-a audio_driver' -- override script query
# '-f' -- include optional non-X framebuffer support
# '-h' -- display help message
# '-r' -- uninstall a previous installation
# See: http://my-svn.assembla.com/svn/scratchonlinux/scratch/README
# Prerequisites (Debian/Ubuntu/Mint, possibly other .deb based distros):
# sudo apt-get install build-essential pkg-config squeak-vm # see note 1
# sudo apt-get install libglib2.0-dev libpango1.0-dev libcairo2-dev libv4l-dev
# Prerequisites (Fedora/openSUSE [zypper install]):
# sudo yum install wget gcc make pkgconfig pango-devel cairo-devel libv4l-devel
# sudo yum install squeak-vm # or see note 1 below for alternative
# Suggested usage:
# wget http://info.scratch.mit.edu/sites/infoscratch.media.mit.edu/files/file/source-package/scratch-1.4.0.1.tar.gz
# tar -zxf scratch-1.4.0.1.tar.gz # (decompresses to directory 'scratch')
# make -C scratch/
# sudo bash scratch_install.sh -a ALSA scratch/ # omit '-a ALSA' for list
# Run 'scratch' in terminal, or from 'Development' sub-menu, and 'scratchfb'
# outside of X if option '-f' was selected
# Notes:
# 1 Squeak VM version 4.4 (current) does not work with the Scratch version
# above. A solution is to manually install a 4.0.3 .deb from an earlier
# distro version (eg. Natty/Squeeze). Alternatively see:
# http://squeakvm.org/unix/release/ for binary and source downloads.
# 2 Package 'squeak-plugins-scratch' is available in Precise (Ubuntu) and
# Wheezy (Debian), and removes the need for 'make' above, and also the
# dev packages, but needs libcairo2, libglib2.0-0 and libpango1.0-0.
# 3 Framebuffer support is experimental at present. For x86/x86_64 the
# module uvesafb must be loaded ('sudo modprobe uvesafb') and the 'v86d'
# package is needed. The 'fbset' package is also needed and 'scratchfb'
# must be started in a 1024x768 mode or higher ('fbset 1024x768-75').
# If you wish to start in a hi-res mode by default, use vga=xyz at boot.
# Also, the user must be a member of group 'video', and permissions
# on /dev/psaux or /dev/input/mice or /dev/adbmouse must be set to 0666
# ('sudo adduser <username> video' and 'sudo chmod 0666 /dev/xyz').
# Running 'scratchfb' as superuser is not recommended.
SCRATCH_SRC=""
SCRATCH_SND=""
SCRATCH_INI="/usr/bin/scratch"
SCRATCH_INI_FB="/usr/bin/scratchfb"
SCRATCH_LIB="/usr/lib/scratch"
SCRATCH_DAT="/usr/share/scratch"
SCRATCH_PLG="$SCRATCH_LIB/plugins"
SCRATCH_PLG_OLD="$SCRATCH_LIB/Plugins"
SCRATCH_APP="/usr/share/applications/scratch.desktop"
SCRATCH_ICN="/usr/share/icons/hicolor/48x48/apps/scratch.png"
SCRATCH_TYP="/usr/share/icons/hicolor/48x48/mimetypes/gnome-mime-application-x-scratch-project.png"
SCRATCH_ICH="/usr/share/icons/hicolor/128x128/apps/scratch.png"
SCRATCH_TYH="/usr/share/icons/hicolor/128x128/mimetypes/gnome-mime-application-x-scratch-project.png"
SQUEAK_DIR="/usr/lib/squeak"
scratch_framebuffer=""
squeak_plugins_scratch=""
if [ -n "`which dpkg 2>/dev/null`" ] ; then
# echo -n "Looking for squeak-plugins-scratch... "
# if [ -n "`dpkg --list | grep squeak-plugins-scratch`" ] ; then
if [ -d "/usr/share/doc/squeak-plugins-scratch/" ] ; then
squeak_plugins_scratch="y"
echo "Found package 'squeak-plugins-scratch'."
fi
# else
# echo "This does not appear to be a .deb based distro."
fi
while [ "$1" != "" ] ; do
case $1 in
-r)
echo "Removing MIT Scratch..."
rm $SCRATCH_INI $SCRATCH_INI_FB $SCRATCH_APP
rm $SCRATCH_ICN $SCRATCH_TYP $SCRATCH_ICH $SCRATCH_TYH
if [ -d "$SCRATCH_PLG_OLD" ] ; then
rm -rf $SCRATCH_PLG_OLD
fi
if [ -z "$squeak_plugins_scratch" ] ; then
rm -rf $SCRATCH_LIB
fi
rm -rf $SCRATCH_DAT
exit 0
;;
-h)
echo "Usage: sudo bash scratch_install.sh [-v squeak_vm_dir] [-a audio_driver] [-f]"
echo " -h|-r|source_dir"
exit 0
;;
-f)
scratch_framebuffer="y"
shift
;;
-v)
if [ -n "$2" ] ; then
SQUEAK_DIR="$2"
shift 2
else
echo "Error: Option '-v' requires an argument."
exit 1
fi
;;
-a)
if [ -n "$2" ] ; then
SCRATCH_SND="$2"
shift 2
else
echo "Error: Option '-a' requires an argument."
exit 1
fi
;;
-*)
echo "Error: Unknown option '$1'."
exit 1
;;
*)
break
;;
esac
done
if [ -n "$1" ] ; then
SCRATCH_SRC="$1"
else
echo "Error: Scratch source directory must be specified."
exit 1
fi
shift
if [ -n "$*" ] ; then
echo "Error: Trailing arguments not understood: '$*'"
exit 1
fi
if [ -z "$squeak_plugins_scratch" ] ; then
SCRATCH_MISSING=""
if [ ! -f "$SCRATCH_SRC/Plugins/ScratchPlugin" ] ; then
SCRATCH_MISSING="$SCRATCH_MISSING ScratchPlugin"
fi
if [ ! -f "$SCRATCH_SRC/Plugins/CameraPlugin" ] ; then
SCRATCH_MISSING="$SCRATCH_MISSING CameraPlugin"
fi
if [ ! -f "$SCRATCH_SRC/Plugins/UnicodePlugin" ] ; then
SCRATCH_MISSING="$SCRATCH_MISSING UnicodePlugin"
fi
if [ -n "$SCRATCH_MISSING" ] ; then
echo "Error: Missing in $SCRATCH_SRC/Plugins/:$SCRATCH_MISSING"
echo " Please check for development headers and run:"
echo " make -C $SCRATCH_SRC"
exit 1
fi
fi
SCRATCH_VM=`find "$SQUEAK_DIR" -name "squeakvm"`
if [ -z "$SCRATCH_VM" ] ; then
echo "Error: Squeak Virtual Machine binary not found."
echo " Expecting an executable or link named 'squeakvm' in the same"
echo " directory as the plugins in: $SQUEAK_DIR."
echo " Please set option -v and retry."
exit 1
fi
SCRATCH_X11=`find "$SQUEAK_DIR" -name "*vm-display-X11*"`
if [ -z "$SCRATCH_X11" ] ; then
echo "Error: Squeak X11 plugin not found."
exit 1
fi
SCRATCH_FB=""
if [ -n "$scratch_framebuffer" ] ; then
SCRATCH_FB=`find "$SQUEAK_DIR" -name "*vm-display-fbdev*"`
if [ -z "$SCRATCH_FB" ] ; then
echo "Error: Squeak framebuffer plugin not found (option '-f' specified)."
exit 1
fi
fi
SCRATCH_MPEG3=`find "$SQUEAK_DIR" -name "*Mpeg3Plugin*"`
if [ -z "$SCRATCH_MPEG3" ] ; then
echo "Warning: Squeak MPEG3 plugin not found."
fi
SCRATCH_MIDI=`find "$SQUEAK_DIR" -name "*MIDIPlugin*"`
if [ -z "$SCRATCH_MIDI" ] ; then
echo "Warning: Squeak MIDI plugin not found."
fi
SCRATCH_X11_LEAFNAME="${SCRATCH_X11##*\/}"
SCRATCH_MODULE_PREFIX="${SCRATCH_X11_LEAFNAME%%vm-display-X11*}"
SCRATCH_MODULE_SUFFIX="${SCRATCH_X11_LEAFNAME##*vm-display-X11}"
if [ -z "$SCRATCH_SND" ] ; then
declare -a SCRATCH_SND_LIST
declare -i SCRATCH_SND_INDEX=0
echo "Please choose a sound driver from the following list:"
SCRATCH_SND=`find "$SQUEAK_DIR" -name "*vm-sound-*"`
for SND in $SCRATCH_SND ; do
SCRATCH_SND_INDEX=1+$SCRATCH_SND_INDEX
SCRATCH_SND_LIST[$SCRATCH_SND_INDEX]="$SND"
echo -n " $SCRATCH_SND_INDEX) "
SCRATCH_SND_ITEM="${SND##*vm-sound-}"
SCRATCH_SND_ITEM="${SCRATCH_SND_ITEM%%$SCRATCH_MODULE_SUFFIX}"
echo "$SCRATCH_SND_ITEM"
done
echo -n "Enter your choice [1-$SCRATCH_SND_INDEX]: "
read
while [ -z "$REPLY" ] ; do
read
done
SCRATCH_SND="${SCRATCH_SND_LIST[$REPLY]}"
else
SCRATCH_SND=`find "$SQUEAK_DIR" -name "*vm-sound-$SCRATCH_SND*"`
if [ -z "$SCRATCH_SND" ] ; then
echo "Error: Squeak sound driver not found: $SCRATCH_SND"
exit 1
fi
fi
SCRATCH_SND_LEAFNAME="${SCRATCH_SND##*\/}"
SCRATCH_SND_SELECT="${SCRATCH_SND_LEAFNAME%%$SCRATCH_MODULE_SUFFIX}"
SCRATCH_SND_SELECT="${SCRATCH_SND_SELECT##$SCRATCH_MODULE_PREFIX}"
echo "Creating: $SCRATCH_INI"
# Possibly use package run-script in future?
#if [ -n "$squeak_plugins_scratch" ] ; then
# cp -f /usr/share/doc/squeak-plugins-scratch/scripts/run-scratch $SCRATCH_INI
# else
echo "#!/bin/sh" >$SCRATCH_INI
echo "# This file was created by scratch-install.sh" >>$SCRATCH_INI
echo "" >>$SCRATCH_INI
echo "$SCRATCH_VM \\" >>$SCRATCH_INI
echo "-plugins $SCRATCH_PLG:${SCRATCH_VM%/*} \\" >>$SCRATCH_INI
echo "-$SCRATCH_SND_SELECT -vm-display-X11 \\" >>$SCRATCH_INI
echo "$SCRATCH_DAT/Scratch.image \"\${@}\"" >>$SCRATCH_INI
#fi
chmod a+x $SCRATCH_INI
if [ -n "$scratch_framebuffer" ] ; then
echo "Creating: $SCRATCH_INI_FB"
sed -e 's/vm-display-X11/vm-display-fbdev/' <$SCRATCH_INI >$SCRATCH_INI_FB
chmod a+x $SCRATCH_INI_FB
fi
#echo "Creating symlinks in: $SCRATCH_PLG"
mkdir -p "$SCRATCH_PLG"
#ln -sf "$SCRATCH_X11" "$SCRATCH_PLG/$SCRATCH_X11_LEAFNAME"
#if [ -n "$SCRATCH_FB" ] ; then
# ln -sf "$SCRATCH_FB" "$SCRATCH_PLG/${SCRATCH_FB##*\/}"
#fi
#ln -sf "$SCRATCH_SND" "$SCRATCH_PLG/$SCRATCH_SND_LEAFNAME"
#if [ -n "$SCRATCH_MPEG3" ] ; then
# ln -sf "$SCRATCH_MPEG3" "$SCRATCH_PLG/${SCRATCH_MPEG3##*\/}"
#fi
#if [ -n "$SCRATCH_MIDI" ] ; then
# ln -sf "$SCRATCH_MIDI" "$SCRATCH_PLG/${SCRATCH_MIDI##*\/}"
#fi
if [ -z "$squeak_plugins_scratch" ] ; then
echo "Copying plugins to: $SCRATCH_PLG"
for SCRATCH_MODULE in "ScratchPlugin" "CameraPlugin" "UnicodePlugin" ; do
cp -f "$SCRATCH_SRC/Plugins/$SCRATCH_MODULE" "$SCRATCH_PLG/$SCRATCH_MODULE_PREFIX$SCRATCH_MODULE$SCRATCH_MODULE_SUFFIX"
done
fi
echo "Creating desktop shortcut and icons"
cp -f "$SCRATCH_SRC/src/scratch.desktop" "$SCRATCH_APP"
cp -f "$SCRATCH_SRC/src/icons/48x48/scratch.png" "$SCRATCH_ICN"
cp -f "$SCRATCH_SRC/src/icons/48x48/gnome-mime-application-x-scratch-project.png" "$SCRATCH_TYP"
cp -f "$SCRATCH_SRC/src/icons/128x128/scratch.png" "$SCRATCH_ICH"
cp -f "$SCRATCH_SRC/src/icons/128x128/gnome-mime-application-x-scratch-project.png" "$SCRATCH_TYH"
gtk-update-icon-cache "${SCRATCH_ICN%%/48x48*}"
echo -n "Copying Scratch data files..."
mkdir -p "$SCRATCH_DAT"
for SCRATCH_DATA in "Scratch.image" "Help" "locale" "Media" "Projects" ; do
echo -n " $SCRATCH_DATA"
cp -r -f "$SCRATCH_SRC/$SCRATCH_DATA" "$SCRATCH_DAT/"
done
echo ""
echo "Scratch installation complete!"