Mercurial > trustbridge
comparison packaging/linux-installer.inc.in @ 705:ff2efc1cb8fa
Use config from old installation for sensible default prefix.
author | Sascha Wilde <wilde@intevation.de> |
---|---|
date | Wed, 02 Jul 2014 11:56:56 +0200 |
parents | 480bc550d2ad |
children | 37899f717fa5 |
comparison
equal
deleted
inserted
replaced
704:480bc550d2ad | 705:ff2efc1cb8fa |
---|---|
3 ME=`basename "$0"` | 3 ME=`basename "$0"` |
4 DEFAULT_PREFIX="$HOME/TrustBridge" | 4 DEFAULT_PREFIX="$HOME/TrustBridge" |
5 CFGPATH="${XDG_DATA_HOME:-$HOME/.local/share}/BSI/TrustBridge" | 5 CFGPATH="${XDG_DATA_HOME:-$HOME/.local/share}/BSI/TrustBridge" |
6 SYSCFGPATH="/etc/TrustBridge" | 6 SYSCFGPATH="/etc/TrustBridge" |
7 INSTCFGNAME="installation.cfg" | 7 INSTCFGNAME="installation.cfg" |
8 FORCE=0 | |
8 | 9 |
9 instcfg_file="${CFGPATH}/${INSTCFGNAME}" | 10 instcfg_file="${CFGPATH}/${INSTCFGNAME}" |
10 declare -A instcfg | 11 declare -A instcfg oldinstcfg |
11 instcfg=( | 12 instcfg=( |
12 [TIMESTMP]=`date -u +%Y%m%d%H%M%S` | 13 [TIMESTMP]=`date -u +%Y%m%d%H%M%S` |
13 [VERSION]='@PROJECT_VERSION@' | 14 [VERSION]='@PROJECT_VERSION@' |
15 [PREFIX]='' | |
16 ) | |
17 oldinstcfg=( | |
18 [TIMESTMP]='' | |
19 [VERSION]='' | |
14 [PREFIX]='' | 20 [PREFIX]='' |
15 ) | 21 ) |
16 | 22 |
17 version() | 23 version() |
18 { | 24 { |
42 Usage: $ME [OPTION]... | 48 Usage: $ME [OPTION]... |
43 Install TrustBridge. | 49 Install TrustBridge. |
44 | 50 |
45 Options: | 51 Options: |
46 -p, --prefix=PATH install files in PATH | 52 -p, --prefix=PATH install files in PATH |
53 -f, --force install to given prefix, even when a current | |
54 installation with different prefix exists. | |
47 --help display this help and exit | 55 --help display this help and exit |
48 --version output version information and exit | 56 --version output version information and exit |
49 EOF | 57 EOF |
50 exit $1 | 58 exit $1 |
51 } | 59 } |
52 | 60 |
53 parse_args() | 61 parse_args() |
54 { | 62 { |
55 OPTS=`getopt \ | 63 OPTS=`getopt \ |
56 -l help,prefix:,version \ | 64 -l force,help,prefix:,version \ |
57 -o p: -n "$ME" -- "$@"` | 65 -o f,p: -n "$ME" -- "$@"` |
58 [ $? -eq 0 ] || usage 23 | 66 [ $? -eq 0 ] || usage 23 |
59 | 67 |
60 eval set -- "$OPTS" | 68 eval set -- "$OPTS" |
61 | 69 |
62 while true ; do | 70 while true ; do |
63 case "$1" in | 71 case "$1" in |
64 --prefix|-p) | 72 --prefix|-p) |
65 instcfg[PREFIX]="$2" | 73 instcfg[PREFIX]="$2" |
66 shift 2 | 74 shift 2 |
75 ;; | |
76 --force|-f) | |
77 FORCE=1 | |
78 shift 1 | |
67 ;; | 79 ;; |
68 --help) | 80 --help) |
69 usage 0 | 81 usage 0 |
70 ;; | 82 ;; |
71 --version) | 83 --version) |
86 for key in "${!instcfg[@]}" ; do | 98 for key in "${!instcfg[@]}" ; do |
87 echo "${key}=${instcfg[$key]}" >>"$instcfg_file" | 99 echo "${key}=${instcfg[$key]}" >>"$instcfg_file" |
88 done | 100 done |
89 } | 101 } |
90 | 102 |
103 read_oldinstcfg() | |
104 { | |
105 if [ -r "$instcfg_file" ] ; then | |
106 echo "Reading '$instcfg_file' ..." | |
107 for key in "${!oldinstcfg[@]}" ; do | |
108 oldinstcfg[$key]=`sed -n "/$key/s/[^=]*=\(.*\)/\1/p" "$instcfg_file"` | |
109 done | |
110 fi | |
111 } | |
112 | |
91 #====================================================================== | 113 #====================================================================== |
92 # main() | 114 # main() |
93 | 115 |
94 parse_args "$@" | 116 parse_args "$@" |
117 read_oldinstcfg | |
95 | 118 |
96 cat <<EOF | 119 cat <<EOF |
97 ------------------------------------------------------------------------ | 120 ------------------------------------------------------------------------ |
98 | 121 |
99 TrustBridge - Installer | 122 TrustBridge - Installer |
101 | 124 |
102 ------------------------------------------------------------------------ | 125 ------------------------------------------------------------------------ |
103 EOF | 126 EOF |
104 | 127 |
105 if [ -z "${instcfg[PREFIX]}" ] ; then | 128 if [ -z "${instcfg[PREFIX]}" ] ; then |
129 | |
130 if [ "${oldinstcfg[PREFIX]}" ] ; then | |
131 DEFAULT_PREFIX="${oldinstcfg[PREFIX]}" | |
132 echo "An existing installation (v${oldinstcfg[VERSION]}) was detected!" | |
133 echo "It is HIGHLY RECOMMENDED to accept the default prefix" | |
134 echo "to update the current installation." | |
135 echo "For a new prefix you should deinstall first!" | |
136 fi | |
106 echo -n "Select installation prefix for TrustBridge [${DEFAULT_PREFIX}]: " | 137 echo -n "Select installation prefix for TrustBridge [${DEFAULT_PREFIX}]: " |
107 read -e instcfg[PREFIX] | 138 read -e instcfg[PREFIX] |
108 | 139 |
109 [ -z "${instcfg[PREFIX]}" ] && instcfg[PREFIX]="${DEFAULT_PREFIX}" | 140 [ -z "${instcfg[PREFIX]}" ] && instcfg[PREFIX]="${DEFAULT_PREFIX}" |
141 else | |
142 # Prefix was given on invocation: | |
143 if [ "${oldinstcfg[PREFIX]}" -a \ | |
144 "${instcfg[PREFIX]}" != "${oldinstcfg[PREFIX]}" -a \ | |
145 $FORCE -ne 1 ] ; then | |
146 fatal "Prefix differs from current installation (${oldinstcfg[PREFIX]}). Aborting!" | |
147 fi | |
110 fi | 148 fi |
111 | 149 |
112 echo "Installing to '${instcfg[PREFIX]}':" | 150 echo "Installing to '${instcfg[PREFIX]}':" |
113 | 151 |
114 if [ ! -d "${instcfg[PREFIX]}" ] ; then | 152 if [ ! -d "${instcfg[PREFIX]}" ] ; then |