chiark / gitweb /
WIP inotify configure test
[inn-innduct.git] / debian / inn2.postinst
1 #!/bin/sh -e
2
3 init_inn_files() {
4     PATHDB=$(/usr/lib/news/bin/innconfval pathdb)
5     if [ -z "$PATHDB" ]; then
6         echo "Cannot determine the database path, aborting."
7         exit 1
8     fi
9     cd $PATHDB
10
11     local package='inn2'
12     if [ -e /usr/share/doc/inn2-lfs/ ]; then
13       package='inn2-lfs'
14     fi
15       
16     for file in active newsgroups; do
17         if [ ! -f $file ]; then
18             echo "Installing initial content for $PATHDB/$file"
19             install -m 644 -o news -g news \
20                 /usr/share/doc/$package/examples/$file .
21         fi
22     done
23
24     if [ ! -f history.dir ]; then
25       echo -n "Building history database in $PATHDB... "
26       if ! /usr/lib/news/bin/makehistory; then
27         echo "failed!"
28         return
29       fi
30       if ! /usr/lib/news/bin/makedbz -i -o -s 300000; then
31         echo "failed!"
32         return
33       fi
34       chown news:news history*
35       chmod 664 history*
36       echo "done."
37     fi
38
39     if [ ! -f active.times ]; then
40         touch active.times
41         chown news:news active.times
42         chmod 644 active.times
43     fi
44
45     # squelch initial noise in email if this isn't present
46     if [ ! -f .news.daily ]; then
47         touch .news.daily
48         chown news:news .news.daily
49     fi
50
51     # make sure typical log files exist, and can be rotated
52     if [ ! -d /var/log/news ]; then
53         install -d -m 775 -o news -g news /var/log/news
54     fi
55     cd /var/log/news
56     [ -f news.notice ] || touch news.crit news.err news.notice
57     chown news:news . OLD path news.crit news.err news.notice
58
59     if [ -x /etc/init.d/inn2 ]; then
60         update-rc.d inn2 defaults > /dev/null
61     fi
62 }
63
64 check_usenet_alias() {
65     # must have an alias for user usenet, point it to root by default
66     if [ -f /etc/aliases ] && ! grep -q '^usenet:' /etc/aliases \
67             && ! getent passwd usenet; then
68         echo "Adding alias for pseudo-user usenet to /etc/aliases."
69         echo "usenet: root" >> /etc/aliases
70         [ -x /usr/bin/newaliases ] && /usr/bin/newaliases
71     fi
72 }
73
74 upgrade_inn_conf() {
75     cd /etc/news
76     if [ "$2" ] && dpkg --compare-versions "$2" lt "2.3.999+20030125-1"; then
77         /usr/lib/news/bin/innupgrade -f inn.conf
78     fi
79 }
80
81 rebuild_history_index() {
82     [ -f /var/lib/news/must-rebuild-history-index ] || return 0
83
84     cd /var/lib/news
85     HLINES=$(tail -1 history.dir | awk '{ print $1 }')
86     [ "$HLINES" ] || HLINES=1000000
87     echo "Rebuilding the history index for $HLINES lines, please wait..."
88     rm history.hash history.index history.dir
89     su news -c "/usr/lib/news/bin/makedbz -s $HLINES -f history"
90
91     rm /var/lib/news/must-rebuild-history-index
92 }
93
94 rebuild_overview() {
95     [ -f /var/lib/news/must-rebuild-overview ] || return 0
96
97     OVENABLED=$(/usr/lib/news/bin/innconfval enableoverview)
98     if [ -z "$OVENABLED" ]; then
99         echo "Cannot determine the overview method used, stopping."
100         exit 1
101     fi
102     if [ $OVENABLED = no -o $OVENABLED = false ]; then
103         return 0
104     fi
105
106     OVMETHOD=$(/usr/lib/news/bin/innconfval ovmethod)
107     if [ -z "$OVMETHOD" ]; then
108         echo "Cannot determine the overview method used, stopping."
109         exit 1
110     elif [ $OVMETHOD = tradindexed -o $OVMETHOD = ovdb ]; then
111         OVPATH=$(/usr/lib/news/bin/innconfval pathoverview)
112         if [ -z "$OVPATH" ]; then
113             echo "Cannot determine the overview path, aborting."
114             exit 1
115         fi
116         echo "Deleting the old overview database, please wait..."
117         find $OVPATH -type f -not -name DB_CONFIG -print0 | xargs -0 -r rm -f
118     elif [ $OVMETHOD = buffindexed ]; then
119         echo "Deleting the old overview database, please wait..."
120         awk -F : '/^[0-9]/ { print $2 }' < /etc/news/buffindexed.conf | \
121             while read name size; do
122                 dd if=/dev/zero of="$name" bs=1024 count="$size"
123             done
124     else
125         echo "Unknown overview method '$OVMETHOD', aborting."
126         exit 1
127     fi
128
129     echo "Rebuilding the overview database, please wait..."
130     su news -c "/usr/lib/news/bin/makehistory -F -O -x"
131
132     rm /var/lib/news/must-rebuild-overview
133 }
134
135 start_innd() {
136 # make sure we can determine the FQDN, since innd won't launch if we can't
137 if hostname --fqdn > /dev/null 2>&1; then
138     invoke-rc.d inn2 start || echo "Could not start INN!"
139 else
140 cat <<END
141
142
143 Not starting innd.  The daemon needs to be able to determine the name of
144 this machine, and your /etc/hosts and/or DNS config is apparently not
145 allowing this to happen.  After you have fixed things so that 'hostname
146 --fqdn' returns a reasonable value, you can start the daemon by running
147 '/etc/init.d/inn2 start'.
148
149
150 END
151 fi
152 }
153
154 case "$1" in
155     configure)
156     init_inn_files
157     check_usenet_alias
158     upgrade_inn_conf "$@"
159     rebuild_history_index
160     rebuild_overview
161     if [ -z "$2" -o ! -e /var/run/news/innd.pid ]; then # first install
162         start_innd
163     else
164         ctlinnd -t 20 throttle "upgrade" > /dev/null || true
165         ctlinnd -t 20 xexec inndstart > /dev/null \
166             || echo "Could not restart INN!"
167     fi
168     ;;
169
170     abort-upgrade|abort-remove|abort-deconfigure)
171     ;;
172
173     *)
174     echo "postinst called with unknown argument '$1'" >&2
175     ;;
176 esac
177
178 #DEBHELPER#
179
180 exit 0
181