3
# Launch squeak from a menu, prompting for and/or installing an image
5
# Last edited: 2010-04-09 04:35:35 by piumarta on ubuntu
9
if pwd -P 2>/dev/null 1>&2; then pwd="pwd -P"; else pwd="pwd"; fi
13
bindir=`cd ${bindir}; ${pwd}`
14
prefix=`dirname ${bindir}`
15
libdir="${prefix}/lib/squeak"
18
# find a way to display dialogues
20
if test -n "$DISPLAY" -a -x "`which kdialog 2>/dev/null`"; then
21
error () { kdialog --error "${me}: $*"; exit 1; }
22
confirm () { if kdialog --yesno "${1} ${2}?"; then result="${2}"; else result=""; fi; }
23
chooseItem () { title="$1"; shift; result=`kdialog --combobox "${title}" $*`; }
24
findFile () { result=`kdialog --title "$1" --getopenfilename . '*.image'`; }
25
findDirectory () { result=`kdialog --title "$1" --getexistingdirectory .`; }
26
elif [ -n "$DISPLAY" -a -x "`which zenity 2>/dev/null`" ]; then
27
error () { zenity --error --text "${me}: $*"; exit 1; }
28
confirm () { if zenity --question --text="${1} ${2}?"; then result="${2}"; else result=""; fi; }
29
chooseItem () { title="$1"; shift; result=`zenity --title "${title}" --list --column Images $*`; }
30
findFile () { result=`zenity --title "$1" --file-selection --file-filter='*.image'`; }
31
findDirectory () { result=`zenity --title "$1" --file-selection --directory`; }
33
error () { echo "${me}: $*" >&2; exit 1; }
34
confirm () { error "this cannot happen"; }
35
chooseItem () { error "this cannot happen"; }
36
findFile () { error "no image name specified"; }
37
findDirectory () { error "this cannot happen"; }
40
# succeed if there are two or more arguments
42
plural () { test -n "$2"; }
46
if test -x "${bindir}/${vm}"; then
48
elif test -x "`which ${vm} 2>/dev/null`"; then
49
vm="`which ${vm} 2>/dev/null`"
51
error "Cannot find ${vm}"
54
# if we have arguments then assume an image name was given or we came
57
if test $# -gt 0; then
61
findFile "Choose a saved image to resume or cancel to install a new one"
63
if test -z "${result}"; then
65
if test -d "${libdir}"; then
66
images=`cd "${libdir}"; ls *.image 2>/dev/null`
68
if test -z "${images}"; then
69
error "no image name specified and no images found in ${libdir}"
72
if plural ${images}; then
73
chooseItem "Choose an image to install" ${images}
75
confirm "Install image" ${images}
77
if test -z "${result}"; then
81
changes=`basename ${image} .image`.changes
82
findDirectory "Choose a destination directory for the image"
83
if test -z "${result}"; then
86
if test -e "${result}/${image}"; then
87
confirm "Overwrite existing ${image} in" "${result}"
88
if test -z "${result}"; then
92
cp -p "${libdir}/${image}" "${result}/."
93
cp -p "${libdir}/${changes}" "${result}/."
94
ln -s "${libdir}"/*.sources "${result}/."
95
image="${result}/${image}"
100
cd "`dirname ${image}`"
101
exec "${vm}" "`basename ${image}`"