|
#!/bin/bash
|
|
# FreenetIS-dhcp DEB: actions after installing of package
|
|
|
|
set -e
|
|
. /usr/share/debconf/confmodule
|
|
|
|
NAME=freenetis-dhcp
|
|
CONFIGFILE=/etc/freenetis/freenetis-dhcp.conf
|
|
|
|
# Quit if config file is missing.
|
|
if [ ! -e $CONFIGFILE ]; then
|
|
echo "$CONFIGFILE not founded!"
|
|
exit 1
|
|
fi
|
|
|
|
. $CONFIGFILE
|
|
|
|
url_regex='(https?|ftp|file)://[-A-Za-z0-9\+&@#/%?=~_|!:,.;]*[-A-Za-z0-9\+&@#/%=~_|]'
|
|
|
|
# Substitute in the values from the debconf db.
|
|
# There are obvious optimizations possible here.
|
|
# The cp before the sed ensures we do not mess up
|
|
# the config file’s ownership and permissions.
|
|
|
|
db_get freenetis-dhcp/path_freenetis
|
|
PATH_FN="$RET"
|
|
|
|
db_get freenetis-dhcp/device_id
|
|
DEVICE_ID="$RET"
|
|
|
|
db_get freenetis-dhcp/timeout
|
|
TIMEOUT="$RET"
|
|
|
|
# check path
|
|
if [ -z "$PATH_FN" ]; then
|
|
echo "Empty path to FreenetIS instance, configuration failed!"
|
|
exit 3
|
|
fi
|
|
|
|
# check path format
|
|
if [[ ! "$PATH_FN" =~ $url_regex ]]; then
|
|
echo "Wrong format of the path to FreenetIS instance, configuration failed!"
|
|
exit 3
|
|
fi
|
|
|
|
# check device ID
|
|
if [[ ! "$DEVICE_ID" =~ ^[0-9]+$ ]] || [ $DEVICE_ID -lt 1 ]; then
|
|
echo "Wrong configuration (ID not set properly), configuration failed!" 1>&2
|
|
exit 1
|
|
fi
|
|
|
|
# check timeout ID
|
|
if [[ ! "$TIMEOUT" =~ ^[0-9]+$ ]] || [ $TIMEOUT -lt 1 ]; then
|
|
echo "Wrong configuration (TIMEOUT not set properly), configuration failed!" 1>&2
|
|
exit 1
|
|
fi
|
|
|
|
cp -a -f $CONFIGFILE $CONFIGFILE.tmp
|
|
|
|
# If the admin deleted or commented some variables but then set
|
|
# them via debconf, (re-)add them to the conffile.
|
|
|
|
test -z "$PATH_FN" || grep -Eq '^ *PATH_FN=' $CONFIGFILE || echo "PATH_FN=" >> $CONFIGFILE
|
|
test -z "$DEVICE_ID" || grep -Eq '^ *DEVICE_ID=' $CONFIGFILE || echo "DEVICE_ID=" >> $CONFIGFILE
|
|
test -z "$TIMEOUT" || grep -Eq '^ *TIMEOUT=' $CONFIGFILE || echo "TIMEOUT=" >> $CONFIGFILE
|
|
|
|
PATH_FN_ESCAPED="${PATH_FN//\//\\/}"
|
|
DEVICE_ID_ESCAPED="${DEVICE_ID//\//\\/}"
|
|
TIMEOUT_ESCAPED="${TIMEOUT//\//\\/}"
|
|
|
|
sed -e "s/^ *PATH_FN=.*/PATH_FN=\"$PATH_FN_ESCAPED\"/" \
|
|
-e "s/^ *DEVICE_ID=.*/DEVICE_ID=\"$DEVICE_ID_ESCAPED\"/" \
|
|
-e "s/^ *TIMEOUT=.*/TIMEOUT=\"$TIMEOUT_ESCAPED\"/" < $CONFIGFILE > $CONFIGFILE.tmp
|
|
|
|
mv -f $CONFIGFILE.tmp $CONFIGFILE
|
|
|
|
# Make post install things
|
|
|
|
# 1) Startup at boot
|
|
|
|
# set on fire after boot
|
|
update-rc.d freenetis-dhcp defaults
|
|
|
|
exit 0
|