Debian Codegraph @

debian/qpsmtpd.postinst

raw
1 #!/bin/sh
2
3 set -e
4
5 RUNAS=qpsmtpd
6 SPOOLDIR=/var/spool/qpsmtpd
7 GREYLISTDIR=/var/lib/qpsmtpd/greylisting
8 LOGDIR=/var/log/qpsmtpd
9 PIDDIR=/var/run/qpsmtpd
10
11 if [ -e /etc/qpsmtpd/debconf-settings ] ; then
12 . /etc/qpsmtpd/debconf-settings
13 fi
14
15 if [ -e /usr/share/debconf/confmodule ] ; then
16 . /usr/share/debconf/confmodule
17 fi
18
19 setup_debconf()
20 {
21 # extract the configuration from debconf and write it where qpsmtpd
22 # can find it, now that the destination exists
23
24 db_get qpsmtpd/startup_enabled
25 ENABLED="$RET"
26
27 db_get qpsmtpd/server_type
28 SERVER="$RET"
29
30 db_get qpsmtpd/listen_interfaces
31 INTERFACES="$RET"
32
33 db_get qpsmtpd/queue_plugin
34 QUEUE_PLUGIN="$RET"
35
36 db_get qpsmtpd/queue_maildir_destination
37 QUEUE_MAILDIR_DESTINATION="$RET"
38
39 db_get qpsmtpd/queue_smtp_proxy_destination
40 QUEUE_PROXY_DESTINATION="$RET"
41
42 db_get qpsmtpd/rcpthosts
43 RCPTHOSTS="$RET"
44
45 TMP=`mktemp /etc/qpsmtpd/.tmp.debconf-settings.$$.XXXXXX`
46 ( echo "# auto-generated by $0 at `date`" ; cat <<"EOT"
47 #
48 # This is a copy of the qpsmtpd debconf settings for use at startup time.
49 # Please don't edit it directly -- if you need to change any of these
50 # settings, run 'dpkg-reconfigure qpsmtpd'.
51 EOT
52 echo "ENABLED=\"$ENABLED\""
53 echo "SERVER=\"$SERVER\""
54 echo "INTERFACES=\"$INTERFACES\""
55 echo "QUEUE_PLUGIN=\"$QUEUE_PLUGIN\""
56 echo "QUEUE_MAILDIR_DESTINATION=\"$QUEUE_MAILDIR_DESTINATION\""
57 echo "QUEUE_PROXY_DESTINATION=\"$QUEUE_PROXY_DESTINATION\""
58 ) > "$TMP"
59
60 mv -f "$TMP" "/etc/qpsmtpd/debconf-settings" || ( rm -f "$TMP" && false )
61 chmod 0644 "/etc/qpsmtpd/debconf-settings"
62
63 TMP=`mktemp /etc/qpsmtpd/.tmp.debconf-queue-select.$$.XXXXXX`
64 ( echo "# auto-generated by $0 at `date`" ; cat <<"EOT"
65 #
66 # This is the qpsmtpd queue plugin selection generated by debconf at
67 # package installation. It reflects the choice of queue method selected
68 # by the debconf UI. Please do not edit it directly -- it will be overwritten
69 # on subsequent package upgrades. To change the queueing/delivery
70 # method, either run 'dpkg-reconfigure qpsmtpd' and pick a different method,
71 # or edit /etc/qpsmtpd/plugins to remove the $include reference to this file,
72 # then pick whatever queue plugin you prefer.
73 EOT
74 if [ "$QUEUE_PLUGIN" = "exim" ] ; then
75 echo "queue/exim-bsmtp"
76 elif [ "$QUEUE_PLUGIN" = "postfix" ] ; then
77 echo "queue/postfix-queue"
78 elif [ "$QUEUE_PLUGIN" = "proxy" ] ; then
79 echo -n "queue/smtp-forward "
80 echo "$QUEUE_PROXY_DESTINATION" | tr ":" " "
81 elif [ "$QUEUE_PLUGIN" = "qmail" ] ; then
82 echo "queue/qmail-queue /usr/sbin/qmail-queue"
83 elif [ "$QUEUE_PLUGIN" = "maildir" ] ; then
84 echo "queue/maildir $QUEUE_MAILDIR_DESTINATION"
85 fi
86 echo
87 ) > "$TMP"
88 mv -f "$TMP" "/etc/qpsmtpd/debian-queue-method"
89 chmod 0644 "/etc/qpsmtpd/debian-queue-method"
90
91 TMP=`mktemp /etc/qpsmtpd/.tmp.debconf-rcpthosts.$$.XXXXXX`
92 ( echo "# auto-generated by $0 at `date`" ; cat <<"EOT"
93 #
94 # This is the Debian-specific qpsmtpd rcpthosts setting, containing the list of
95 # host and domain names for which qpsmtpd will accept mail. It should include
96 # all locally-delivered domain names as well as those for which you wish to
97 # relay mail. This file was generated by debconf when qpsmtpd was installed or
98 # (re)configured. To alter it, please run 'dpkg-reconfigure qpsmtpd'. If you
99 # prefer to edit the rcpthosts list manually, edit /etc/qpstmpd/rcpthosts and
100 # remove the $include reference to this file.
101 EOT
102 echo "$RCPTHOSTS" | perl -pe 's/[\s,]+/\n/g'
103 ) > "$TMP"
104 mv -f "$TMP" "/etc/qpsmtpd/debian-rcpthosts"
105 chmod 0644 "/etc/qpsmtpd/debian-rcpthosts"
106 }
107
108 setup_systemd()
109 {
110 # Carry the ENABLED answer over to the unit, the way the init script
111 # gated on it at every start
112 if command -v deb-systemd-helper > /dev/null ; then
113 if [ "$ENABLED" = "true" -o "$ENABLED" = "1" ] ; then
114 deb-systemd-helper enable qpsmtpd.service > /dev/null || true
115 else
116 deb-systemd-helper disable qpsmtpd.service > /dev/null || true
117 fi
118 fi
119 }
120
121 setup_user()
122 {
123 if ( ! getent passwd "$RUNAS" > /dev/null ) ; then
124 adduser --quiet \
125 --system --home "$SPOOLDIR" \
126 --gecos "qpsmtpd daemon user" \
127 --group "$RUNAS"
128 fi
129 if [ "x$QUEUE_PLUGIN" = "xpostfix" ] ; then
130 if ( ! getent group "postdrop" | \
131 tr ":" "\n" | \
132 grep -q "^$RUNAS\$" ) ; then
133 adduser --quiet "$RUNAS" "postdrop"
134 fi
135 fi
136 }
137
138 setup_perms()
139 {
140 if ( ! dpkg-statoverride --list "$SPOOLDIR" > /dev/null ) ; then
141 dpkg-statoverride --update --add "$RUNAS" "$RUNAS" 2700 "$SPOOLDIR"
142 fi
143 if ( ! dpkg-statoverride --list "$GREYLISTDIR" > /dev/null ) ; then
144 dpkg-statoverride --update --add "$RUNAS" "$RUNAS" 2700 "$GREYLISTDIR"
145 fi
146 if ( ! dpkg-statoverride --list "$LOGDIR" > /dev/null ) ; then
147 dpkg-statoverride --update --add "$RUNAS" adm 2750 "$LOGDIR"
148 fi
149 if ( ! dpkg-statoverride --list "$PIDDIR" > /dev/null ) ; then
150 dpkg-statoverride --update --add "$RUNAS" adm 2755 "$PIDDIR"
151 fi
152 }
153
154 setup_maildir_spool()
155 {
156 if [ "x$QUEUE_PLUGIN" = "xmaildir" -a \
157 "x$QUEUE_MAILDIR_DESTINATION" != "x" ] ; then
158 if [ ! -d "$QUEUE_MAILDIR_DESTINATION" ] ; then
159 [ -d "`dirname "$QUEUE_MAILDIR_DESTINATION"`" ] || \
160 mkdir -m 0755 -p "`dirname "$QUEUE_MAILDIR_DESTINATION"`"
161 [ -d "$QUEUE_MAILDIR_DESTINATION" ] || \
162 mkdir -m 0700 -p "$QUEUE_MAILDIR_DESTINATION"
163 for d in "$QUEUE_MAILDIR_DESTINATION/new" \
164 "$QUEUE_MAILDIR_DESTINATION/cur" \
165 "$QUEUE_MAILDIR_DESTINATION/tmp" ; do
166 if [ ! -d "$d" ] ; then
167 mkdir -m 0700 "$d"
168 fi
169 done
170 chown -R $RUNAS "$QUEUE_MAILDIR_DESTINATION"
171 fi
172 fi
173 }
174
175 upgrade_config()
176 {
177 from_version="$1" ; shift
178 if dpkg --compare-versions "$from_version" lt 0.32 ; then
179 if [ -f /var/log/qpsmtpd/qpsmtpd.log ] ; then
180 chown qpsmtpd /var/log/qpsmtpd/qpsmtpd.log
181 fi
182 fi
183 if dpkg --compare-versions "$from_version" le 0.94-1 ; then
184 # "check_" prefix was removed in upstream change
185 # b1c2fa16b5fda84f361abf15764501fd11e84022
186 db_input high qpsmtpd/pre094_checkplugin_warning || true
187 db_go
188 fi
189 }
190
191 case "$1" in
192 configure)
193 previous="$2"
194 setup_debconf
195 setup_systemd
196 setup_user
197 setup_perms
198 setup_maildir_spool
199 upgrade_config "$previous"
200 ;;
201 abort-upgrade|abort-remove|abort-deconfigure)
202 # no-op
203 ;;
204 *)
205 echo "Unrecognized postinst argument '$1'"
206 ;;
207
208 esac
209
210 #DEBHELPER#
211
212 db_stop
213
214 exit 0
215