comparison packaging/linux-installer.inc @ 1139:1c9001db6ea2

Split up linux installer in to be able to create a uninstaller (TODO).
author Sascha Wilde <wilde@intevation.de>
date Wed, 17 Sep 2014 18:53:04 +0200
parents packaging/linux-installer.inc.in@f1384bf9d4a4
children f67a6873d9c1
comparison
equal deleted inserted replaced
1138:45de97d43e13 1139:1c9001db6ea2
1 #!/bin/bash
2 # Um TrustBridge zu installieren:
3 # 1. Prüfen Sie ob Sie dieser Datei genügend vertrauen, um ihr die Kontrolle
4 # über diesen Rechner zu übergeben. Beispielsweise durch Vergleich mit
5 # einer starken Prüfsumme aus einer zweiten, unabhängigen Quelle.
6 # 2. Öffnen Sie eine Kommandozeile, z.B. klicken Sie auf das "Terminal"-Symbol.
7 # 3. Wechseln Sie in das Verzeichnis, in welchem diese Datei gespeichert ist.
8 # Geben Sie Z.B. in die Kommandozeile ein: cd ~/Schreibtisch
9 # 4. Starten Sie die Anwendung auf der Kommandozeile, beispielsweise
10 # als Installation nur für den aktuellen Nutzer, indem Sie eingeben:
11 # bash TrustBridge-1.0.0-i386.sh
12 # Tipp: Die Tab-Taste nach dem "Tr" ergänzt oft den ganzen Namen.
13 #
14 # NB: Wir konnten kein übliches .deb Paket verwenden, da wir Ihnen
15 # auch die Installation als reiner Nutzer ohne Admin-Rechte ermöglichen.
16 #
17 # To install TrustBridge:
18 # 1. Verify that you trust this specific file far enough, that you are willing
19 # to hand over the control of your computer to it. For example compare
20 # a strong checksum of the file to one from a second, independent source.
21 # 2. Open a command line, e.g. click on the "Terminal"-Symbol.
22 # 3. Change your working directory to where this file is stored.
23 # For example type "cd ~/Desktop" on your command line.
24 # 4. Start the installation on the command line, e.g. for the current user
25 # only by typing something like "bash TrustBridge-1.0.0-i386.sh".
26 # Hint: If you press the tab-key after "Tr" it may complete the filename.
27 #
28 # N.B. We could not have used a .deb package, because the installation must
29 # also work without without adminstrator priviledges.
30 #
31 #
32 # Search the file for 'version()' to find the license information.
33 set -u
34
35 ###INCLUDE:linux-installer-common.inc
36
37 ###INCLUDE:linux-installer-uninstall.inc
38
39 usage()
40 {
41 getxt "Usage: %s [OPTION]...\n" "$ME"
42 getxt "Install TrustBridge.\n\n"
43 getxt "Options:\n"
44 getxt " -p, --prefix=PATH install files in PATH\n"
45 getxt " -f, --force install to given prefix, even when a current\n"
46 getxt " installation with different prefix exists.\n"
47 getxt " -d, --deinstall deinstall files from current installation\n"
48 getxt " -s, --system create a system wide (de)installation\n"
49 getxt " --help display this help and exit\n"
50 getxt " --version output version information and exit\n"
51 exit $1
52 }
53
54 parse_args()
55 {
56 OPTS=`getopt \
57 -l deinstall,update,show-after-update,force,help,prefix:,system,version \
58 -o d,f,p:,s -n "$ME" -- "$@"`
59 [ $? -eq 0 ] || usage 23
60
61 eval set -- "$OPTS"
62
63 while true ; do
64 case "$1" in
65 --prefix|-p)
66 instcfg[PREFIX]="$2"
67 shift 2
68 ;;
69 --system|-s)
70 SYSINST=1
71 shift 1
72 ;;
73 --force|-f)
74 FORCE=1
75 shift 1
76 ;;
77 --deinstall|-d)
78 DEINSTALL=1
79 shift 1
80 ;;
81 --update)
82 UPDATE=1
83 shift 1
84 ;;
85 --help)
86 usage 0
87 ;;
88 --version)
89 version
90 ;;
91 --)
92 shift
93 break
94 ;;
95 esac
96 done
97 }
98
99 finished()
100 {
101 echo
102 echo "#################################################################################"
103 if [ $SYSINST -eq 1 ]; then
104 getxt "System wide installation successful.\n"
105 RUNCMD="su -l $SUDO_USER -c "
106 else
107 getxt "Single user installation successful.\n"
108 RUNCMD=""
109 fi
110 getxt "TrustBridge has been installed to: '%s'\n\n" "${instcfg[PREFIX]}"
111
112 getxt "To remove the application and the root certificates it has inserted,\n"
113 getxt "call the deinstall command:\n"
114 echo " $RUNCMD ${instcfg[PREFIX]}/bin/trustbridge-deinstall-TODO.sh"
115
116 echo "#################################################################################"
117 getxt "Press enter to launch '%s'\n" "${instcfg[PREFIX]}/bin/trustbridge"
118 if [ $UPDATE -eq 0 ]; then
119 read
120 $RUNCMD "${instcfg[PREFIX]}/bin/trustbridge" &
121 else
122 $RUNCMD "${instcfg[PREFIX]}/bin/trustbridge" --tray &
123 fi
124 }
125
126 cleanup()
127 {
128 getxt "Cleaning up temporary stuff ...\n"
129
130 # remove temporary directories:
131 local -a temp_dirs
132 if [ "${lock_dir:-}" ]; then
133 # $lock_dir is generate by the shar
134 temp_dirs+=("${instcfg[PREFIX]}/$lock_dir")
135 fi
136 if [ "${lock_dir:-}" ]; then
137 temp_dirs+=("$extra_bin_path")
138 fi
139
140 for dir in "${temp_dirs[@]-}" ; do
141 [ -d "$dir" ] &&
142 rm -rf "$dir"
143 done
144 }
145
146 write_instcfg()
147 {
148 install -d `dirname "$instcfg_file"`
149 echo "# Created by TrustBridge-Installer, don't touch!" >"$instcfg_file"
150 for key in "${!instcfg[@]}" ; do
151 echo "${key}=${instcfg[$key]}" >>"$instcfg_file"
152 done
153 }
154
155 write_autostart()
156 {
157 cat > "$1" << EOF
158 [Desktop Entry]
159 Type=Application
160 Name=TrustBridge
161 Exec="${instcfg[PREFIX]}/bin/trustbridge" --tray
162 EOF
163 chown "${SUDO_USER:-${USER}}" "$1"
164 chmod 700 "$1"
165 }
166
167 write_startmenu()
168 {
169 cat > "$1" << EOF
170 [Desktop Entry]
171 Type=Application
172 Name=TrustBridge
173 Comment=Install and update trusted root certificates
174 Comment[de]=Vertrauenswürdige Wurzelzertifikate installieren und aktualisieren
175 Exec=${instcfg[PREFIX]}/bin/trustbridge
176 Icon=${instcfg[PREFIX]}/share/pixmaps/trustbridge/trustbridge.png
177 Terminal=false
178 Categories=Network;Qt;
179 StartupNotify=false
180 EOF
181 }
182
183 setup_startmenu()
184 {
185 # Supported desktop environments: Unity, GNOME, XFCE, LXDE, KDE
186 # System wide installation with a nonstandard XDG_DATA_HOME is not
187 # respected with regards to autostart.
188 if [ ! -d "${startmenu_path}" ]; then
189 install -d "${startmenu_path}" || \
190 fatal "Failed to create startmenu directory: '%s'\n" "$startmenu_path"
191 fi
192
193 write_startmenu "${startmenu_path}/trustbridge.desktop"
194 update-desktop-database 2>&1 || true
195 }
196
197 setup_autostart()
198 {
199 # Supported desktop environments: Unity, GNOME, XFCE, LXDE, KDE
200 # System wide installation with a nonstandard XDG_CONFIG_HOME or KDEHOME is not
201 # respected with regards to autostart.
202 if [ ! -d "${autostart_path}" ]; then
203 install -d "${autostart_path}" || \
204 fatal "Failed to create autostart directory: '%s'\n" "$autostart_path"
205 fi
206
207 write_autostart "${autostart_path}/trustbridge.desktop"
208 }
209
210 provide_uudecode_maybe()
211 {
212 # The shar needs uudecode, which might not be installed. If its not
213 # available we will provide our own python based implementation.
214 if which uudecode >/dev/null 2>&1 ; then
215 getxt "Found system uudecode.\n"
216 else
217 local myuudecode="$extra_bin_path/uudecode"
218 cat >"$myuudecode" <<EOF
219 #!/usr/bin/python2
220 import os
221 import sys
222 import uu
223 os.path.chmod = os.chmod
224 def rm_if_exists(file):
225 try:
226 os.remove(file)
227 except OSError:
228 pass
229 os.path.exists = rm_if_exists
230 if len(sys.argv) > 1:
231 f = open(sys.argv[1], 'r')
232 else:
233 f = sys.stdin
234 uu.decode(f, None, None, 1)
235 EOF
236 chmod 755 "$myuudecode"
237 PATH="${extra_bin_path}:$PATH"
238 getxt "Using python uudecode provided by installer.\n"
239 fi
240 }
241
242 #======================================================================
243 # main()
244 trap cleanup EXIT
245
246 parse_args "$@"
247 check_priv
248 init_vars
249 read_oldinstcfg
250
251 cat <<EOF
252 ------------------------------------------------------------------------
253
254 TrustBridge - Installer
255 Version ${instcfg[VERSION]} - ${ARCH} (Testversion)
256
257 ------------------------------------------------------------------------
258 EOF
259
260 if [ "$ARCH" == "x86_64" -a "$ARCH" != "$HOST_ARCH" ]; then
261 getxt "It appears your system architecture is %s.\n" "$HOST_ARCH"
262 getxt "This installer is for 64 bit systems.\n"
263 getxt "Really install TrustBridge for '%s' systems? [y/n]\n" "${ARCH}"
264 yorn || exit 0
265 fi
266
267 if [ "$ARCH" == "i386" ]; then
268 if [[ "$HOST_ARCH" != *86 ]]; then
269 getxt "It appears your system architecture is %s.\n" "$HOST_ARCH"
270 getxt "This installer is for 32 bit systems.\n"
271 getxt "Really install TrustBridge for '%s' systems? [y/n]\n" "${ARCH}"
272 yorn || exit 0
273 fi
274 fi
275
276 if [ $DEINSTALL -eq 1 ] ; then
277 deinstall
278 # Stop after deinstallation:
279 exit 0
280 fi
281
282 if [ -z "${instcfg[PREFIX]}" ] ; then
283
284 if [ "${oldinstcfg[PREFIX]}" ] ; then
285 inst_default_prefix="${oldinstcfg[PREFIX]}"
286 getxt "An existing installation (v%s) was detected!\n" "${oldinstcfg[VERSION]}"
287 getxt "It is HIGHLY RECOMMENDED to accept the default prefix\n"
288 getxt "to update the current installation.\n"
289 getxt "For a new prefix you should deinstall first!\n"
290 fi
291 getxt "Select installation prefix for TrustBridge [%s]: " "${inst_default_prefix}"
292 read -e instcfg[PREFIX]
293
294 [ -z "${instcfg[PREFIX]}" ] && instcfg[PREFIX]="${inst_default_prefix}"
295 else
296 # Prefix was given on invocation:
297 if [ "${oldinstcfg[PREFIX]}" -a \
298 "${instcfg[PREFIX]}" != "${oldinstcfg[PREFIX]}" -a \
299 $FORCE -ne 1 ] ; then
300 fatal "Prefix differs from current installation (%s). Aborting!\n" "${oldinstcfg[PREFIX]}"
301 fi
302 fi
303
304 getxt "Installing to '%s':\n" "${instcfg[PREFIX]}"
305
306 if [ ! -d "${instcfg[PREFIX]}" ] ; then
307 getxt "creating installation directory ...\n"
308 install -d "${instcfg[PREFIX]}" || fatal "Could not create '%s'!\n" "${instcfg[PREFIX]}"
309 fi
310
311 getxt "checking for uudecode ...\n"
312 provide_uudecode_maybe
313
314 getxt "unpacking files ...\n"
315 cd "${instcfg[PREFIX]}"
316
317 set +u
318 set -- '-c'
319 # ----------------------------------------------------------------------
320 # regular shar archive inserted here:
321 ###SHAR###
322 # ----------------------------------------------------------------------
323
324 getxt "Preparing trustbridge-tray-starter ...\n"
325 sed -i "/^PREFIX=/c\PREFIX='${instcfg[PREFIX]}'" \
326 "${instcfg[PREFIX]}/bin/trustbridge-tray-starter.sh"
327
328 getxt "Setting up cronjob ...\n"
329 setup_cronjob
330
331 getxt "Setting up autostart ...\n"
332 setup_autostart
333
334 getxt "Setting up start menu entries ...\n"
335 setup_startmenu
336
337 getxt "Writing installation configuration to: %s ...\n" "$instcfg_file"
338 write_instcfg
339
340 finished
341
342 # cleanup
343 # is called implicitly at exit via trap...
344 exit 0

http://wald.intevation.org/projects/trustbridge/