~hilaire-fernandes/drgeo/trunk

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/bin/bash

DIR_LOCAL="$HOME/.drgeo"
DIR_SHARE="/usr/share/drgeo2"

# usage function
usage (){
    cat <<EOF
usage $0 options :

This script run drgeo2 after copying all needed files in \$HOME/.drgeo

OPTIONS :

-h : print this help
-c : remove all files in your $HOME/.drgeo directory
-f : do a clean start (same as a --clear start and a second one)
-p : launch drgeo2 with a new image file, change won't be saved

EOF
}

# Link resources
linkTo () {
	[ -e "$DIR_LOCAL/$1" ] || ln -s "$DIR_SHARE/$1" "$DIR_LOCAL/$1"
}

# copy resources
copyTo () {
	[ -e "$DIR_LOCAL/$1" ] || cp "$DIR_SHARE/$1" "$DIR_LOCAL/$1"
}


# launching function
launch (){
    cd "$DIR_LOCAL"
    VM="$DIR_LOCAL/Contents/Linux"
    RESOURCES="$DIR_LOCAL/Contents/Resources"
    image="$RESOURCES/drgeo.image"
    # icon (note: gvfs-set-attribute is found in gvfs-bin on Ubuntu
    # systems and it seems to require an absolute filename)
    gvfs-set-attribute \
    "$0" \
    "metadata::custom-icon" \
    "file://$RESOURCES/drgeo.png" \
    2> /dev/null   
    
    # execute
    "$VM/pharo" \
    --plugins "$VM" \
    --encoding utf-8 \
    -vm-display-X11 \
        -title "Dr. Geo" \
        "$image"   
}

pre-launch () {
    mkdir -p "$DIR_LOCAL/Contents"
    mkdir -p "$DIR_LOCAL/MyExports"
    mkdir -p "$DIR_LOCAL/MySketches"
    mkdir -p "$DIR_LOCAL/Contents/Resources"
    
	copyTo "Contents/Resources/drgeo.image"
	copyTo "Contents/Resources/drgeo.changes"
    
    pushd "$DIR_SHARE/Contents/Resources"
	for file in ./*; do
		linkTo "Contents/Resources/$file"
    done
    popd
    
	linkTo "examples"
	linkTo "SmalltalkSketches"
	linkTo "splash.bmp"	
	linkTo "Contents/Linux"
}

cleanup() {
    read -p "Do you really want to remove your $DIR_LOCAL directory ? (y/N)" -n 1 -r
    if [[ $REPLY =~ ^[Yy]$ ]]; then
        rm -Rf "$DIR_LOCAL"
    else
		echo
        exit 1
    fi
}

if [ $# -eq 0 ]; then
    pre-launch
    launch
fi

while getopts "hcfp" opt;
do
    case "$opt" in
    h)
        usage
        exit 0
        ;;
    c)
        cleanup
		echo
        exit 0
        ;;
    f)
        cleanup
        pre-launch
        launch
        ;;
    p)
        DIR_LOCAL="/tmp/.drgeo"
        rm -Rf "$DIR_LOCAL"
        pre-launch
        launch
        rm -Rf "$DIR_LOCAL"
        ;;
    esac
done