3
# Launch squeak from a menu, prompting for and/or installing an image
5
# Last edited: 2009-12-17 10:21:38 by piumarta on ubuntu
11
bindir=`cd ${bindir}; pwd`
12
prefix=`dirname ${bindir}`
13
libdir="${prefix}/lib/squeak"
16
# find a way to display dialogues
18
if test -n "$DISPLAY" -a -x "`which kdialog 2>/dev/null`"; then
19
error () { kdialog --error "${me}: $*"; exit 1; }
20
confirm () { if kdialog --yesno "${1} ${2}?"; then result="${2}"; else result=""; fi; }
21
chooseItem () { title="$1"; shift; result=`kdialog --combobox "${title}" $*`; }
22
findFile () { result=`kdialog --title "$1" --getopenfilename . '*.image'`; }
23
findDirectory () { result=`kdialog --title "$1" --getexistingdirectory .`; }
24
elif [ -n "$DISPLAY" -a -x "`which zenity 2>/dev/null`" ]; then
25
error () { zenity --error --text "${me}: $*"; exit 1; }
26
confirm () { if zenity --question --text="${1} ${2}?"; then result="${2}"; else result=""; fi; }
27
chooseItem () { title="$1"; shift; result=`zenity --title "${title}" --list --column Images $*`; }
28
findFile () { result=`zenity --title "$1" --file-selection --file-filter='*.image'`; }
29
findDirectory () { result=`zenity --title "$1" --file-selection --directory`; }
31
error () { echo "${me}: $*" >&2; exit 1; }
32
confirm () { error "this cannot happen"; }
33
chooseItem () { error "this cannot happen"; }
34
findFile () { error "no image name specified"; }
35
findDirectory () { error "this cannot happen"; }
38
# succeed if there are two or more arguments
40
plural () { test -n "$2"; }
44
if test -x "${bindir}/${vm}"; then
46
elif test -x "`which ${vm} 2>/dev/null`"; then
47
vm="`which ${vm} 2>/dev/null`"
49
error "Cannot find ${vm}"
52
# if we have arguments then assume an image name was given or we came
55
if test $# -gt 0; then
59
findFile "Choose a saved image to resume or cancel to install a new one"
61
if test -z "${result}"; then
63
if test -d "${libdir}"; then
64
images=`cd "${libdir}"; ls *.image 2>/dev/null`
66
if test -z "${images}"; then
67
error "no image name specified and no images found in ${libdir}"
70
if plural ${images}; then
71
chooseItem "Choose an image to install" ${images}
73
confirm "Install image" ${images}
75
if test -z "${result}"; then
79
changes=`basename ${image} .image`.changes
80
findDirectory "Choose a destination directory for the image"
81
if test -z "${result}"; then
84
if test -e "${result}/${image}"; then
85
confirm "Overwrite existing ${image} in" "${result}"
86
if test -z "${result}"; then
90
cp -p "${libdir}/${image}" "${result}/."
91
cp -p "${libdir}/${changes}" "${result}/."
92
ln -s "${libdir}"/*.sources "${result}/."
93
image="${result}/${image}"
98
cd "`dirname ${image}`"
99
exec "${vm}" "`basename ${image}`"