~drgeo-developers/drgeo/trunk

« back to all changes in this revision

Viewing changes to VMs/xo/vm-2010-07-21/bin/squeak.sh

  • Committer: Hilaire Fernandes
  • Date: 2012-01-27 21:15:40 UTC
  • Revision ID: hilaire.fernandes@gmail.com-20120127211540-912spf97bhpx6mve
Initial additions

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/sh
 
2
 
3
# Launch squeak from a menu, prompting for and/or installing an image
 
4
 
5
# Last edited: 2009-12-17 10:21:38 by piumarta on ubuntu
 
6
 
 
7
PATH=/usr/bin:/bin
 
8
 
 
9
me=`basename $0`
 
10
bindir=`dirname $0`
 
11
bindir=`cd ${bindir}; pwd`
 
12
prefix=`dirname ${bindir}`
 
13
libdir="${prefix}/lib/squeak"
 
14
vm="squeak"
 
15
 
 
16
# find a way to display dialogues
 
17
 
 
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`; }
 
30
else
 
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"; }
 
36
fi
 
37
 
 
38
# succeed if there are two or more arguments
 
39
 
 
40
plural () { test -n "$2"; }
 
41
 
 
42
# find the VM
 
43
 
 
44
if test -x "${bindir}/${vm}"; then
 
45
    vm="${bindir}/${vm}"
 
46
elif test -x "`which ${vm} 2>/dev/null`"; then
 
47
    vm="`which ${vm} 2>/dev/null`"
 
48
else
 
49
    error "Cannot find ${vm}"
 
50
fi
 
51
 
 
52
# if we have arguments then assume an image name was given or we came
 
53
# from a command line
 
54
 
 
55
if test $# -gt 0; then
 
56
    exec "${vm}" "$@"
 
57
fi
 
58
 
 
59
findFile "Choose a saved image to resume or cancel to install a new one"
 
60
 
 
61
if test -z "${result}"; then
 
62
    images=""
 
63
    if test -d "${libdir}"; then
 
64
        images=`cd "${libdir}"; ls *.image 2>/dev/null`
 
65
    fi
 
66
    if test -z "${images}"; then
 
67
        error "no image name specified and no images found in ${libdir}"
 
68
        exit 1
 
69
    fi
 
70
    if plural ${images}; then
 
71
        chooseItem "Choose an image to install" ${images}
 
72
    else
 
73
        confirm "Install image" ${images}
 
74
    fi
 
75
    if test -z "${result}"; then
 
76
        exit 0
 
77
    fi
 
78
    image=${result}
 
79
    changes=`basename ${image} .image`.changes
 
80
    findDirectory "Choose a destination directory for the image"
 
81
    if test -z "${result}"; then
 
82
        exit 0
 
83
    fi
 
84
    if test -e "${result}/${image}"; then
 
85
        confirm "Overwrite existing ${image} in" "${result}"
 
86
        if test -z "${result}"; then
 
87
            exit 0;
 
88
        fi
 
89
    fi
 
90
    cp -p "${libdir}/${image}"   "${result}/."
 
91
    cp -p "${libdir}/${changes}" "${result}/."
 
92
    ln -s "${libdir}"/*.sources  "${result}/."
 
93
    image="${result}/${image}"
 
94
else
 
95
    image="${result}"
 
96
fi
 
97
 
 
98
cd "`dirname ${image}`"
 
99
exec "${vm}" "`basename ${image}`"