File: linux-install.sh.in

package info (click to toggle)
snek 1.13-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 27,420 kB
  • sloc: ansic: 23,496; python: 4,344; makefile: 1,684; sh: 691; lisp: 2
file content (260 lines) | stat: -rw-r--r-- 4,683 bytes parent folder | download | duplicates (4)
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
#!/bin/sh

can_ask=y

finish()
{
    if [ "$can_ask" = "y" ]; then
	echo ""
	echo -n "Press enter to continue..."
	read foo
    fi
    exit $1
}

#
# Make sure we have a terminal to talk to
#

if tty -s; then
    :
else
    case "$DISPLAY" in
	"")
	echo 'No user input available'
	can_ask=n
	;;
	*)
	GUESS_XTERMS="x-terminal-emulator xterm rxvt roxterm gnome-terminal dtterm eterm Eterm kvt konsole aterm"
        for a in $GUESS_XTERMS; do
            if type $a >/dev/null 2>&1; then
                XTERM=$a
                break
            fi
        done
	case "$XTERM" in
	    "")
	    echo 'No terminal emulator available'
	    can_ask=n
	    ;;
	    *)
	    exec "$XTERM" -e "sh '$0'"
	    ;;
	esac
	;;
    esac
fi

#
# Make sure we can run python3
#

echo -n "Checking for python3..."

if python3 --version > /dev/null 2>&1; then
    echo " found it."
else
    echo " python3 isn't working."
    echo ""
    echo "You'll need to install lsusb and python3 with pyserial and curses"
    echo "on this computer before Snek will work properly."
    finish 1
fi
    
echo -n "Checking for pyserial..."

if python3 -m serial.tools.list_ports > /dev/null 2>&1; then
    echo "  found it."
else
    echo " pyserial isn't working."
    echo ""
    echo "You'll need to install lsusb and python3 with pyserial and curses"
    echo "on this computer before Snek will work properly."
    finish 1
fi

echo -n "Checking for python curses..."

if python3 -c 'import curses' > /dev/null 2>&1; then
    echo "   found it."
else
    echo " python curses isn't working."
    echo ""
    echo "You'll need to install lsusb and python3 with pyserial and curses"
    echo "on this computer before Snek will work properly."
    finish 1
fi

#
# Pick an installation target
# 

if [ '(' -d /opt -a -w /opt ')' -o '(' -d /opt/Snek -a -w /opt/Snek ')' ]; then
    target_default=/opt
else
    target_default="$HOME"
fi

case "$#" in
0)
    echo -n "Installation location [default: $target_default] "
    if [ "$can_ask" = "y" ]; then
	read target
    else
	echo ""
	target=""
    fi
    case "$target" in
	"")
	target="$target_default"
	;;
    esac
    ;;
*)
    target="$1"
    ;;
esac

target_snek="$target"/Snek

echo -n "Installing to $target..."

#
# Make sure the target exists
#
mkdir -p "$target_snek"

if [ ! -d "$target_snek" ]; then
    echo "$target_snek does not exist and cannot be created"
    finish 1
fi

if [ ! -w "$target_snek" ]; then
    echo "$target_snek cannot be written"
    finish 1
fi

#
# Unpack the tar archive appended to the end of this script
#
archive_line=`awk '/^__ARCHIVE_BELOW__/ {print NR + 1; exit 0; }' "$0"`

tail -n+$archive_line "$0" | tar xjf - -C "$target"

case $? in
0)
    echo " done."
    ;;
*)
    echo "Install failed."
    finish 1
    ;;
esac

#
# Create custom files by editing the paths
#

case "$target" in
/*)
    target_abs="$target"
    ;;
*)
    target_abs=`pwd`/$target
    ;;
esac

BIN="$target_abs"/Snek

for infile in "$target"/Snek/*.in; do
    desktop=`basename "$infile" .in`
    # pre-pend a vendor to .desktop filenames
    case "$desktop" in
	*.desktop)
	    desktop="keithp.com-$desktop"
	    ;;
    esac
    desktop="$target"/Snek/"$desktop"
    rm -f "$desktop"
    sed -e "s;@"SHAREDIR"@;$BIN;g" -e "s;@"BINDIR"@;$BIN;g" -e "s;@"ICONDIR"@;$BIN;g" -e "s;@"SNEK_VERSION"@;@SNEK_VERSION@;g" "$infile" > "$desktop"
    chmod +x "$desktop"
done

#
# Install the .desktop files
#

for desktop in "$target"/Snek/*.desktop; do
    case `id -u` in
	0)
	    xdg-desktop-menu install --mode system "$desktop"
	    ;;
	*)
	    xdg-desktop-menu install --mode user "$desktop"
	    ;;
    esac
done

#
# Install icons
#

for icon_dir in /usr/share/icons/hicolor/scalable/mimetypes "$HOME/.icons" "$HOME/.kde/share/icons"; do
    if [ -w "$icon_dir" ]; then
	cp "$target"/Snek/*.svg "$icon_dir"
	update-icon-caches "$icon_dir"
    fi
done


#
# Install icon to desktop if desired
#

if [ -d $HOME/Desktop ]; then
    default_desktop=n
    if [ "$can_ask" = "y" ]; then
	:
    else
	default_desktop=y
    fi

    answered=n
    while [ "$answered" = "n" ]; do
	echo -n "Install icons to desktop? [default: $default_desktop] "
	if [ "$can_ask" = "y" ]; then
	    read do_desktop
	else
	    echo
	    do_desktop=""
	fi

	case "$do_desktop" in
	    "")
	    do_desktop=$default_desktop
	    ;;
	esac

	case "$do_desktop" in
	[yYnN]*)
	    answered=y
	    ;;
	esac
    done

    case "$do_desktop" in
	[yY]*)
	    echo -n "Installing desktop icons..."
	    for d in "$target"/Snek/*.desktop; do
		base=`basename $d`
		cp --remove-destination "$d" "$HOME/Desktop/"
	    done
	    ;;
    esac

    echo " done."
fi

finish 0

__ARCHIVE_BELOW__