comparison debian/postinst @ 425:c2fd00030991 noffle

[svn] added preliminary ucf support
author godisch
date Fri, 20 Jun 2003 17:48:28 +0100
parents e5bd838e0c27
children 011e51924b23
comparison
equal deleted inserted replaced
424:afa2ff7b5ebf 425:c2fd00030991
1 #!/bin/sh 1 #!/bin/sh
2 # $Id: postinst 562 2003-06-20 06:05:22Z godisch $ 2 # $Id: postinst 568 2003-06-20 16:48:28Z godisch $
3 3
4 set -e 4 set -e
5 5
6 [ "$1" = configure ] || exit 0 6 [ "$1" = configure ] || exit 0
7
8 server_config=/etc/news/noffle.conf
9 debian_config=/etc/default/noffle
10 7
11 maxfetch_default=300 8 maxfetch_default=300
12 defexpire_default=14 9 defexpire_default=14
13 10
14 if dpkg --compare-versions "$2" lt-nl 1.1.2-1; then 11 if dpkg --compare-versions "$2" lt-nl 1.1.2-1; then
15 echo 12 echo
16 echo "/etc/noffle/conf moved to $server_config, /etc/noffle/conf.debian" 13 echo "/etc/noffle/conf moved to /etc/news/noffle.conf, /etc/noffle/conf.debian"
17 echo "moved to $debian_config. /etc/noffle and /var/log/noffle are not" 14 echo "moved to /etc/default/noffle. /etc/noffle and /var/log/noffle are not"
18 echo "used any longer, you may remove them. noffle expiration logs are" 15 echo "used any longer, you may remove them. noffle expiration logs are"
19 echo "still available through syslog." 16 echo "still available through syslog."
20 echo 17 echo
21 sleep 2 18 sleep 2
22 mv -f /etc/noffle/conf $server_config || : 19 mv -f /etc/noffle/conf /etc/news/noffle.conf || :
23 mv -f /etc/noffle/conf.debian $debian_config || : 20 mv -f /etc/noffle/conf.debian /etc/default/noffle || :
24 mv -f /etc/noffle/conf.old $server_config.old 2> /dev/null || : 21 mv -f /etc/noffle/conf.old /etc/news/noffle.conf.old 2> /dev/null || :
25 mv -f /etc/noffle/conf.debian.old $debian_config.old 2> /dev/null || : 22 mv -f /etc/noffle/conf.debian.old /etc/default/noffle.old 2> /dev/null || :
26 rmdir --ignore-fail-on-non-empty /etc/noffle 23 rmdir --ignore-fail-on-non-empty /etc/noffle
27 fi 24 fi
28 25
29 if dpkg --compare-versions "$2" eq 1.1.2-1; then 26 if dpkg --compare-versions "$2" eq 1.1.2-1; then
30 # 1.1.2-1 was in unstable only, don't notify 27 # 1.1.2-1 was in unstable only, don't notify
31 mv -f /etc/noffle.conf $server_config || : 28 mv -f /etc/noffle.conf /etc/news/noffle.conf || :
32 mv -f /etc/noffle.conf.old $server_config.old 2> /dev/null || : 29 mv -f /etc/noffle.conf.old /etc/news/noffle.conf.old 2> /dev/null || :
33 fi 30 fi
34 31
35 if [ -e /usr/share/debconf/confmodule ]; then 32 if [ -e /usr/share/debconf/confmodule ]; then
36 . /usr/share/debconf/confmodule 33 . /usr/share/debconf/confmodule
37 db_version 2.0 34 db_version 2.0
38 db_get noffle/debconf 35
39 if [ "$RET" = true ]; then 36 db_get noffle/port
40 db_get noffle/port 37 port="$RET"
41 port="$RET" 38 if [ -z "$port" -o "$port" = 119 ]; then
42 if [ -z "$port" -o "$port" = 119 ]; then 39 port=nntp
43 port=nntp
44 fi
45 # maybe disabled only, e.g. dpkg -r noffle
46 update-inetd --remove "/usr/bin/noffle -r" || :
47 update-inetd --group MAIL --add "$port\tstream\ttcp\tnowait\tnews\t/usr/sbin/tcpd /usr/bin/noffle -r"
48 db_get noffle/server
49 server="$RET"
50 [ "$server" ] || server=news
51 db_get noffle/username
52 username="$RET"
53 db_get noffle/password
54 password="$RET"
55 db_get noffle/fetchmode
56 fetchmode="$RET"
57 [ "$fetchmode" ] || if [ -x /usr/sbin/pppd ]; then
58 fetchmode=ppp
59 else
60 fetchmode=cron
61 fi
62 db_get noffle/maxfetch
63 maxfetch="$RET"
64 [ "$maxfetch" ] || maxfetch="$maxfetch_default"
65 db_get noffle/default-expire
66 defexpire="$RET"
67 [ "$defexpire" ] || defexpire="$defexpire_default"
68 # try to be idempotent
69 if [ ! -e $server_config.new -a ! -e $debian_config.new ]; then
70 # make some backup files
71 cmp -s $server_config $server_config.old || \
72 cp -pf $server_config $server_config.old 2> /dev/null || :
73 cmp -s $debian_config $debian_config.old || \
74 cp -pf $debian_config $debian_config.old 2> /dev/null || :
75 fi
76 # $server_config may contain sensitive information for NNTP authentication
77 umask 027
78 # we need to use sed instead of Perl to avoid another package dependency
79 cat /usr/share/noffle/noffle.conf | \
80 sed "s/^server[[:space:]].*/server $server $username $password/" | \
81 sed "s/^max-fetch[[:space:]].*/max-fetch $maxfetch/" | \
82 sed "s/^default-expire[[:space:]].*/default-expire $defexpire/" \
83 > $server_config.new
84 chgrp news $server_config.new
85 umask 022
86 cat /usr/share/noffle/conf.debian | \
87 sed "s/^NOFFLE_FETCHMODE=.*/NOFFLE_FETCHMODE=$fetchmode/" \
88 > $debian_config.new
89 mv -f $server_config.new $server_config
90 mv -f $debian_config.new $debian_config
91 fi 40 fi
41 update-inetd --remove "/usr/bin/noffle -r" || :
42 update-inetd --group MAIL --add "$port\tstream\ttcp\tnowait\tnews\t/usr/sbin/tcpd /usr/bin/noffle -r"
43
44 db_get noffle/server
45 server="$RET"
46 [ "$server" ] || server=news
47 db_get noffle/username
48 username="$RET"
49 db_get noffle/password
50 password="$RET"
51 db_get noffle/fetchmode
52 fetchmode="$RET"
53 [ "$fetchmode" ] || if [ -x /usr/sbin/pppd ]; then
54 fetchmode=ppp
55 else
56 fetchmode=cron
57 fi
58 db_get noffle/maxfetch
59 maxfetch="$RET"
60 [ "$maxfetch" ] || maxfetch="$maxfetch_default"
61 db_get noffle/default-expire
62 defexpire="$RET"
63 [ "$defexpire" ] || defexpire="$defexpire_default"
64
65 # /etc/news/noffle.conf may contain sensitive information for NNTP authentication
66 umask 027
67 cat /usr/share/noffle/noffle.conf | \
68 sed "s/^server[[:space:]].*/server $server $username $password/" | \
69 sed "s/^max-fetch[[:space:]].*/max-fetch $maxfetch/" | \
70 sed "s/^default-expire[[:space:]].*/default-expire $defexpire/" \
71 > /etc/news/noffle.conf.new
72 chgrp news /etc/news/noffle.conf.new
73 ucf --three-way /etc/news/noffle.conf.new /etc/news/noffle.conf < /dev/tty
74 rm -f /etc/news/noffle.conf.new
75
76 umask 022
77 cat /usr/share/noffle/conf.debian | \
78 sed "s/^NOFFLE_FETCHMODE=.*/NOFFLE_FETCHMODE=$fetchmode/" \
79 > /etc/default/noffle.new
80 ucf --three-way /etc/default/noffle.new /etc/default/noffle < /dev/tty
81 rm -f /etc/default/noffle.new
82
92 db_stop 83 db_stop
93 else 84 else
94 # no debconf available 85 # no debconf available
95 if [ ! -e $server_config ]; then 86 ucf --three-way /usr/share/noffle/noffle.conf /etc/news/noffle.conf < /dev/tty
96 umask 027 87 ucf --three-way /usr/share/noffle/conf.debian /etc/default/noffle < /dev/tty
97 cp -f /usr/share/noffle/noffle.conf $server_config.new
98 chgrp news $server_config.new
99 mv -fb $server_config.new $server_config
100 fi
101 if [ ! -e $debian_config ]; then
102 umask 022
103 cp -f /usr/share/noffle/conf.debian $debian_config.new
104 mv -fb $debian_config.new $debian_config
105 fi
106 if ! grep -q "/usr/bin/noffle -r" /etc/inetd.conf; then 88 if ! grep -q "/usr/bin/noffle -r" /etc/inetd.conf; then
107 # just an example, the user needs to activate it himself 89 # just an example, the user needs to activate it himself
108 # update-inetd will silently fail if nntp is already occupied 90 # update-inetd will silently fail if nntp is already occupied
109 update-inetd --group MAIL --add "nntp\tstream\ttcp\tnowait\tnews\t/usr/sbin/tcpd /usr/bin/noffle -r" 91 update-inetd --group MAIL --add "nntp\tstream\ttcp\tnowait\tnews\t/usr/sbin/tcpd /usr/bin/noffle -r"
110 if grep -q "^nntp.*/usr/bin/noffle -r"; then 92 if grep -q "^nntp.*/usr/bin/noffle -r"; then
111 update-inetd --disable nntp 93 update-inetd --disable nntp
112 fi 94 fi
95 echo
96 echo "You need to active noffle manually in /etc/inetd.conf."
97 echo
98 sleep 2
113 fi 99 fi
114 fi 100 fi
115 101
116 # sanity checks 102 # sanity checks
117 chown -R news:news /var/lock/noffle /var/spool/noffle 103 chown -R news:news /var/lock/noffle /var/spool/noffle