| 1 |
#!/bin/sh -e |
| 2 |
|
| 3 |
# summary of how this script can be called: |
| 4 |
# * <postinst> `configure' <most-recently-configured-version> |
| 5 |
# * <old-postinst> `abort-upgrade' <new version> |
| 6 |
# * <conflictor's-postinst> `abort-remove' `in-favour' <package> <new-version> |
| 7 |
# * <deconfigured's-postinst> `abort-deconfigure' `in-favour' |
| 8 |
# <failed-install-package> <version> `removing' |
| 9 |
# <conflicting-package> <version> |
| 10 |
# for details, see /usr/share/doc/packaging-manual/ |
| 11 |
# |
| 12 |
# quoting from the policy: |
| 13 |
# Any necessary prompting should almost always be confined to the |
| 14 |
# post-installation script, and should be protected with a conditional |
| 15 |
# so that unnecessary prompting doesn't happen if a package's |
| 16 |
# installation fails and the `postinst' is called with `abort-upgrade', |
| 17 |
# `abort-remove' or `abort-deconfigure'. |
| 18 |
|
| 19 |
|
| 20 |
ETC_DIR="/etc/proftpd" |
| 21 |
CONF=$ETC_DIR/proftpd.conf |
| 22 |
CONF_NEW=$ETC_DIR/proftpd.conf.proftpd-new |
| 23 |
MODULES=$ETC_DIR/modules.conf |
| 24 |
MODULES_NEW=$ETC_DIR/modules.conf.proftpd-new |
| 25 |
|
| 26 |
installftp() |
| 27 |
{ |
| 28 |
if [ -f /usr/share/proftpd/templates/welcome.msg ] ; then |
| 29 |
mkdir -p /srv/ftp |
| 30 |
cp -p -v /usr/share/proftpd/templates/welcome.msg /srv/ftp/welcome.msg.proftpd-new || true |
| 31 |
do_update /srv/ftp/welcome.msg || true |
| 32 |
fi |
| 33 |
} |
| 34 |
|
| 35 |
list_options() |
| 36 |
{ |
| 37 |
if [ -f $CONF_NEW ] ; then |
| 38 |
sed -i -e "s/lsdefaultoptions/ListOptions/i" $CONF_NEW |
| 39 |
fi |
| 40 |
} |
| 41 |
|
| 42 |
tcpwin_options() |
| 43 |
{ |
| 44 |
if [ -f $CONF_NEW ] ; then |
| 45 |
sed -i -e "s/tcpreceivewindow/SocketOptions rcvbuf/i" \ |
| 46 |
-e "s/tcpsendwindow/SocketOptions sndbuf/i" $CONF_NEW |
| 47 |
fi |
| 48 |
} |
| 49 |
|
| 50 |
scoreboard() |
| 51 |
{ |
| 52 |
if [ -f $CONF_NEW ] ; then |
| 53 |
sed -i -e "s/\(scoreboardpath.*\)/#\n#ScoreboardPath is deprecated in 1.2.9, use ScoreboardFile instead\n#\1\n#\n#ScoreboardFile\t\/run\/proftpd\/proftpd.scoreboard\n#/i" \ |
| 54 |
$CONF_NEW |
| 55 |
fi |
| 56 |
} |
| 57 |
|
| 58 |
include_modules() |
| 59 |
{ |
| 60 |
if [ -f $CONF_NEW ] ; then |
| 61 |
if ! egrep -qi "^[[:space:]]*Include.*/etc/proftpd/modules.conf" $CONF_NEW ; then |
| 62 |
printf "#\n# Includes required DSO modules. This is mandatory in proftpd 1.3\n#\nInclude\t/etc/proftpd/modules.conf\n\n" >$CONF_NEW.tmp.$$ |
| 63 |
cat $CONF_NEW >>$CONF_NEW.tmp.$$ |
| 64 |
mv -f $CONF_NEW.tmp.$$ $CONF_NEW |
| 65 |
fi |
| 66 |
fi |
| 67 |
} |
| 68 |
|
| 69 |
identlookups() |
| 70 |
{ |
| 71 |
if [ -f $CONF_NEW ] ; then |
| 72 |
if ! egrep -qi "^[[:space:]]*<IfModule mod_ident.c>" $CONF_NEW ; then |
| 73 |
perl -pi -e "s{^(.*IdentLookups.*)}{<IfModule mod_ident.c>\n\1\n</IfModule>\n}i;" $CONF_NEW |
| 74 |
fi |
| 75 |
fi |
| 76 |
} |
| 77 |
|
| 78 |
add_mod_ident() |
| 79 |
{ |
| 80 |
if [ -f $MODULES_NEW ] ; then |
| 81 |
if ! egrep -qi "^[[:space:]]|#*LoadModule mod_ident.c" $MODULES_NEW ; then |
| 82 |
perl -pi -e "s{^(ModulePath .*)}{\1\n\n#\n# Added at upgrade time\n#\nLoadModule mod_ident.c\n}i;" $MODULES_NEW |
| 83 |
fi |
| 84 |
fi |
| 85 |
} |
| 86 |
|
| 87 |
add_mod_ls() |
| 88 |
{ |
| 89 |
if [ -f $MODULES_NEW ] ; then |
| 90 |
if ! egrep -qi "^[[:space:]]|#*LoadModule mod_ls.c" $MODULES_NEW ; then |
| 91 |
perl -pi -e "s{^(ModulePath .*)}{\1\n# Debian #1103154: needed to make default config executable\n#\nLoadModule mod_ls.c\n}i;" $MODULES_NEW |
| 92 |
fi |
| 93 |
fi |
| 94 |
} |
| 95 |
|
| 96 |
add_mod_xfer() |
| 97 |
{ |
| 98 |
if [ -f $MODULES_NEW ] ; then |
| 99 |
if ! egrep -qi "^[[:space:]]|#*LoadModule mod_xfer.c" $MODULES_NEW ; then |
| 100 |
perl -pi -e "s{^(ModulePath .*)}{\1\n# Debian #1103154: needed to make default config executable\n#\nLoadModule mod_xfer.c\n}i;" $MODULES_NEW |
| 101 |
fi |
| 102 |
fi |
| 103 |
} |
| 104 |
|
| 105 |
replace_file () { |
| 106 |
file=$1 |
| 107 |
if [ ! -f ${file} ] ; then |
| 108 |
mv ${file}.proftpd-new ${file} |
| 109 |
else |
| 110 |
cp $file ${file}.proftpd-old |
| 111 |
ucf ${file}.proftpd-new $file |
| 112 |
fi |
| 113 |
} |
| 114 |
|
| 115 |
do_update () { |
| 116 |
file=$1 |
| 117 |
if diff -q ${file} ${file}.proftpd-new >/dev/null 2>&1; then |
| 118 |
# Old file and new file are identical |
| 119 |
rm -f ${file}.proftpd-new |
| 120 |
else |
| 121 |
replace_file $file |
| 122 |
fi |
| 123 |
} |
| 124 |
|
| 125 |
disable_script () { |
| 126 |
file=$1 |
| 127 |
if [ -x ${file} ]; then |
| 128 |
cp ${file} ${file}.disabled |
| 129 |
cat >${file}.disabled <<EOF |
| 130 |
#!/bin/sh |
| 131 |
# This script has been disabled at upgrade time |
| 132 |
|
| 133 |
exit 0 |
| 134 |
|
| 135 |
EOF |
| 136 |
cat ${file} >>${file}.disabled |
| 137 |
rm -f ${file} |
| 138 |
fi |
| 139 |
} |
| 140 |
|
| 141 |
# update-inetd is used if found, else you are on your own |
| 142 |
if [ ! -z `command -v update-inetd` ]; then |
| 143 |
UPDATE_INETD=update-inetd |
| 144 |
else |
| 145 |
UPDATE_INETD=/bin/true |
| 146 |
fi |
| 147 |
|
| 148 |
if [ "$1" = "configure" ]; then |
| 149 |
|
| 150 |
# mv eventual old configuration in the new location |
| 151 |
if [ -f /etc/proftpd.conf -a ! -f $CONF ]; then |
| 152 |
mv /etc/proftpd.conf $CONF |
| 153 |
fi |
| 154 |
|
| 155 |
# use current configuration files or generate new ones from scratch |
| 156 |
for name in proftpd modules sql ldap tls virtuals sftp geoip snmp |
| 157 |
do |
| 158 |
if [ ! -f $ETC_DIR/$name.conf ]; then |
| 159 |
cp /usr/share/proftpd/templates/$name.conf $ETC_DIR/$name.conf.proftpd-new |
| 160 |
else |
| 161 |
cp $ETC_DIR/$name.conf $ETC_DIR/$name.conf.proftpd-new |
| 162 |
fi |
| 163 |
done |
| 164 |
|
| 165 |
# update-inetd does not manage hostlist prefix to service, at least avoid to add a duplicated line |
| 166 |
if [ -f /etc/inetd.conf -a $(grep -qs '^([[:alnum:],.]+)?:?ftp[[:space:]]+' /etc/inetd.conf|wc -l) -eq 0 ]; then |
| 167 |
$UPDATE_INETD --group STANDARD --add '#<off># ftp stream tcp nowait root /usr/sbin/tcpd /usr/sbin/proftpd' |
| 168 |
fi |
| 169 |
|
| 170 |
installftp |
| 171 |
|
| 172 |
# do mandatory changes |
| 173 |
list_options |
| 174 |
tcpwin_options |
| 175 |
scoreboard |
| 176 |
include_modules |
| 177 |
identlookups |
| 178 |
add_mod_ident |
| 179 |
add_mod_ls |
| 180 |
add_mod_xfer |
| 181 |
|
| 182 |
# disable old cron jobs if needed |
| 183 |
disable_script /etc/cron.monthly/proftpd |
| 184 |
disable_script /etc/cron.monthly/proftpd-basic |
| 185 |
|
| 186 |
# propose maintainer changes to user |
| 187 |
do_update /etc/proftpd/proftpd.conf |
| 188 |
do_update /etc/proftpd/modules.conf |
| 189 |
do_update /etc/proftpd/tls.conf |
| 190 |
do_update /etc/proftpd/sql.conf |
| 191 |
do_update /etc/proftpd/ldap.conf |
| 192 |
do_update /etc/proftpd/virtuals.conf |
| 193 |
do_update /etc/proftpd/sftp.conf |
| 194 |
do_update /etc/proftpd/geoip.conf |
| 195 |
do_update /etc/proftpd/snmp.conf |
| 196 |
|
| 197 |
# be safe and change permissions for .conf files where passwords should |
| 198 |
# potentially be present |
| 199 |
chmod 600 /etc/proftpd/sql.conf* /etc/proftpd/ldap.conf* || true |
| 200 |
|
| 201 |
# clean run files (pidfile and scoreboard) |
| 202 |
rm -f /run/proftpd/proftpd* /run/proftpd.pid |
| 203 |
|
| 204 |
fi |
| 205 |
|
| 206 |
if [ ! -d /run/systemd/system/ ] && [ -e "/etc/init.d/proftpd" ]; then |
| 207 |
systemd-sysusers ${DPKG_ROOT:+--root="$DPKG_ROOT"} proftpd-core.conf |
| 208 |
set +e |
| 209 |
proftpd -t >/dev/null 2>&1 |
| 210 |
if [ $? = 0 ]; then |
| 211 |
set -e |
| 212 |
else |
| 213 |
echo "Cannot start proftpd, please check syntax of your configuration file $CONF" |
| 214 |
fi |
| 215 |
fi |
| 216 |
|
| 217 |
# Check if we are standalone, before trying to start via systemd. |
| 218 |
|
| 219 |
if [ "$1" = "configure" ]; then |
| 220 |
if egrep -qi "^[[:space:]]*ServerType.*standalone" /etc/proftpd/proftpd.conf |
| 221 |
then |
| 222 |
echo "Server configured as standalone." |
| 223 |
else |
| 224 |
echo "Server not configured as standalone, exiting." |
| 225 |
exit 0 |
| 226 |
fi |
| 227 |
fi |
| 228 |
|
| 229 |
#DEBHELPER# |