123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- #!/bin/sh
- set -e
- # Source debconf library.
- . /usr/share/debconf/confmodule
- NGIRCD=/usr/sbin/ngircd
- CONFIG=/etc/ngircd/ngircd.conf
- CONVERT=/usr/share/ngircd/ngircd-conf-convert
- [ -x "$NGIRCD" ] || exit 0
- [ -f "$CONFIG" ] || exit 0
- [ -x "$CONVERT" ] || exit 0
- TEMPDIR=
- # conversion required?
- if grep -qiE '^[ \t]*\[(Limits|Options|SSL)\]' "$CONFIG" ; then
- # Using new section names, we're done
- exit 0
- fi
- while true ; do
- # Shall we do conversion?
- db_reset ngircd/conversion-do
- db_input high ngircd/conversion-do || true
- db_go
- db_get ngircd/conversion-do
- if [ "$RET" = "false" ]; then
- break
- fi
- # Check old configuration
- if </dev/null "$NGIRCD" --configtest --config "$CONFIG" >/dev/null ; then
- :
- else
- # broken
- db_input high ngircd/broken-oldconfig || true
- db_go
- break
- fi
- # have a temporary directory
- TEMPDIR=$(mktemp -d /tmp/ngircd.XXXXX)
- [ "$TEMPDIR" ] && [ -d "$TEMPDIR" ] || exit 0
- chmod 700 "$TEMPDIR"
- # create new configuration
- CONFIG_NEW="$TEMPDIR/ngircd.conf"
- touch "$CONFIG_NEW"
- "$CONVERT" "$CONFIG" "$CONFIG_NEW"
- if cmp -s "$CONFIG" "$CONFIG_NEW" ; then
- echo "Nothing to do."
- break
- fi
- # create dumps from --configtest and compare
- DUMP_OLD="$TEMPDIR/dump.old"
- </dev/null "$NGIRCD" --configtest --config "$CONFIG" |
- sed -n '/GLOBAL/,$p' >"$DUMP_OLD"
- DUMP_NEW="$TEMPDIR/dump.new"
- </dev/null "$NGIRCD" --configtest --config "$CONFIG_NEW" |
- sed -n '/GLOBAL/,$p' >"$DUMP_NEW"
- if cmp -s "$DUMP_OLD" "$DUMP_NEW" ; then
- # success
- CONFIG_BAK="$CONFIG.pre18"
- chown --reference="$CONFIG" "$CONFIG_NEW"
- chmod --reference="$CONFIG" "$CONFIG_NEW"
- mv "$CONFIG" "$CONFIG_BAK"
- mv "$CONFIG_NEW" "$CONFIG"
- echo "Conversion and verification sucessfull. Your configuration file is at"
- echo " $CONFIG"
- echo "A backup of the old configuration has been saved to"
- echo " $CONFIG_BAK"
- break
- fi
- DIFF="$(sdiff -BbW "$DUMP_OLD" "$DUMP_NEW")"
- db_capb escape
- db_subst ngircd/conversion-fail DIFF "$(printf %s "$DIFF" | debconf-escape -e)"
- db_input critical ngircd/conversion-fail || true
- db_go
- db_reset ngircd/conversion-fail
- db_capb
- break
- done
- # cleanup
- db_purge
- [ "$TEMPDIR" ] && rm -rf "$TEMPDIR"
- exit 0
|