-
Notifications
You must be signed in to change notification settings - Fork 70
/
setup.body
383 lines (344 loc) · 11.9 KB
/
setup.body
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
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
#
# Original by Konstantinos Sykas <getafix@oolite.org> (26-Mar-2011)
#
# Type: shell script
# Description: The Oolite installation script, executed following the package self-extraction.
#
# 2011-04-03: Updated to facilitate rsync repository setup for oolite-update script
# 2011-04-04: Redirected "which" stderr to /dev/null. In some distros (e.g. Fedora 11, Mint 10 Julia etc.)
# the "which <filename>" command uses stderr to report a file not found or other warnings
# 2018-07-02: Add command line arguments support.
# First argument added is "--systemwide-path Directory"
# 2023-07-10: Add interactive parts from oolite.src to startup script based on FreeDesktop tools
#
# Handle the command line arguments
OOLITE_VERSION=$1 # This value is given in the make_installer.sh script. Check the line where makeself.sh is called; the last argument.
shift
while true
do
case "$1" in
--systemwide-directory)
INSTALL_ROOT_SYSTEMWIDE=${2:-.}/dummy
INSTALL_ROOT_SYSTEMWIDE=`dirname $INSTALL_ROOT_SYSTEMWIDE`
if [ ! -d "$INSTALL_ROOT_SYSTEMWIDE" ]; then
echo System directory $INSTALL_ROOT_SYSTEMWIDE does not exist. Exiting...
exit 1
fi
shift 2
;;
-*)
echo Unrecognized Oolite setup flag : "$1" >&2
exit 1
;;
*)
break ;;
esac
done
# Environment vars init part 1 of 2
INSTALL_ROOT=""
OOLITE_ROOT_NAME="Oolite${TRUNK}"
OOLITEAPP_NAME="oolite.app"
if [ ! ${INSTALL_ROOT_SYSTEMWIDE} ]
then
INSTALL_ROOT_SYSTEMWIDE="/opt"
fi
INSTALL_ROOT_USERHOME="GNUstep/Applications" # CAUTION! Depending on the usage, this should be sometimes manually pre-pended with $HOME/
STARTUP_SCRIPTS_PATH_SYSTEMWIDE="/usr/local/bin"
STARTUP_SCRIPTS_PATH_USERHOME="${INSTALL_ROOT_USERHOME}/${OOLITE_ROOT_NAME}" # CAUTION! Depending on the usage, this should be sometimes manually pre-pended with $HOME/
ERROR_CODE_UNINSTALL_FAILED=111 # arbitrary error code to detect if uninstall did nothing
# NOTE: also used in uninstall[.source] script
# System-wide or single user installation selection
# The default option changes depending on if the
# user is root or not.
if [ `id -u` -eq 0 ]
then
USER_IS_ROOT=1
USER_CHOICES="[S/h]"
else
USER_CHOICES="[s/H]"
fi
if [ ! ${UNATTENDED_INSTALLATION} ]
then
read -p "Install Oolite${TRUNK} system-wide or in your home directory? ${USER_CHOICES} " CHOICE
if [ ${USER_IS_ROOT} ]
then
if [ "x$CHOICE" = "xh" ] || [ "x$CHOICE" = "xH" ]
then
echo "You cannot be root and install Oolite${TRUNK} in your home directory."
exit 1
fi
else
if [ "x$CHOICE" = "xs" ] || [ "x$CHOICE" = "xS" ]
then
echo "You must be root to install Oolite${TRUNK} system-wide."
exit 1
fi
fi
fi
# Environment vars init part 2 of 2
ICON_SIZE="48"
if [ ${USER_IS_ROOT} ]
then
INSTALL_ROOT=${INSTALL_ROOT_SYSTEMWIDE}
STARTUP_SCRIPTS_PATH=${STARTUP_SCRIPTS_PATH_SYSTEMWIDE}
DESKTOP_MODE="system"
else
INSTALL_ROOT=$HOME/${INSTALL_ROOT_USERHOME}
STARTUP_SCRIPTS_PATH=$HOME/${STARTUP_SCRIPTS_PATH_USERHOME}
DESKTOP_MODE="user"
fi
OOLITE_ROOT=${INSTALL_ROOT}/${OOLITE_ROOT_NAME}
OOLITEAPP_PATH=${OOLITE_ROOT}/${OOLITEAPP_NAME}
INSTALLER_REPOS=${OOLITEAPP_PATH}/oolite.installer.tmp
SELF_PATH=$(cd $(dirname $0); pwd -P)
SELF_FILENAME=$(basename $0)
# Check if uninstall is necessary
#
# a. If user is not root, this script checks if another
# system-wide or current user home directory installation
# exists.
# b. If user is root, this script checks only if another
# system-wide installation exists.
#
# TODO - When user is root this script cannot detect
# if there is an Oolite installation in any
# user home directory.
# Uninstall, if possible, the current active system-wide installation
if [ ${USER_IS_ROOT} ]
then
OOLITE_SHORTCUT=${STARTUP_SCRIPTS_PATH}/oolite${TRUNK}
if [ -e ${OOLITE_SHORTCUT} ]
then
INSTALL_ROOT_SYSTEMWIDE_ACTIVE=`cat ${OOLITE_SHORTCUT} | head -2 | tail -1`
INSTALL_ROOT_SYSTEMWIDE_ACTIVE=${INSTALL_ROOT_SYSTEMWIDE_ACTIVE%%/Oolite*}
${INSTALL_ROOT_SYSTEMWIDE_ACTIVE}/${OOLITE_ROOT_NAME}/uninstall 2> /dev/null
if [ $? -eq ${ERROR_CODE_UNINSTALL_FAILED} ]
then
exit ${ERROR_CODE_UNINSTALL_FAILED}
fi
fi
fi
# Uninstall user's instalation
${OOLITE_ROOT}/uninstall 2> /dev/null
# Start installation
echo "Installing Oolite${TRUNK} in \"${OOLITE_ROOT}\"..."
# Generate Oolite root directory and
# copy main oolite binary and Resources
# as well as the rest of the tars
echo -n "Copying oolite executable and resources... "
mkdir -p ${OOLITEAPP_PATH}
cp -pR ${SELF_PATH}/* ${OOLITEAPP_PATH}/.
cd ${OOLITE_ROOT}
# Generate uninstall script
echo "#!/bin/sh" > uninstall
echo >> uninstall
echo >> uninstall
if [ ${TRUNK} ]
then
echo "TRUNK=\"${TRUNK}\"" >> uninstall
fi
echo "OOLITE_ROOT_NAME=\"${OOLITE_ROOT_NAME}\"" >> uninstall
echo "INSTALL_ROOT_SYSTEMWIDE=\"${INSTALL_ROOT_SYSTEMWIDE}\"" >> uninstall
echo "INSTALL_ROOT_USERHOME=\"${INSTALL_ROOT_USERHOME}\"" >> uninstall
echo "STARTUP_SCRIPTS_PATH_SYSTEMWIDE=\"${STARTUP_SCRIPTS_PATH_SYSTEMWIDE}\"" >> uninstall
echo "STARTUP_SCRIPTS_PATH_USERHOME=\"${STARTUP_SCRIPTS_PATH_USERHOME}\"" >> uninstall
echo "ICON_SIZE=\"${ICON_SIZE}\"" >> uninstall
echo "ERROR_CODE_UNINSTALL_FAILED=${ERROR_CODE_UNINSTALL_FAILED}" >> uninstall
cat ${OOLITEAPP_PATH}/uninstall.source >> uninstall
rm -f ${OOLITEAPP_PATH}/uninstall.source
chmod +x uninstall
echo "Done."
# Install AddOns/Basic-debug.oxp
if [ -f ${INSTALLER_REPOS}/addons.tar.gz ]
then
echo -n "Extracting AddOns/Basic-debug.oxp... "
cd ${OOLITE_ROOT}
tar zxf ${INSTALLER_REPOS}/addons.tar.gz
rm ${INSTALLER_REPOS}/addons.tar.gz
echo "Done."
fi
# Install documentation
echo -n "Extracting documentation... "
mkdir -p ${OOLITE_ROOT}/doc
cd ${OOLITE_ROOT}/doc
tar zxf ${INSTALLER_REPOS}/oolite.doc.tar.gz
rm ${INSTALLER_REPOS}/oolite.doc.tar.gz
echo "This is the first time you've run the game. Here is the README file -" > README-PREAMBLE.TXT
echo "more docs can be found at ${OOLITE_ROOT_NAME}/doc/" >> README-PREAMBLE.TXT
echo "Press q to exit this document and launch the game" >> README-PREAMBLE.TXT
echo >> README-PREAMBLE.TXT
echo "Done."
# Copy dependency libraries and DTDs
# Note that we do not install any libraries to the system.
# We just copy them in the Oolite tree structure.
echo -n "Extracting dependencies... "
mkdir -p ${OOLITE_ROOT}/oolite-deps
cd ${OOLITE_ROOT}/oolite-deps
tar zxf ${INSTALLER_REPOS}/oolite.deps.tar.gz
tar zxf ${INSTALLER_REPOS}/oolite.dtd.tar.gz
rm ${INSTALLER_REPOS}/oolite.deps.tar.gz
rm ${INSTALLER_REPOS}/oolite.dtd.tar.gz
echo "Done."
# Create folder for the OXPs
mkdir -p ${OOLITE_ROOT}/AddOns
# Generate release.txt used by oolite-update
echo -n "Generating startup and wrapper scripts... "
cd ${OOLITE_ROOT}
# Generate release information
mv ${INSTALLER_REPOS}/release.txt .
# Generate startup scripts
cd ${STARTUP_SCRIPTS_PATH}
cat << EOF_STARTUP_SCRIPT > oolite${TRUNK}
#!/bin/sh
# show readme on first launch
if [ ! -f \$HOME/.Oolite/.oolite${TRUNK}-run ]
then
mkdir -p $HOME/.Oolite/
touch \$HOME/.Oolite/.oolite${TRUNK}-run
xdg-open file://${OOLITE_ROOT}/doc/README-PREAMBLE.TXT
xdg-open file://${OOLITE_ROOT}/doc/README.TXT
fi
# launch oolite
${OOLITEAPP_PATH}/oolite-wrapper \$@
RC=\$?
# show message in case of error
if [ "\${RC}" != "0" ]
then
notify-send --urgency=critical --icon ${OOLITE_ROOT}/oolite.app/Resources/Textures/oolite-logo1.png "Oolite" "Oolite died in a singularity with exit code \${RC}. For troubleshooting check console and log output."
fi
exit \${RC}
EOF_STARTUP_SCRIPT
chmod +x oolite${TRUNK}
echo "#!/bin/sh" > oolite${TRUNK}-update
echo "${OOLITEAPP_PATH}/oolite-update \$@" >> oolite${TRUNK}-update
echo "exit \$?" >> oolite${TRUNK}-update
chmod +x oolite${TRUNK}-update
# Generate oolite wrapper script
cd ${OOLITEAPP_PATH}
tar zxf ${INSTALLER_REPOS}/oolite.wrap.tar.gz
rm ${INSTALLER_REPOS}/oolite.wrap.tar.gz
# Generate a thick oolite wrapper script as well as
# the oolite-update script
echo "#!/bin/sh" > oolite-wrapper
echo >> oolite-wrapper
echo >> oolite-wrapper
echo "TRUNK=\"${TRUNK}\"" >> oolite-wrapper
cat oolite.src >> oolite-wrapper
rm oolite.src
chmod +x oolite-wrapper
# Generate oolite update script
echo "#!/bin/sh" > oolite-update
echo >> oolite-update
echo >> oolite-update
echo "TRUNK=\"${TRUNK}\"" >> oolite-update
echo "SELF_PACKAGER=1" >> oolite-update # Just to keep compatibility with autopackage script
echo "OOLITE_ROOT_NAME=\"${OOLITE_ROOT_NAME}\"" >> oolite-update
echo "INSTALL_ROOT_SYSTEMWIDE=\"${INSTALL_ROOT_SYSTEMWIDE}\"" >> oolite-update
echo "INSTALL_ROOT_USERHOME=\"${INSTALL_ROOT_USERHOME}\"" >> oolite-update
cat oolite-update.src >> oolite-update
rm oolite-update.src
chmod +x oolite-update
echo "Done."
# Install desktop menu and icon
echo -n "Updating desktop menu... "
cd ${OOLITE_ROOT}
tar zxf ${INSTALLER_REPOS}/freedesktop.tar.gz
rm ${INSTALLER_REPOS}/freedesktop.tar.gz
cd FreeDesktop
# Ensure no desktop menu conflict with Linux repos oolite installation
awk -v var="Exec=${STARTUP_SCRIPTS_PATH}/oolite${TRUNK}" '{ gsub(/Exec=oolite/,var,$0); print }' oolite.desktop > oolite.desktop.tmp
mv oolite.desktop.tmp oolite.desktop
awk -v var="Icon=oolite${TRUNK}.org-icon" '{ gsub(/Icon=oolite-icon/,var,$0); print }' oolite.desktop > oolite.desktop.tmp
mv oolite.desktop.tmp oolite.desktop
awk -v var="Name=Oolite${TRUNK} (oolite.space)" '{ gsub(/Name=Oolite/,var,$0); print }' oolite.desktop > oolite.desktop.tmp
mv oolite.desktop.tmp oolite${TRUNK}.org.desktop
rm oolite.desktop
mv oolite-icon.png oolite${TRUNK}.org-icon.png
xdg-desktop-menu install --novendor --mode ${DESKTOP_MODE} oolite${TRUNK}.org.desktop 1> /dev/null 2> /dev/null
desktop_rc=$?
if [ $desktop_rc -eq 0 ]
then
rm oolite${TRUNK}.org.desktop
xdg-icon-resource install --novendor --mode ${DESKTOP_MODE} --size ${ICON_SIZE} oolite${TRUNK}.org-icon.png 1> /dev/null 2> /dev/null
icon_rc=$?
if [ $icon_rc -eq 3 ] || [ $icon_rc -eq 4 ] || [ $icon_rc -eq 127 ]
then
echo
echo "Warning $icon_rc: xdg-utils not properly installed. Oolite${TRUNK} icon cannot be installed."
else
if [ $icon_rc -eq 1 ] || [ $icon_rc -eq 2 ] || [ $icon_rc -eq 5 ]
then
echo
echo "Warning $icon_rc: oolite${TRUNK}.org-icon.png not found. Please report this as a broken package."
else
rm oolite${TRUNK}.org-icon.png
fi
fi
else
if [ $desktop_rc -eq 3 ] || [ $desktop_rc -eq 4 ] || [ $desktop_rc -eq 127 ]
then
echo
echo "Warning ${desktop_rc}: xdg-utils not properly installed. Oolite${TRUNK} desktop menu cannot be installed."
else
if [ $desktop_rc -eq 1 ] || [ $desktop_rc -eq 2 ] || [ $desktop_rc -eq 5 ]
then
echo
echo "Warning ${desktop_rc}: oolite${TRUNK}.org.desktop not found. Please report this as a broken package."
fi
fi
fi
if [ $desktop_rc -eq 0 ] && [ $icon_rc -eq 0 ]
then
echo "Done."
fi
# Clean up
echo -n "Cleaning up temporary folders... "
rc=0
rm ${OOLITEAPP_PATH}/setup 1> /dev/null 2> /dev/null
if [ $? -ne 0 ]
then
rc=$(($rc+1))
fi
rmdir ${OOLITE_ROOT}/FreeDesktop 1> /dev/null 2> /dev/null
if [ $? -ne 0 ]
then
rc=$(($rc+2))
fi
rmdir ${INSTALLER_REPOS} 1> /dev/null 2> /dev/null
if [ $? -ne 0 ]
then
rc=$(($rc+11))
fi
if [ $rc -gt 10 ]
then
echo
echo "Error ${rc}: Some temporary files and/or folders could not be deleted. Please report this as a broken package."
# Uninstall whatever you can and exit!
exit 1
else
if [ $rc -gt 0 ]
then
echo "Warning ${rc}: Some temporary files and/or folders could not be deleted."
else
echo "Done."
fi
fi
# Finished installation!
echo "Finished!"
echo
if [ $desktop_rc -eq 0 ]
then
echo "A desktop menu entry \"Oolite${TRUNK} (oolite.space)\" has been added under Games."
fi
echo -n "To start Oolite${TRUNK} from a shell, "
# check PATH
if [ "`which oolite${TRUNK} 2> /dev/null`" = "${STARTUP_SCRIPTS_PATH}/oolite${TRUNK}" ]
then
echo "run \"oolite${TRUNK}\"."
else
echo "run \"${STARTUP_SCRIPTS_PATH}/oolite${TRUNK}\"."
fi
echo "To uninstall Oolite${TRUNK}, run \"${OOLITE_ROOT}/uninstall\"."
echo
# Exit with grace!
exit 0