File: inn2.postinst

package info (click to toggle)
inn2 2.4.2-3
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 2,148 kB
  • ctags: 20
  • sloc: sh: 518; makefile: 269
file content (166 lines) | stat: -rw-r--r-- 4,532 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#!/bin/sh -e

. /usr/share/debconf/confmodule
db_version 2.0

init_inn_files() {
    PATHDB=$(/usr/lib/news/bin/innconfval pathdb)
    if [ -z "$PATHDB" ]; then
	echo "Cannot determine the database path, aborting."
	exit 1
    fi
    cd $PATHDB

    for file in active newsgroups; do
	if [ ! -f $file ]; then
	    echo "Installing initial content for $PATHDB/$file"
	    install -m 644 -o news -g news \
		/usr/share/doc/inn2/examples/$file .
	fi
    done

    if [ ! -f history.dir ]; then
      echo -n "Building history database in $PATHDB... "
      if ! /usr/lib/news/bin/makehistory; then
        echo "failed!"
        return
      fi
      if ! /usr/lib/news/bin/makedbz -i -o -s 300000; then
        echo "failed!"
        return
      fi
      chown news:news history*
      chmod 664 history*
      echo "done."
    fi

    if [ ! -f active.times ]; then
	touch active.times
	chown news:news active.times
	chmod 644 active.times
    fi

    # squelch initial noise in email if this isn't present
    if [ ! -f .news.daily ]; then
	touch .news.daily
	chown news:news .news.daily
    fi

    # make sure typical log files exist, and can be rotated
    if [ ! -d /var/log/news ]; then
	install -d -m 775 -o news -g news /var/log/news
    fi
    cd /var/log/news
    [ -f news.notice ] || touch news.crit news.err news.notice
    chown news:news . OLD path news.crit news.err news.notice
}

check_usenet_alias() {
    # must have an alias for user usenet, point it to root by default
    if [ -f /etc/aliases ] && ! grep -q '^usenet:' /etc/aliases \
	    && ! getent passwd usenet; then
	echo "Adding alias for pseudo-user usenet to /etc/aliases."
	echo "usenet: root" >> /etc/aliases
	[ -x /usr/bin/newaliases ] && /usr/bin/newaliases
    fi
}

upgrade_inn_conf() {
    cd /etc/news
    if [ "$2" ] && dpkg --compare-versions "$2" lt "2.3.999+20030125-1"; then
	/usr/lib/news/bin/innupgrade -f inn.conf
    fi
}

rebuild_history_index() {
    [ -f /var/lib/news/must-rebuild-history-index ] || return 0

    cd /var/lib/news
    HLINES=$(tail -1 history.dir | awk '{ print $1 }')
    [ "$HLINES" ] || HLINES=1000000
    echo "Rebuilding the history index for $HLINES lines, please wait..."
    rm history.hash history.index history.dir
    su news -c "/usr/lib/news/bin/makedbz -s $HLINES -f history"

    rm /var/lib/news/must-rebuild-history-index
}

rebuild_overview() {
    [ -f /var/lib/news/must-rebuild-overview ] || return 0

    OVENABLED=$(/usr/lib/news/bin/innconfval enableoverview)
    if [ -z "$OVENABLED" ]; then
	echo "Cannot determine the overview method used, stopping."
	exit 1
    fi
    if [ $OVENABLED = no -o $OVENABLED = false ]; then
	return 0
    fi

    OVMETHOD=$(/usr/lib/news/bin/innconfval ovmethod)
    if [ -z "$OVMETHOD" ]; then
	echo "Cannot determine the overview method used, stopping."
	exit 1
    elif [ $OVMETHOD = tradindexed -o $OVMETHOD = ovdb ]; then
	OVPATH=$(/usr/lib/news/bin/innconfval pathoverview)
	if [ -z "$OVPATH" ]; then
	    echo "Cannot determine the overview path, aborting."
	    exit 1
	fi
	echo "Deleting the old overview database, please wait..."
	find $OVPATH -type f -not -name DB_CONFIG -print0 | xargs -0 -r rm -f
    elif [ $OVMETHOD = buffindexed ]; then
	echo "Deleting the old overview database, please wait..."
	awk -F : '/^[0-9]/ { print $2 }' < /etc/news/buffindexed.conf | \
	    while read name size; do
		dd if=/dev/zero of="$name" bs=1024 count="$size"
	    done
    else
	echo "Unknown overview method '$OVMETHOD', aborting."
	exit 1
    fi

    echo "Rebuilding the overview database, please wait..."
    su news -c "/usr/lib/news/bin/makehistory -F -O -x"

    rm /var/lib/news/must-rebuild-overview
}

case "$1" in
    configure)
    init_inn_files
    check_usenet_alias
    upgrade_inn_conf "$@"
    rebuild_history_index
    rebuild_overview
    ;;

    abort-upgrade|abort-remove|abort-deconfigure)
    ;;

    *)
    echo "postinst called with unknown argument '$1'" >&2
    ;;
esac

# punt allowing debhelper's dh_installinit to manage this, so that we can
# conditionalize the start call to the init.d fragment to prevent installs
# from failing on mis-configured systems.
if [ -x /etc/init.d/inn2 ]; then
    update-rc.d inn2 defaults > /dev/null
fi

#DEBHELPER#

# make sure we can determine the FQDN, since innd won't launch if we can't
if hostname --fqdn > /dev/null 2>&1; then
    invoke-rc.d inn2 start || echo "Could not start INN!"
else
    db_input high inn2/postinst-cannot-start || true
    db_go || true
fi

db_stop

exit 0