1
0

ngircd.config 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #!/bin/sh
  2. set -e
  3. # Source debconf library.
  4. . /usr/share/debconf/confmodule
  5. NGIRCD=/usr/sbin/ngircd
  6. CONFIG=/etc/ngircd/ngircd.conf
  7. CONVERT=/usr/share/ngircd/ngircd-conf-convert
  8. [ -x "$NGIRCD" ] || exit 0
  9. [ -f "$CONFIG" ] || exit 0
  10. [ -x "$CONVERT" ] || exit 0
  11. TEMPDIR=
  12. # conversion required?
  13. if grep -qiE '^[ \t]*\[(Limits|Options|SSL)\]' "$CONFIG" ; then
  14. # Using new section names, we're done
  15. exit 0
  16. fi
  17. while true ; do
  18. # Shall we do conversion?
  19. db_reset ngircd/conversion-do
  20. db_input high ngircd/conversion-do || true
  21. db_go
  22. db_get ngircd/conversion-do
  23. if [ "$RET" = "false" ]; then
  24. break
  25. fi
  26. # Check old configuration
  27. if </dev/null "$NGIRCD" --configtest --config "$CONFIG" >/dev/null ; then
  28. :
  29. else
  30. # broken
  31. db_input high ngircd/broken-oldconfig || true
  32. db_go
  33. break
  34. fi
  35. # have a temporary directory
  36. TEMPDIR=$(mktemp -d /tmp/ngircd.XXXXX)
  37. [ "$TEMPDIR" ] && [ -d "$TEMPDIR" ] || exit 0
  38. chmod 700 "$TEMPDIR"
  39. # create new configuration
  40. CONFIG_NEW="$TEMPDIR/ngircd.conf"
  41. touch "$CONFIG_NEW"
  42. "$CONVERT" "$CONFIG" "$CONFIG_NEW"
  43. if cmp -s "$CONFIG" "$CONFIG_NEW" ; then
  44. echo "Nothing to do."
  45. break
  46. fi
  47. # create dumps from --configtest and compare
  48. DUMP_OLD="$TEMPDIR/dump.old"
  49. </dev/null "$NGIRCD" --configtest --config "$CONFIG" |
  50. sed -n '/GLOBAL/,$p' >"$DUMP_OLD"
  51. DUMP_NEW="$TEMPDIR/dump.new"
  52. </dev/null "$NGIRCD" --configtest --config "$CONFIG_NEW" |
  53. sed -n '/GLOBAL/,$p' >"$DUMP_NEW"
  54. if cmp -s "$DUMP_OLD" "$DUMP_NEW" ; then
  55. # success
  56. CONFIG_BAK="$CONFIG.pre18"
  57. chown --reference="$CONFIG" "$CONFIG_NEW"
  58. chmod --reference="$CONFIG" "$CONFIG_NEW"
  59. mv "$CONFIG" "$CONFIG_BAK"
  60. mv "$CONFIG_NEW" "$CONFIG"
  61. echo "Conversion and verification sucessfull. Your configuration file is at"
  62. echo " $CONFIG"
  63. echo "A backup of the old configuration has been saved to"
  64. echo " $CONFIG_BAK"
  65. break
  66. fi
  67. DIFF="$(sdiff -BbW "$DUMP_OLD" "$DUMP_NEW")"
  68. db_capb escape
  69. db_subst ngircd/conversion-fail DIFF "$(printf %s "$DIFF" | debconf-escape -e)"
  70. db_input critical ngircd/conversion-fail || true
  71. db_go
  72. db_reset ngircd/conversion-fail
  73. db_capb
  74. break
  75. done
  76. # cleanup
  77. db_purge
  78. [ "$TEMPDIR" ] && rm -rf "$TEMPDIR"
  79. exit 0