comparison packaging/linux-installer.inc.in @ 707:37899f717fa5

Added system wide installation.
author Sascha Wilde <wilde@intevation.de>
date Wed, 02 Jul 2014 12:39:28 +0200
parents ff2efc1cb8fa
children acbe75423283
comparison
equal deleted inserted replaced
706:6bb3018b966d 707:37899f717fa5
1 #!/bin/bash 1 #!/bin/bash
2 set -u
2 3
3 ME=`basename "$0"` 4 ME=`basename "$0"`
4 DEFAULT_PREFIX="$HOME/TrustBridge" 5 DEFAULT_PREFIX="$HOME/TrustBridge"
6 SYSDEFAULT_PREFIX="/usr/local"
5 CFGPATH="${XDG_DATA_HOME:-$HOME/.local/share}/BSI/TrustBridge" 7 CFGPATH="${XDG_DATA_HOME:-$HOME/.local/share}/BSI/TrustBridge"
6 SYSCFGPATH="/etc/TrustBridge" 8 SYSCFGPATH="/etc/TrustBridge"
7 INSTCFGNAME="installation.cfg" 9 INSTCFGNAME="installation.cfg"
8 FORCE=0 10 FORCE=0
11 SYSINST=0
9 12
10 instcfg_file="${CFGPATH}/${INSTCFGNAME}"
11 declare -A instcfg oldinstcfg 13 declare -A instcfg oldinstcfg
14 declare inst_default_prefix instcfg_file
12 instcfg=( 15 instcfg=(
13 [TIMESTMP]=`date -u +%Y%m%d%H%M%S` 16 [TIMESTMP]=`date -u +%Y%m%d%H%M%S`
14 [VERSION]='@PROJECT_VERSION@' 17 [VERSION]='@PROJECT_VERSION@'
15 [PREFIX]='' 18 [PREFIX]=''
16 ) 19 )
48 Usage: $ME [OPTION]... 51 Usage: $ME [OPTION]...
49 Install TrustBridge. 52 Install TrustBridge.
50 53
51 Options: 54 Options:
52 -p, --prefix=PATH install files in PATH 55 -p, --prefix=PATH install files in PATH
53 -f, --force install to given prefix, even when a current 56 -s, --system=PATH make an system wide installation
57 -f, --force install to given prefix, even when a current
54 installation with different prefix exists. 58 installation with different prefix exists.
55 --help display this help and exit 59 --help display this help and exit
56 --version output version information and exit 60 --version output version information and exit
57 EOF 61 EOF
58 exit $1 62 exit $1
59 } 63 }
60 64
61 parse_args() 65 parse_args()
62 { 66 {
63 OPTS=`getopt \ 67 OPTS=`getopt \
64 -l force,help,prefix:,version \ 68 -l force,help,prefix:,system,version \
65 -o f,p: -n "$ME" -- "$@"` 69 -o f,p:,s -n "$ME" -- "$@"`
66 [ $? -eq 0 ] || usage 23 70 [ $? -eq 0 ] || usage 23
67 71
68 eval set -- "$OPTS" 72 eval set -- "$OPTS"
69 73
70 while true ; do 74 while true ; do
71 case "$1" in 75 case "$1" in
72 --prefix|-p) 76 --prefix|-p)
73 instcfg[PREFIX]="$2" 77 instcfg[PREFIX]="$2"
74 shift 2 78 shift 2
79 ;;
80 --system|-s)
81 SYSINST=1
82 shift 1
75 ;; 83 ;;
76 --force|-f) 84 --force|-f)
77 FORCE=1 85 FORCE=1
78 shift 1 86 shift 1
79 ;; 87 ;;
89 ;; 97 ;;
90 esac 98 esac
91 done 99 done
92 } 100 }
93 101
102 init_vars()
103 {
104 if [ $SYSINST -eq 1 ] ; then
105 inst_default_prefix="$SYSDEFAULT_PREFIX"
106 instcfg_file="${SYSCFGPATH}/${INSTCFGNAME}"
107 else
108 inst_default_prefix="$DEFAULT_PREFIX"
109 instcfg_file="${CFGPATH}/${INSTCFGNAME}"
110 fi
111 }
112
94 write_instcfg() 113 write_instcfg()
95 { 114 {
96 install -d `dirname "$instcfg_file"` 115 install -d `dirname "$instcfg_file"`
97 echo "# Created by TrustBridge-Installer, don't touch!" >"$instcfg_file" 116 echo "# Created by TrustBridge-Installer, don't touch!" >"$instcfg_file"
98 for key in "${!instcfg[@]}" ; do 117 for key in "${!instcfg[@]}" ; do
105 if [ -r "$instcfg_file" ] ; then 124 if [ -r "$instcfg_file" ] ; then
106 echo "Reading '$instcfg_file' ..." 125 echo "Reading '$instcfg_file' ..."
107 for key in "${!oldinstcfg[@]}" ; do 126 for key in "${!oldinstcfg[@]}" ; do
108 oldinstcfg[$key]=`sed -n "/$key/s/[^=]*=\(.*\)/\1/p" "$instcfg_file"` 127 oldinstcfg[$key]=`sed -n "/$key/s/[^=]*=\(.*\)/\1/p" "$instcfg_file"`
109 done 128 done
110 fi 129 fi
111 } 130 }
131
132 check_priv()
133 {
134 if [ $SYSINST -eq 1 -a "$UID" -ne 0 ] ; then
135 fatal "System wide installation requires root privileges!"
136 fi
137 }
138
112 139
113 #====================================================================== 140 #======================================================================
114 # main() 141 # main()
115 142
116 parse_args "$@" 143 parse_args "$@"
144 init_vars
145 check_priv
117 read_oldinstcfg 146 read_oldinstcfg
118 147
119 cat <<EOF 148 cat <<EOF
120 ------------------------------------------------------------------------ 149 ------------------------------------------------------------------------
121 150
126 EOF 155 EOF
127 156
128 if [ -z "${instcfg[PREFIX]}" ] ; then 157 if [ -z "${instcfg[PREFIX]}" ] ; then
129 158
130 if [ "${oldinstcfg[PREFIX]}" ] ; then 159 if [ "${oldinstcfg[PREFIX]}" ] ; then
131 DEFAULT_PREFIX="${oldinstcfg[PREFIX]}" 160 inst_default_prefix="${oldinstcfg[PREFIX]}"
132 echo "An existing installation (v${oldinstcfg[VERSION]}) was detected!" 161 echo "An existing installation (v${oldinstcfg[VERSION]}) was detected!"
133 echo "It is HIGHLY RECOMMENDED to accept the default prefix" 162 echo "It is HIGHLY RECOMMENDED to accept the default prefix"
134 echo "to update the current installation." 163 echo "to update the current installation."
135 echo "For a new prefix you should deinstall first!" 164 echo "For a new prefix you should deinstall first!"
136 fi 165 fi
137 echo -n "Select installation prefix for TrustBridge [${DEFAULT_PREFIX}]: " 166 echo -n "Select installation prefix for TrustBridge [${inst_default_prefix}]: "
138 read -e instcfg[PREFIX] 167 read -e instcfg[PREFIX]
139 168
140 [ -z "${instcfg[PREFIX]}" ] && instcfg[PREFIX]="${DEFAULT_PREFIX}" 169 [ -z "${instcfg[PREFIX]}" ] && instcfg[PREFIX]="${inst_default_prefix}"
141 else 170 else
142 # Prefix was given on invocation: 171 # Prefix was given on invocation:
143 if [ "${oldinstcfg[PREFIX]}" -a \ 172 if [ "${oldinstcfg[PREFIX]}" -a \
144 "${instcfg[PREFIX]}" != "${oldinstcfg[PREFIX]}" -a \ 173 "${instcfg[PREFIX]}" != "${oldinstcfg[PREFIX]}" -a \
145 $FORCE -ne 1 ] ; then 174 $FORCE -ne 1 ] ; then

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