| 1 |
#!/bin/bash |
| 2 |
# postinst script for mlat-client-adsbfi |
| 3 |
# |
| 4 |
# see: dh_installdeb(1) |
| 5 |
|
| 6 |
set -e |
| 7 |
|
| 8 |
# summary of how this script can be called: |
| 9 |
# * <postinst> `configure' <most-recently-configured-version> |
| 10 |
# * <old-postinst> `abort-upgrade' <new version> |
| 11 |
# * <conflictor's-postinst> `abort-remove' `in-favour' <package> |
| 12 |
# <new-version> |
| 13 |
# * <postinst> `abort-remove' |
| 14 |
# * <deconfigured's-postinst> `abort-deconfigure' `in-favour' |
| 15 |
# <failed-install-package> <version> `removing' |
| 16 |
# <conflicting-package> <version> |
| 17 |
# for details, see http://www.debian.org/doc/debian-policy/ or |
| 18 |
# the debian-policy package |
| 19 |
|
| 20 |
NAME=mlat-client-adsbfi |
| 21 |
CONFIGFILE=/etc/default/$NAME |
| 22 |
TEMPLATECONFIG=/usr/share/$NAME/config-template |
| 23 |
SEDSCRIPT=$CONFIGFILE.sed.tmp |
| 24 |
|
| 25 |
subvar_raw() { |
| 26 |
# $1 = db var value |
| 27 |
# $2 = config var name |
| 28 |
|
| 29 |
# if not present in the config file, add it |
| 30 |
if grep -Eq "^ *$2=" $CONFIGFILE |
| 31 |
then |
| 32 |
# Already present |
| 33 |
true |
| 34 |
else |
| 35 |
echo "# $2 added automatically on upgrade" >> $CONFIGFILE |
| 36 |
echo "$2=" >> $CONFIGFILE |
| 37 |
fi |
| 38 |
|
| 39 |
# add to the sedscript |
| 40 |
echo "s@^ *$2=.*@$2=\"$1\"@" >>$SEDSCRIPT |
| 41 |
} |
| 42 |
|
| 43 |
subvar() { |
| 44 |
# $1 = db var name |
| 45 |
# $2 = config var name |
| 46 |
db_get $NAME/$1 |
| 47 |
subvar_raw "$RET" "$2" |
| 48 |
} |
| 49 |
|
| 50 |
subvar_yn() { |
| 51 |
# $1 = db var name |
| 52 |
# $2 = config var name |
| 53 |
db_get $NAME/$1 |
| 54 |
if [ "$RET" = "true" ]; then subvar_raw "yes" "$2"; else subvar_raw "no" "$2"; fi |
| 55 |
} |
| 56 |
|
| 57 |
case "$1" in |
| 58 |
configure) |
| 59 |
. /usr/share/debconf/confmodule |
| 60 |
|
| 61 |
# Generate config file, if it doesn't exist. |
| 62 |
if [ ! -e $CONFIGFILE ]; then |
| 63 |
tail -n +4 $TEMPLATECONFIG >$CONFIGFILE |
| 64 |
fi |
| 65 |
|
| 66 |
rm -f $SEDSCRIPT |
| 67 |
|
| 68 |
subvar_yn start-client START_CLIENT |
| 69 |
subvar run-as-user RUN_AS_USER |
| 70 |
subvar server-hostport SERVER_HOSTPORT |
| 71 |
subvar server-user SERVER_USER |
| 72 |
subvar input-type INPUT_TYPE |
| 73 |
subvar input-hostport INPUT_HOSTPORT |
| 74 |
subvar receiver-lat LAT |
| 75 |
subvar receiver-lon LON |
| 76 |
subvar receiver-alt ALT |
| 77 |
subvar results RESULTS |
| 78 |
subvar log-file LOGFILE |
| 79 |
subvar extra-args EXTRA_ARGS |
| 80 |
|
| 81 |
cp -a -f $CONFIGFILE $CONFIGFILE.tmp |
| 82 |
sed -f $SEDSCRIPT < $CONFIGFILE > $CONFIGFILE.tmp |
| 83 |
mv -f $CONFIGFILE.tmp $CONFIGFILE |
| 84 |
rm $SEDSCRIPT |
| 85 |
|
| 86 |
db_get $NAME/run-as-user |
| 87 |
RUNAS="$RET" |
| 88 |
if ! getent passwd "$RUNAS" >/dev/null |
| 89 |
then |
| 90 |
adduser --system --home /usr/share/$NAME --no-create-home --quiet "$RUNAS" |
| 91 |
fi |
| 92 |
|
| 93 |
;; |
| 94 |
|
| 95 |
abort-upgrade|abort-remove|abort-deconfigure) |
| 96 |
;; |
| 97 |
|
| 98 |
*) |
| 99 |
echo "postinst called with unknown argument \`$1'" >&2 |
| 100 |
exit 1 |
| 101 |
;; |
| 102 |
esac |
| 103 |
|
| 104 |
# dh_installdeb will replace this with shell code automatically |
| 105 |
# generated by other debhelper scripts. |
| 106 |
|
| 107 |
#DEBHELPER# |
| 108 |
|
| 109 |
if [ "$1" = "configure" ]; then db_stop; fi |
| 110 |
exit 0 |