debian/masqmail-debian

view postinst @ 56:8638dc3d7bcd

added a note about `set -e' in init scripts We should work on that some day.
author meillo@marmaro.de
date Mon, 19 Jul 2010 12:25:29 +0200
parents 5ef519035828
children
line source
1 #!/bin/sh
2 set -e
4 # source debconf library
5 . /usr/share/debconf/confmodule
7 CONFIGFILE=/etc/masqmail/masqmail.conf
8 WORKTMP=$CONFIGFILE.tmp
9 DEBCONFTMP=$CONFIGFILE.debconf
11 DEFAULTSFILE=/etc/default/masqmail
12 DEBDEFTMP=$DEFAULTSFILE.debconf
14 create_db_conf (){
15 rm -f $WORKTMP $DEBCONFTMP
17 cat >> $DEBCONFTMP << EOF
18 ### BEGIN DEBCONF SECTION
19 # Do not edit within this region if you want your changes to be preserved by
20 # debconf. Instead, make changes after the "### END DEBCONF SECTION" line.
21 EOF
23 db_get masqmail/host_name || true
24 echo "host_name=\"$RET\"" >> $DEBCONFTMP
25 db_get masqmail/local_hosts || true
26 echo "local_hosts=\"$RET\"" >> $DEBCONFTMP
27 db_get masqmail/local_nets || true
28 echo "local_nets=\"$RET\"" >> $DEBCONFTMP
29 db_get masqmail/listen_addresses || true
30 echo "listen_addresses=\"$RET\"" >> $DEBCONFTMP
32 echo "spool_dir=\"/var/spool/masqmail\"" >> $DEBCONFTMP
33 echo "mail_dir=\"/var/mail\"" >> $DEBCONFTMP
34 echo "log_dir=\"/var/log/masqmail\"" >> $DEBCONFTMP
35 echo "do_queue=false" >> $DEBCONFTMP
37 db_get masqmail/use_syslog || true
38 echo "use_syslog=$RET" >> $DEBCONFTMP
40 db_get masqmail/online_detect || true
41 echo "online_detect=$RET" >> $DEBCONFTMP
42 if [ "$RET" = "file" ] ; then
43 db_get masqmail/online_file || true
44 echo "online_file=\"$RET\"" >> $DEBCONFTMP
45 else
46 db_get masqmail/online_pipe || true
47 echo "online_pipe=\"$RET\"" >> $DEBCONFTMP
48 fi
50 db_get masqmail/mbox_default || true
51 echo "mbox_default=$RET" >> $DEBCONFTMP
52 db_get masqmail/mda || true
53 echo "mda=\"$RET\"" >> $DEBCONFTMP
55 echo "alias_file=/etc/aliases" >> $DEBCONFTMP
56 db_get masqmail/alias_local_caseless || true
57 echo "alias_local_caseless=\"$RET\"" >> $DEBCONFTMP
59 cat >> $DEBCONFTMP << EOF
60 ### END DEBCONF SECTION
61 EOF
62 }
64 write_db_conf (){
66 if [ -e $CONFIGFILE ]; then
67 # does the file have debconf markers in it?
68 if egrep -q '^### BEGIN DEBCONF SECTION' $CONFIGFILE && \
69 egrep -q '^### END DEBCONF SECTION' $CONFIGFILE; then
70 # see if the beginning of the file was left alone; sed cannot backtrack in
71 # an address range
72 if ! head -1 $CONFIGFILE | egrep -q '^### BEGIN DEBCONF SECTION'; then
73 # sick, sick, sick
74 LINES=$(sed -n '1,/^### BEGIN DEBCONF SECTION/p' < $CONFIGFILE | wc -l)
75 sed -n 1,$(( $LINES - 1 ))p < $CONFIGFILE > $WORKTMP
76 fi
77 cat $DEBCONFTMP >> $WORKTMP
78 sed -n '/^### END DEBCONF SECTION/,$p' < $CONFIGFILE | tail -n +2 >> $WORKTMP
79 else
80 echo "Existing $CONFIGFILE has missing or half-open debconf region;" >&2;
81 echo "not writing masqmail configuration file." >&2;
82 exit 1
83 fi
84 else
85 cat >> $DEBCONFTMP << EOF
86 #
87 # include the locations of your route and get configurations here.
88 # Examples:
89 # online_routes.default = "/etc/masqmail/default.route"
90 # online_gets.default = "/etc/masqmail/default.get"
91 # You can have more of those, with '.default' replaced with other
92 # names. See man 8 masqmail.conf.
93 #
94 EOF
95 cp $DEBCONFTMP $WORKTMP
96 fi
98 mv $WORKTMP $CONFIGFILE
100 # rm -f $WORKTMP $DEBCONFTMP
101 }
103 create_db_defaults () {
104 cat >> $DEBDEFTMP << EOF
105 #
106 # better use 'dpkg-reconfigure masqmail'
107 # instead of editing by hand
108 #
109 EOF
111 db_get masqmail/init_smtp_daemon || true
112 echo "INIT_SMTP_DAEMON=\"$RET\"" >> $DEBDEFTMP
113 db_get masqmail/init_queue_daemon || true
114 echo "INIT_QUEUE_DAEMON=\"$RET\"" >> $DEBDEFTMP
115 db_get masqmail/init_fetch_daemon || true
116 echo "INIT_FETCH_DAEMON=\"$RET\"" >> $DEBDEFTMP
118 echo "#" >> $DEBDEFTMP
120 db_get masqmail/queue_daemon_ival || true
121 echo "QUEUE_DAEMON_IVAL=\"$RET\"" >> $DEBDEFTMP
122 db_get masqmail/fetch_daemon_ival || true
123 echo "FETCH_DAEMON_IVAL=\"$RET\"" >> $DEBDEFTMP
125 echo "#" >> $DEBDEFTMP
127 db_get masqmail/ipup_runqueue || true
128 echo "IPUP_RUNQUEUE=\"$RET\"" >> $DEBDEFTMP
129 db_get masqmail/ipup_fetch || true
130 echo "IPUP_FETCH=\"$RET\"" >> $DEBDEFTMP
132 db_get masqmail/ifup_ifaces || true
133 echo "IFUP_IFACES=\"$RET\"" >> $DEBDEFTMP
134 }
136 write_db_defaults () {
137 mv $DEBDEFTMP $DEFAULTSFILE
138 }
140 case "$1" in
141 configure)
143 # Create spool and log directories
144 install -d -omail -gmail /var/log/masqmail
145 install -d -omail -gmail /var/spool/masqmail
146 install -d -omail -gmail /var/spool/masqmail/input
147 install -d -omail -gmail /var/spool/masqmail/lock
148 install -d -omail -gmail /var/spool/masqmail/popuidl
150 db_get masqmail/manage_config_with_debconf || true
151 if [ "$RET" = "true" ]; then
152 db_get masqmail/move_existing_nondebconf_config || true
153 if [ "$RET" = "true" ]; then
154 create_db_conf
155 write_db_conf
156 fi
157 create_db_defaults
158 write_db_defaults
159 fi
161 ;;
163 abort-upgrade|abort-remove|abort-deconfigure)
164 ;;
165 esac
167 #DEBHELPER#