Mercurial > trustbridge
comparison packaging/linux-installer-common.inc.in @ 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 | |
children | 96ecd345c961 |
comparison
equal
deleted
inserted
replaced
1138:45de97d43e13 | 1139:1c9001db6ea2 |
---|---|
1 #-*-sh-*- | |
2 ME=`basename "$0"` | |
3 DEFAULT_PREFIX="$HOME/TrustBridge" | |
4 SYSDEFAULT_PREFIX="/usr/local" | |
5 CFGPATH="${XDG_CONFIG_HOME:-$HOME/.config}/BSI" | |
6 DATAPATH="${XDG_DATA_HOME:-$HOME/.local/share}/BSI/TrustBridge" | |
7 SYSCFGPATH="/etc/TrustBridge" | |
8 # FIXME: | |
9 # Set the real data path for system wide installation once its known. | |
10 SYSDATAPATH="$DATAPATH" | |
11 INSTCFGNAME="TrustBridge-inst.cfg" | |
12 FORCE=0 | |
13 SYSINST=0 | |
14 DEINSTALL=0 | |
15 UPDATE=0 | |
16 BINNAMES="###BINNAMES###" | |
17 ICONNAME="###ICONNAME###" | |
18 HELPNAMES="###HELPNAMES###" | |
19 HELPNAMES_SOURCES="###HELPNAMES_SOURCES###" | |
20 HELPNAMES_STATIC="###HELPNAMES_STATIC###" | |
21 HELPNAMES_IMG="###HELPNAMES_IMG###" | |
22 ARCH="###ARCH###" | |
23 | |
24 declare -A instcfg oldinstcfg | |
25 declare inst_default_prefix instdata_path instcfg_path instcfg_file | |
26 instcfg=( | |
27 [TIMESTMP]=`date -u +%Y%m%d%H%M%S` | |
28 [VERSION]='@PROJECT_VERSION@' | |
29 [PREFIX]='' | |
30 ) | |
31 oldinstcfg=( | |
32 [TIMESTMP]='' | |
33 [VERSION]='' | |
34 [PREFIX]='' | |
35 ) | |
36 | |
37 declare -A L10N_DE | |
38 ###INCLUDE:linux-installer.l10n-de | |
39 | |
40 getxt() | |
41 { | |
42 # Poor mans gettext for l10n completely self contained in one shell | |
43 # script. | |
44 MSGID="$1" | |
45 shift | |
46 case ${LANGUAGE:-${LC_ALL:-${LC_MESSAGES:-$LANG}}} in | |
47 de*) | |
48 if [ "${L10N_DE[$MSGID]}" ] ; then | |
49 MSG="${L10N_DE[$MSGID]}" | |
50 else | |
51 MSG="$MSGID" | |
52 fi | |
53 ;; | |
54 *) | |
55 MSG="$MSGID" | |
56 ;; | |
57 esac | |
58 | |
59 printf "$MSG" "$@" | |
60 } | |
61 | |
62 version() | |
63 { | |
64 cat <<EOF | |
65 TrustBridge ${instcfg[VERSION]} Installer | |
66 | |
67 Copyright (C) 2014 by Bundesamt für Sicherheit in der Informationstechnik | |
68 Software engineering by Intevation GmbH | |
69 | |
70 This file is Free Software under the GNU GPL (v>=2) | |
71 and comes with ABSOLUTELY NO WARRANTY! | |
72 See LICENSE.txt for details. | |
73 EOF | |
74 exit 0 | |
75 } | |
76 | |
77 fatal() | |
78 { | |
79 getxt "$1" >&2 | |
80 if [ $DEINSTALL -eq 1 ] ; then | |
81 getxt "Deinstallation failed.\n" >&2 | |
82 else | |
83 getxt "Installation failed.\n" >&2 | |
84 fi | |
85 exit 1 | |
86 } | |
87 | |
88 yorn() | |
89 { | |
90 local c | |
91 while true ; do | |
92 read -n 1 c | |
93 echo | |
94 case "$c" in | |
95 y|Y|j|J) | |
96 return 0 | |
97 ;; | |
98 n|N) | |
99 return 1 | |
100 ;; | |
101 *) | |
102 getxt >&2 "Answer [Y]es or [N]o:\n" | |
103 esac | |
104 done | |
105 } | |
106 | |
107 check_priv() | |
108 { | |
109 if [ $SYSINST -eq 1 -a "$UID" -ne 0 ] ; then | |
110 fatal "System wide installation or deinstallation requires root privileges!\n" | |
111 fi | |
112 } | |
113 | |
114 init_vars() | |
115 { | |
116 if [ -n "${SUDO_USER-}" ] ; then | |
117 # Default to system wide installation when running with sudo | |
118 SYSINST=1 | |
119 fi | |
120 | |
121 if [ $SYSINST -eq 1 ] ; then | |
122 inst_default_prefix="$SYSDEFAULT_PREFIX" | |
123 instcfg_path="${SYSCFGPATH}" | |
124 instdata_path="${SYSDATAPATH}" | |
125 autostart_path="$(getent passwd "${SUDO_USER}" | cut -d ':' -f 6)/.config/autostart" | |
126 startmenu_path="/usr/share/applications" | |
127 else | |
128 inst_default_prefix="$DEFAULT_PREFIX" | |
129 instcfg_path="${CFGPATH}" | |
130 instdata_path="${DATAPATH}" | |
131 autostart_path=${XDG_CONFIG_HOME:-~/.config/autostart} | |
132 startmenu_path=${XDG_DATA_HOME:-~/.local/share/applications} | |
133 if [ $DEINSTALL -eq 1 ] ; then | |
134 if [ ! -r ${instcfg_path}/${INSTCFGNAME} ]; then | |
135 if [ -r ${SYSCFGPATH}/${INSTCFGNAME} ]; then | |
136 # Fall back to system uninstallation if no user config found | |
137 SYSINST=1 | |
138 init_vars | |
139 check_priv | |
140 fi | |
141 fi | |
142 else | |
143 # extra bin path not needed on deinstall: | |
144 extra_bin_path=`mktemp --tmpdir -d tmpbin.XXXXXXXXXX` | |
145 fi | |
146 fi | |
147 instcfg_file="${instcfg_path}/${INSTCFGNAME}" | |
148 HOST_ARCH=$(uname -m) | |
149 } | |
150 | |
151 read_oldinstcfg() | |
152 { | |
153 if [ -r "$instcfg_file" ] ; then | |
154 getxt "Reading '%s' ...\n" "$instcfg_file" | |
155 for key in "${!oldinstcfg[@]}" ; do | |
156 oldinstcfg[$key]=`sed -n "/$key/s/[^=]*=\(.*\)/\1/p" "$instcfg_file"` | |
157 done | |
158 fi | |
159 } | |
160 | |
161 | |
162 setup_cronjob() | |
163 { | |
164 local tmpcrontab=`mktemp` | |
165 | |
166 if [ $SYSINST -eq 1 -a "${SUDO_USER+X}" ] ; then | |
167 local crontabopt="-u $SUDO_USER" | |
168 else | |
169 local crontabopt='' | |
170 fi | |
171 | |
172 if [ "$1" != "deinstall" ] ; then | |
173 local trustbridge_tray_starter="${instcfg[PREFIX]}/bin/trustbridge-tray-starter.sh" | |
174 else | |
175 local trustbridge_tray_starter="${oldinstcfg[PREFIX]}/bin/trustbridge-tray-starter.sh" | |
176 fi | |
177 | |
178 crontab $crontabopt -l | \ | |
179 grep -vF "$trustbridge_tray_starter" \ | |
180 >"$tmpcrontab" | |
181 if [ "$1" != "deinstall" ] ; then | |
182 echo "$(( $RANDOM / 555 )) 12 * * * \"$trustbridge_tray_starter\"" \ | |
183 >>"$tmpcrontab" | |
184 fi | |
185 crontab $crontabopt "$tmpcrontab" | |
186 rm "$tmpcrontab" | |
187 } |