comparison packaging/linux-installer.inc.in @ 711:acbe75423283

Added deinstallation functionality.
author Sascha Wilde <wilde@intevation.de>
date Wed, 02 Jul 2014 15:12:25 +0200
parents 37899f717fa5
children e71c59b16eee
comparison
equal deleted inserted replaced
710:86c9ff4cfb02 711:acbe75423283
7 CFGPATH="${XDG_DATA_HOME:-$HOME/.local/share}/BSI/TrustBridge" 7 CFGPATH="${XDG_DATA_HOME:-$HOME/.local/share}/BSI/TrustBridge"
8 SYSCFGPATH="/etc/TrustBridge" 8 SYSCFGPATH="/etc/TrustBridge"
9 INSTCFGNAME="installation.cfg" 9 INSTCFGNAME="installation.cfg"
10 FORCE=0 10 FORCE=0
11 SYSINST=0 11 SYSINST=0
12 DEINSTALL=0
13 BINNAMES="###BINNAMES###"
12 14
13 declare -A instcfg oldinstcfg 15 declare -A instcfg oldinstcfg
14 declare inst_default_prefix instcfg_file 16 declare inst_default_prefix instcfg_file
15 instcfg=( 17 instcfg=(
16 [TIMESTMP]=`date -u +%Y%m%d%H%M%S` 18 [TIMESTMP]=`date -u +%Y%m%d%H%M%S`
39 } 41 }
40 42
41 fatal() 43 fatal()
42 { 44 {
43 echo "$1" >&2 45 echo "$1" >&2
44 echo "Installation failed." >&2 46 if [ $DEINSTALL -eq 1 ] ; then
47 echo "Deinstallation failed." >&2
48 else
49 echo "Installation failed." >&2
50 fi
45 exit 1 51 exit 1
46 } 52 }
47 53
48 usage() 54 usage()
49 { 55 {
51 Usage: $ME [OPTION]... 57 Usage: $ME [OPTION]...
52 Install TrustBridge. 58 Install TrustBridge.
53 59
54 Options: 60 Options:
55 -p, --prefix=PATH install files in PATH 61 -p, --prefix=PATH install files in PATH
56 -s, --system=PATH make an system wide installation
57 -f, --force install to given prefix, even when a current 62 -f, --force install to given prefix, even when a current
58 installation with different prefix exists. 63 installation with different prefix exists.
64 -d, --deinstall deinstall files from current installation
65 -s, --system=PATH make an system wide (de)installation
59 --help display this help and exit 66 --help display this help and exit
60 --version output version information and exit 67 --version output version information and exit
61 EOF 68 EOF
62 exit $1 69 exit $1
63 } 70 }
64 71
72 yorn()
73 {
74 local c
75 while true ; do
76 read -n 1 c
77 echo
78 case "$c" in
79 y|Y|j|J)
80 return 0
81 ;;
82 n|N)
83 return 1
84 ;;
85 *)
86 echo >&2 "Answer [Y]es or [N]o: "
87 esac
88 done
89 }
90
65 parse_args() 91 parse_args()
66 { 92 {
67 OPTS=`getopt \ 93 OPTS=`getopt \
68 -l force,help,prefix:,system,version \ 94 -l deinstall,force,help,prefix:,system,version \
69 -o f,p:,s -n "$ME" -- "$@"` 95 -o d,f,p:,s -n "$ME" -- "$@"`
70 [ $? -eq 0 ] || usage 23 96 [ $? -eq 0 ] || usage 23
71 97
72 eval set -- "$OPTS" 98 eval set -- "$OPTS"
73 99
74 while true ; do 100 while true ; do
81 SYSINST=1 107 SYSINST=1
82 shift 1 108 shift 1
83 ;; 109 ;;
84 --force|-f) 110 --force|-f)
85 FORCE=1 111 FORCE=1
112 shift 1
113 ;;
114 --deinstall|-d)
115 DEINSTALL=1
86 shift 1 116 shift 1
87 ;; 117 ;;
88 --help) 118 --help)
89 usage 0 119 usage 0
90 ;; 120 ;;
134 if [ $SYSINST -eq 1 -a "$UID" -ne 0 ] ; then 164 if [ $SYSINST -eq 1 -a "$UID" -ne 0 ] ; then
135 fatal "System wide installation requires root privileges!" 165 fatal "System wide installation requires root privileges!"
136 fi 166 fi
137 } 167 }
138 168
169 deinstall()
170 {
171 if [ "${oldinstcfg[PREFIX]}" ] ; then
172 echo "Really deinstall TrustBridge from '${oldinstcfg[PREFIX]}'?"
173 yorn || exit 0
174 local deinstdir="${oldinstcfg[PREFIX]}/bin"
175 echo "Deinstalling from '${oldinstcfg[PREFIX]}'."
176 for file in $BINNAMES ; do
177 local path="${deinstdir}/$file"
178 echo "Deleting '$path' ..."
179 rm "$path" || echo >&2 "WARNING: Could not delete: '$path'!"
180 done
181 while [ "$deinstdir" -a -z "$(ls -A "$deinstdir")" ] ; do
182 echo "Deleting empty directory '$deinstdir' ..."
183 rmdir "$deinstdir"
184 deinstdir=`dirname "$deinstdir"`
185 done
186 echo "Removing installation configuration from: $instcfg_file ..."
187 rm "$instcfg_file"
188 echo "Deinstallation finished."
189 else
190 echo "No current installation found! No harm done."
191 fi
192 }
193
139 194
140 #====================================================================== 195 #======================================================================
141 # main() 196 # main()
142 197
143 parse_args "$@" 198 parse_args "$@"
151 TrustBridge - Installer 206 TrustBridge - Installer
152 Version ${instcfg[VERSION]} 207 Version ${instcfg[VERSION]}
153 208
154 ------------------------------------------------------------------------ 209 ------------------------------------------------------------------------
155 EOF 210 EOF
211
212 if [ $DEINSTALL -eq 1 ] ; then
213 deinstall
214 # Stop after deinstallation:
215 exit 0
216 fi
156 217
157 if [ -z "${instcfg[PREFIX]}" ] ; then 218 if [ -z "${instcfg[PREFIX]}" ] ; then
158 219
159 if [ "${oldinstcfg[PREFIX]}" ] ; then 220 if [ "${oldinstcfg[PREFIX]}" ] ; then
160 inst_default_prefix="${oldinstcfg[PREFIX]}" 221 inst_default_prefix="${oldinstcfg[PREFIX]}"
184 fi 245 fi
185 246
186 echo "unpacking files ..." 247 echo "unpacking files ..."
187 cd "${instcfg[PREFIX]}" 248 cd "${instcfg[PREFIX]}"
188 249
250 set +u
189 # ---------------------------------------------------------------------- 251 # ----------------------------------------------------------------------
190 # regular shar archive inserted here: 252 # regular shar archive inserted here:
191 ###SHAR### 253 ###SHAR###
192 # ---------------------------------------------------------------------- 254 # ----------------------------------------------------------------------
193 255

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