Projekt

Obecné

Profil

Stáhnout (2.23 KB) Statistiky
| Větev: | Tag: | Revize:
5af3ffcf Ondřej Fibich
#!/bin/bash
# FreenetIS-qos DEB: actions after installing of package

set -e
. /usr/share/debconf/confmodule

NAME=freenetis-qos
CONFIGFILE=/etc/freenetis/freenetis-qos.conf

# Quit if config file is missing.
if [ ! -e $CONFIGFILE ]; then
echo "$CONFIGFILE not founded!"
exit 1
fi

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-qos/path_freenetis
PATH_FN="$RET"

db_get freenetis-qos/input_interface
INPUT_INTERFACE="$RET"

db_get freenetis-qos/output_interface
OUTPUT_INTERFACE="$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 input iface
if [ -z "$INPUT_INTERFACE" ]; then
echo "Empty input interface, configuration failed!"
exit 3
fi

# check output iface
if [ -z "$OUTPUT_INTERFACE" ]; then
echo "Empty output interface, configuration failed!"
exit 3
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 "$INPUT_INTERFACE" || grep -Eq '^ *INPUT_INTERFACE=' $CONFIGFILE || echo "INPUT_INTERFACE=" >> $CONFIGFILE
test -z "$OUTPUT_INTERFACE" || grep -Eq '^ *OUTPUT_INTERFACE=' $CONFIGFILE || echo "OUTPUT_INTERFACE=" >> $CONFIGFILE

PATH_FN_ESCAPED="${PATH_FN//\//\\/}"
INPUT_INTERFACE_ESCAPED="${INPUT_INTERFACE//\//\\/}"
OUTPUT_INTERFACE_ESCAPED="${OUTPUT_INTERFACE//\//\\/}"

sed -e "s/^ *PATH_FN=.*/PATH_FN=\"$PATH_FN_ESCAPED\"/" \
-e "s/^ *INPUT_INTERFACE=.*/INPUT_INTERFACE=\"$INPUT_INTERFACE_ESCAPED\"/" \
-e "s/^ *OUTPUT_INTERFACE=.*/OUTPUT_INTERFACE=\"$OUTPUT_INTERFACE_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-qos defaults

exit 0