| 1 |
#!/bin/sh |
| 2 |
# postinst script for fex |
| 3 |
# |
| 4 |
# see: dh_installdeb(1) |
| 5 |
|
| 6 |
set -e |
| 7 |
|
| 8 |
. /usr/share/debconf/confmodule |
| 9 |
|
| 10 |
# summary of how this script can be called: |
| 11 |
# * <postinst> `configure' <most-recently-configured-version> |
| 12 |
# * <old-postinst> `abort-upgrade' <new version> |
| 13 |
# * <conflictor's-postinst> `abort-remove' `in-favour' <package> |
| 14 |
# <new-version> |
| 15 |
# * <postinst> `abort-remove' |
| 16 |
# * <deconfigured's-postinst> `abort-deconfigure' `in-favour' |
| 17 |
# <failed-install-package> <version> `removing' |
| 18 |
# <conflicting-package> <version> |
| 19 |
# for details, see http://www.debian.org/doc/debian-policy/ or |
| 20 |
# the debian-policy package |
| 21 |
|
| 22 |
case "$1" in |
| 23 |
configure) |
| 24 |
# lets give them a fex user/group in all cases. |
| 25 |
getent group fex >/dev/null 2>&1 || addgroup --system fex |
| 26 |
getent passwd fex >/dev/null 2>&1 || adduser --system --home /usr/share/fex --no-create-home \ |
| 27 |
--disabled-password --shell /bin/sh --ingroup fex fex |
| 28 |
|
| 29 |
FEX_USER_SHELL=$(getent passwd fex|awk -F: '{print $7}') |
| 30 |
if [ "$FEX_USER_SHELL" = "/bin/false" ];then |
| 31 |
echo "Updating user fex to have a valid shell (/bin/sh)" |
| 32 |
chsh -s /bin/sh fex |
| 33 |
fi |
| 34 |
|
| 35 |
# ensure fac and fex_cleanup are run as user fex |
| 36 |
for file in fex_cleanup logwatch fexwall;do |
| 37 |
dpkg-statoverride --list /usr/share/fex/bin/$file >/dev/null || dpkg-statoverride --add fex fex 4750 /usr/share/fex/bin/$file |
| 38 |
chown fex:fex /usr/share/fex/bin/$file |
| 39 |
chmod 4750 /usr/share/fex/bin/$file |
| 40 |
done |
| 41 |
dpkg-statoverride --list /usr/bin/fac >/dev/null || dpkg-statoverride --add fex fex 4750 /usr/bin/fac |
| 42 |
chown fex:fex /usr/bin/fac |
| 43 |
chmod 4750 /usr/bin/fac |
| 44 |
|
| 45 |
if [ ! -d /var/lib/fex/htdocs ]; then |
| 46 |
echo "Installing initial copy of htdocs into /var/lib/fex/htdocs ..." |
| 47 |
mkdir -p /var/lib/fex/htdocs/FAQ/ /var/lib/fex/htdocs/DOX/ |
| 48 |
cd /usr/share/fex/htdocs/ |
| 49 |
find . -type f -exec cp {} /var/lib/fex/htdocs/{} \; |
| 50 |
ln -sf /usr/share/javascript/jquery/jquery.js /var/lib/fex/htdocs/FAQ/jquery.js |
| 51 |
ln -s /usr/share/fex/htdocs/download /var/lib/fex/htdocs/ |
| 52 |
else |
| 53 |
echo "Upgrading version file in /var/lib/fex/htdocs" |
| 54 |
cp /usr/share/fex/htdocs/version /var/lib/fex/htdocs/version |
| 55 |
echo "/var/lib/fex/htdocs exists already, checking for default install" |
| 56 |
[ -d /var/lib/fex/htdocs/FAQ ]||mkdir /var/lib/fex/htdocs/FAQ/ |
| 57 |
[ -d /var/lib/fex/htdocs/DOX ]||mkdir /var/lib/fex/htdocs/DOX/ |
| 58 |
tmp=$(mktemp) |
| 59 |
vers=$(mktemp -d) |
| 60 |
(cd ${vers};tar xfz /usr/share/fex/.md5/htdocs.tgz) |
| 61 |
if [ -f /usr/share/fex/.lastver ];then |
| 62 |
lastinst=$(cat /usr/share/fex/.lastver) |
| 63 |
db_set fex/lastver "$lastinst" |
| 64 |
rm -f /usr/share/fex/.lastver |
| 65 |
else |
| 66 |
db_get fex/lastver |
| 67 |
lastinst=$RET |
| 68 |
fi |
| 69 |
lastinstnoepoch=$(echo $lastinst | cut -d':' -f 2) |
| 70 |
if [ -f ${vers}/${lastinst} ];then |
| 71 |
if (cd /var/lib/fex;md5sum -c --quiet "${vers}/${lastinst}" >/dev/null 2>&1);then |
| 72 |
# htdocs is identical |
| 73 |
echo "Updating $lastinst default htdocs to new default htdocs" |
| 74 |
cd /usr/share/fex/htdocs/ |
| 75 |
find . -type f -exec cp {} /var/lib/fex/htdocs/{} \; |
| 76 |
rm -f "$tmp" |
| 77 |
fi |
| 78 |
if [ -L /var/lib/fex/htdocs/download ];then |
| 79 |
if [ "$(readlink /var/lib/fex/htdocs/download)" = "/usr/share/fex/htdocs/download" ];then |
| 80 |
#echo "Download directory is up to date." |
| 81 |
true |
| 82 |
else |
| 83 |
echo "Download directory is pointing to non-default location." |
| 84 |
echo "Please update client scripts yourself" |
| 85 |
fi |
| 86 |
else |
| 87 |
for file in /usr/share/fex/htdocs/download/*;do |
| 88 |
ln -sf "$file" /var/lib/fex/htdocs/download |
| 89 |
done |
| 90 |
fi |
| 91 |
if [ -L /var/lib/fex/htdocs/FAQ/jquery.js ];then |
| 92 |
if [ "$(readlink /var/lib/fex/htdocs/FAQ/jquery.js)" = "/usr/share/javascript/jquery/jquery.js" ];then |
| 93 |
#echo "jquery.js link is up to date." |
| 94 |
true |
| 95 |
else |
| 96 |
echo "jquery.js in htdocs/FAQ is pointing to non-default location." |
| 97 |
echo "Please update jquery.js symlink yourself unless intended to not be system default" |
| 98 |
fi |
| 99 |
elif [ ! -f "/var/lib/fex/htdocs/FAQ/jquery.js" ];then |
| 100 |
ln -s /usr/share/javascript/jquery/jquery.js /var/lib/fex/htdocs/FAQ/jquery.js |
| 101 |
fi |
| 102 |
fi |
| 103 |
# tmp is created by mktemp and not cleaned up |
| 104 |
# if we don't have ${vers}/${lastinst} - |
| 105 |
# thus custom builds are always custom |
| 106 |
if [ -f "$tmp" ];then |
| 107 |
echo "Customizations in htdocs found. Not touching any files." |
| 108 |
echo "The new default pages are at /usr/share/fex/htdocs/." |
| 109 |
echo "Please check the diff yourself and update your htdocs dir if required." |
| 110 |
rm "$tmp" |
| 111 |
fi |
| 112 |
if [ -e /var/lib/fex/htdocs/FIX.jar ];then |
| 113 |
echo "F*IX is no longer supported. You should remove /var/lib/fex/htdocs/FIX.jar." |
| 114 |
elif [ -L /var/lib/fex/htdocs/FIX.jar -a ! -e /var/lib/fex/htdocs/FIX.jar ];then |
| 115 |
echo "Removing dangling symlink to FIX.jar" |
| 116 |
rm -f /var/lib/fex/htdocs/FIX.jar |
| 117 |
fi |
| 118 |
rm -rf ${vers} |
| 119 |
fi |
| 120 |
|
| 121 |
# make sure we don't have MYHOSTNAME.MYDOMAIN as $hostname in /etc/fex/fex.ph |
| 122 |
myhostname=$(hostname -f) # in case our piuparts chroot doesn't know about hostname |
| 123 |
if [ ! -f /etc/fex/fex.ph ];then |
| 124 |
if [ -z "$myhostname" ];then |
| 125 |
echo 'Initializing /etc/fex/fex.ph WITHOUT hostname (Please correct before using F*EX)' |
| 126 |
cat /usr/share/fex/templates/fex.ph >/var/lib/fex/fex.ph |
| 127 |
else |
| 128 |
echo 'Initializing /etc/fex/fex.ph with correcting hostname (using: '${myhostname}')' |
| 129 |
cat /usr/share/fex/templates/fex.ph|sed -e 's/^\$hostname.*/\$hostname = '"'${myhostname}'"';/' >/var/lib/fex/fex.ph |
| 130 |
fi |
| 131 |
# make sure we reset ucf here.. |
| 132 |
ucfr --purge fex /etc/fex/fex.ph |
| 133 |
mv /var/lib/fex/fex.ph /etc/fex/fex.ph |
| 134 |
ucfr fex /etc/fex/fex.ph |
| 135 |
|
| 136 |
# XXX: fex adminpw and ~fex/.fex/id will be autocreated by fex_cleanup further down |
| 137 |
else |
| 138 |
if egrep -q '^\$hostname.*=.*'"'MYHOSTNAME.MYDOMAIN'" /etc/fex/fex.ph 2>/dev/null;then |
| 139 |
echo 'Unconfigured hostname found in /etc/fex/fex.ph! Please correct before using F*EX' |
| 140 |
else |
| 141 |
PW=$(perl -e 'require "/etc/fex/fex.ph";print $admin_pw;') |
| 142 |
ADMIN=$(perl -e 'require "/etc/fex/fex.ph";print $admin;') |
| 143 |
if [ ! -f /usr/share/fex/.fex/id -a -n "$PW" ];then |
| 144 |
echo "Creating fex admin login. Moving admin_pw from fex.ph" |
| 145 |
[ -d /usr/share/fex/.fex/ ]||install -d -m 0700 -o fex -g fex /usr/share/fex/.fex/ |
| 146 |
touch /usr/share/fex/.fex/id |
| 147 |
chmod 0600 /usr/share/fex/.fex/id |
| 148 |
chown fex:fex /usr/share/fex/.fex/id |
| 149 |
perl -e 'require "/etc/fex/fex.ph";$opt_p ||= "8888";print "$hostname:$opt_p\n$admin\n$admin_pw\n";' > /usr/share/fex/.fex/id |
| 150 |
fi |
| 151 |
if [ ! -f "/usr/share/fex/spool/${ADMIN}/@" ];then |
| 152 |
mkdir -p "/usr/share/fex/spool/${ADMIN}" |
| 153 |
chmod 0700 "/usr/share/fex/spool/${ADMIN}" |
| 154 |
touch "/usr/share/fex/spool/${ADMIN}/@" |
| 155 |
chmod 0600 "/usr/share/fex/spool/${ADMIN}/@" |
| 156 |
chown fex:fex "/usr/share/fex/spool/${ADMIN}" |
| 157 |
echo "$PW" > "/usr/share/fex/spool/${ADMIN}/@" |
| 158 |
fi |
| 159 |
if grep -q '^$admin_pw' /etc/fex/fex.ph 2>/dev/null;then |
| 160 |
echo '$admin_pw is set in /etc/fex/fex.ph ...' |
| 161 |
echo 'Removing line and replacing by comment.' |
| 162 |
echo 'From now on the fexmaster account also works in the web fac UI.' |
| 163 |
sed -i -e '/^$admin_pw/s,^$admin_pw.*$,### $admin_pw is no longer used - fexmaster account may now also login via web-fac,' /etc/fex/fex.ph |
| 164 |
PW=$(perl -e 'require "/etc/fex/fex.ph";print $admin_pw;') |
| 165 |
if [ -n "$PW" ];then |
| 166 |
echo |
| 167 |
echo ' *** WARNING ***' |
| 168 |
echo 'Some sort of include happening inside fex.ph. Please remove $admin_pw in include manually!' |
| 169 |
echo ' *** WARNING ***' |
| 170 |
echo |
| 171 |
fi |
| 172 |
fi |
| 173 |
fi |
| 174 |
NOTIFY=$(perl -e 'require "/etc/fex/fex.ph";print $notify_newrelease;') |
| 175 |
if [ "$NOTIFY" != "" ];then |
| 176 |
echo "You have notify_newrelease defined in /etc/fex/fex.ph!" |
| 177 |
echo 'This should be set to' |
| 178 |
echo '# ************************************************************' |
| 179 |
echo '$notify_newrelease='"'';" |
| 180 |
echo '# ************************************************************' |
| 181 |
echo 'to ensure you do not get nagged for new upstream releases.' |
| 182 |
echo "Updates for Debian fex come through apt/aptitude and don't need this obviously." |
| 183 |
fi |
| 184 |
fi |
| 185 |
if [ -f /etc/aliases -o -L /etc/aliases ]; then |
| 186 |
if ! grep -qi "^\s*fex\s*:" /etc/aliases; then |
| 187 |
if [ -z "$2" ];then |
| 188 |
echo "Adding system alias for fex to root" |
| 189 |
echo "fex: root" >> /etc/aliases |
| 190 |
# run newaliases for e.g. postfix |
| 191 |
newal=`which newaliases || true` |
| 192 |
if [ -n "$newal" ] && [ -x "$newal" ]; then |
| 193 |
$newal || true |
| 194 |
fi |
| 195 |
else |
| 196 |
echo "You have no alias set for user fex in /etc/aliases!" |
| 197 |
echo "Consider adding one or you will not receive bounced emails from" |
| 198 |
echo "fex daemon email notifications" |
| 199 |
fi |
| 200 |
fi |
| 201 |
fi |
| 202 |
if [ -f /etc/exim/exim.conf -o -f /var/lib/exim4/config.autogenerated ]; then |
| 203 |
# exim4 found... |
| 204 |
[ ! -f /var/lib/exim4/config.autogenerated ]||ISTRUSTED=$(egrep '^\s*(MAIN_TRUSTED_USERS|trusted_users)\s*=.*fex' /var/lib/exim4/config.autogenerated||true) |
| 205 |
[ ! -f /etc/exim/exim.conf ]||ISTRUSTED=$(egrep '^\s*(MAIN_TRUSTED_USERS|trusted_users)\s*=.*fex' /etc/exim/exim.conf||true) |
| 206 |
[ -z "$ISTRUSTED" ]||echo "You're running exim4 and fex isn't in the trusted_users list. Consider adding or email notifications may not work!" |
| 207 |
fi |
| 208 |
|
| 209 |
# make sure we have correct permissions |
| 210 |
dpkg-statoverride --list /etc/fex/fex.ph >/dev/null || dpkg-statoverride --add fex fex 0640 /etc/fex/fex.ph |
| 211 |
dpkg-statoverride --list /etc/fex/fup.pl >/dev/null || dpkg-statoverride --add fex fex 0640 /etc/fex/fup.pl |
| 212 |
chown fex:fex /etc/fex/fex.ph /etc/fex/fup.pl |
| 213 |
chmod 0640 /etc/fex/fex.ph /etc/fex/fup.pl |
| 214 |
|
| 215 |
logdir=`sed -n '/\$logdir/s/^\$logdir\s*=\s*['"'"'"]\(.*\)['"'"'"].*/\1/p' /etc/fex/fex.ph|tail -n 1||true` |
| 216 |
if [ "$logdir" = "/var/log/fex" ];then |
| 217 |
for log in cleanup.log dop.log error.log fexsrv.log fop.log fup.log;do |
| 218 |
if [ -r /var/spool/fex/${log} ];then |
| 219 |
echo -n "Moving old log file ${log} to /var/log/fex" |
| 220 |
if [ ! -r /var/log/fex/${log} ];then |
| 221 |
mv /var/spool/fex/${log} /var/log/fex/ |
| 222 |
chmod 0640 /var/log/fex/${log} |
| 223 |
echo '.' |
| 224 |
elif [ ! -r /var/log/fex/${log}.1 ];then |
| 225 |
# we already have a new logfile in /var/log/fex |
| 226 |
mv /var/spool/fex/${log} /var/log/fex/${log}.1 |
| 227 |
chmod 0640 /var/log/fex/${log}* |
| 228 |
echo '.' |
| 229 |
else |
| 230 |
echo ': failed!' |
| 231 |
echo "New logdir already populated." |
| 232 |
echo "Please move /var/spool/fex/${log} yourself if required." |
| 233 |
fi |
| 234 |
else |
| 235 |
# Create new logfile with correct permissions |
| 236 |
touch /var/log/fex/${log} |
| 237 |
chmod 0640 /var/log/fex/${log} |
| 238 |
fi |
| 239 |
done |
| 240 |
elif [ -n "$logdir" ];then |
| 241 |
if [ "${logdir}" = '$spooldir' ];then |
| 242 |
echo 'Logdir still pointing to $spooldir. Please update to /var/log/fex' |
| 243 |
echo 'in order to take full advantage of logrotate settings.' |
| 244 |
echo 'Once you have updated your configfiles just run:' |
| 245 |
echo ' dpkg-reconfigure fex' |
| 246 |
echo 'To have the logfiles moved into their new location' |
| 247 |
else |
| 248 |
echo "Custom logdir configured. Not moving logfile to /var/log/fex." |
| 249 |
fi |
| 250 |
fi |
| 251 |
|
| 252 |
echo -n "Adding default spool keys dirs with secure permissions: " |
| 253 |
for dir in .dkeys .ukeys .akeys .skeys .gkeys .xkeys .locks;do |
| 254 |
mkdir -p "/var/spool/fex/$dir" |
| 255 |
chmod 0700 "/var/spool/fex/$dir" |
| 256 |
done |
| 257 |
echo "done." |
| 258 |
|
| 259 |
chown -R fex:fex /usr/share/fex/ /var/lib/fex/ /var/log/fex/ /var/spool/fex/ |
| 260 |
chmod 0750 /usr/share/fex/ /var/lib/fex/ /var/log/fex/ /var/spool/fex/ |
| 261 |
|
| 262 |
fexsrv=`egrep '\s/usr/share/fex/bin/fexsrv' /etc/inetd.conf 2>/dev/null||true` |
| 263 |
if [ -n "$fexsrv" ];then |
| 264 |
touch /usr/share/fex/.inetd_has_fex |
| 265 |
else |
| 266 |
rm -f /usr/share/fex/.inetd_has_fex |
| 267 |
fi |
| 268 |
if [ -f /etc/xinetd.d/fex ];then |
| 269 |
if [ "$(ucfq -w /etc/xinetd.d/fex |awk -F: '{print $4}')" = "Yes" ];then |
| 270 |
echo "F*EX already active through xinetd. Not adding systemd service." |
| 271 |
SYSTEMD_SOCKET_STAND_DOWN=1 |
| 272 |
else |
| 273 |
echo "Removing xinetd F*EX service and replacing it with systemd socket..." |
| 274 |
ucf --debconf-ok -p /etc/xinetd.d/fex |
| 275 |
rm -f /etc/xinetd.d/fex |
| 276 |
if [ -x /etc/init.d/xinetd ]; then |
| 277 |
if [ -x /usr/sbin/invoke-rc.d ]; then |
| 278 |
invoke-rc.d xinetd reload || true |
| 279 |
else |
| 280 |
/etc/init.d/xinetd reload || true |
| 281 |
fi |
| 282 |
fi |
| 283 |
fi |
| 284 |
elif [ -r /etc/inetd.conf ];then |
| 285 |
if [ -n "$fexsrv" ];then |
| 286 |
echo "F*EX already active through inetd. Not adding systemd service." |
| 287 |
SYSTEMD_SOCKET_STAND_DOWN=1 |
| 288 |
fi |
| 289 |
fi |
| 290 |
if [ -d /run/systemd/system ];then |
| 291 |
systemctl daemon-reload |
| 292 |
if [ -z "$SYSTEMD_SOCKET_STAND_DOWN" ];then |
| 293 |
systemctl enable fex.socket |
| 294 |
systemctl restart fex.socket |
| 295 |
fi |
| 296 |
elif [ -d /etc/xinetd.d ];then |
| 297 |
ucf --debconf-ok /usr/share/fex/templates/xinetd_fex /etc/xinetd.d/fex |
| 298 |
remainingsrv=`grep -r /usr/share/fex/bin/fexsrv /etc/xinetd.d|grep -v '^/etc/xinetd.d/fex:'|sed -e 's#^/etc/xinetd.d/\([^:]\+\):.*#\1#'|grep -v 'fex.*-*'||true` |
| 299 |
if [ ! -z "$remainingsrv" ];then |
| 300 |
echo "User-defined services in xinetd not updated: ${remainingsrv}. Please update yourself!" |
| 301 |
fi |
| 302 |
if [ -x /etc/init.d/xinetd ]; then |
| 303 |
if [ -x /usr/sbin/invoke-rc.d ]; then |
| 304 |
invoke-rc.d xinetd reload || true |
| 305 |
else |
| 306 |
/etc/init.d/xinetd reload || true |
| 307 |
fi |
| 308 |
fi |
| 309 |
elif [ -r /etc/inetd.conf ];then |
| 310 |
# We're running openbsd-inetd or something similar |
| 311 |
fexsrv=`egrep '\s/usr/share/fex/bin/fexsrv' /etc/inetd.conf 2>/dev/null||true` |
| 312 |
if [ -x /usr/sbin/update-inetd -a -z "$fexsrv" ];then |
| 313 |
# as --multi is ugly we'll only support v4 through inetd.conf |
| 314 |
# whoever wants IPv6 needs to go xinetd or hack his own version |
| 315 |
# i.e. replace tcp with tcp6 |
| 316 |
update-inetd --add '8888\tstream\ttcp\tnowait\tfex:fex\t/usr/sbin/tcpd\t/usr/share/fex/bin/fexsrv' |
| 317 |
elif [ -z "$fexsrv" ];then |
| 318 |
echo 'Unable to automatically update inetd.conf' |
| 319 |
echo 'Please update yourself and restart inetd' |
| 320 |
fi |
| 321 |
fi |
| 322 |
echo 'Running fex_cleanup to verify config integrity ...' |
| 323 |
su -s /bin/bash -c /usr/share/fex/bin/fex_cleanup fex |
| 324 |
|
| 325 |
;; |
| 326 |
|
| 327 |
abort-upgrade|abort-remove|abort-deconfigure) |
| 328 |
;; |
| 329 |
|
| 330 |
*) |
| 331 |
echo "postinst called with unknown argument \`$1'" >&2 |
| 332 |
exit 1 |
| 333 |
;; |
| 334 |
esac |
| 335 |
|
| 336 |
# dh_installdeb will replace this with shell code automatically |
| 337 |
# generated by other debhelper scripts. |
| 338 |
|
| 339 |
#DEBHELPER# |
| 340 |
|
| 341 |
exit 0 |
| 342 |
|
| 343 |
# vi: set smartindent ts=4 sw=4 expandtab autoindent sts=4: |