109 lines
3.4 KiB
Bash
109 lines
3.4 KiB
Bash
#!/bin/bash
|
|
# postinst script for dump1090
|
|
#
|
|
# see: dh_installdeb(1)
|
|
|
|
set -e
|
|
|
|
# summary of how this script can be called:
|
|
# * <postinst> `configure' <most-recently-configured-version>
|
|
# * <old-postinst> `abort-upgrade' <new version>
|
|
# * <conflictor's-postinst> `abort-remove' `in-favour' <package>
|
|
# <new-version>
|
|
# * <postinst> `abort-remove'
|
|
# * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
|
|
# <failed-install-package> <version> `removing'
|
|
# <conflicting-package> <version>
|
|
# for details, see http://www.debian.org/doc/debian-policy/ or
|
|
# the debian-policy package
|
|
|
|
NAME=dump1090-fa
|
|
RUNAS=dump1090
|
|
CRONFILE=/etc/cron.d/$NAME
|
|
TEMPLATECRON=/usr/share/$NAME/cron-template
|
|
|
|
case "$1" in
|
|
configure)
|
|
. /usr/share/debconf/confmodule
|
|
|
|
if ! getent passwd "$RUNAS" >/dev/null
|
|
then
|
|
adduser --system --home /usr/share/$NAME --no-create-home --quiet "$RUNAS"
|
|
fi
|
|
|
|
# plugdev required for bladeRF USB access
|
|
adduser "$RUNAS" plugdev
|
|
|
|
# Make sure the "data" directory is owned by dump1090 so the dump1090-fa process has write access
|
|
jsondir="/usr/share/dump1090-fa/html/data"
|
|
if [ -d ${jsondir} ]; then
|
|
echo "Changing permissions on ${jsondir}..." >&2
|
|
chown ${RUNAS}:nogroup ${jsondir}
|
|
chmod 755 ${jsondir}
|
|
fi
|
|
|
|
# Update apache
|
|
changed=false
|
|
for apachefile in /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/default-ssl.conf
|
|
do
|
|
if [ -f ${apachefile} ]; then
|
|
echo "Modifying ${apachefile}..." >&2
|
|
sed -i '/<\/VirtualHost>/i \
|
|
####dump1090-start###\
|
|
Alias "/data" "/dump1090-fa/data"\
|
|
Alias "/dump1090-fa" "/usr/share/dump1090-fa/html"\
|
|
Alias "^/dump1090-fa$" "/dump1090-fa"\
|
|
SetEnvIf Request_URI "/dump1090-fa/data/.*\.json$" Header set "Access-Control-Allow-Origin" "*"\
|
|
####dump1090-end###' ${apachefile}
|
|
changed=true
|
|
fi
|
|
done
|
|
|
|
# Restart apache
|
|
if $changed
|
|
then
|
|
echo "Restarting Apache..." >&2
|
|
invoke-rc.d apache2 restart || echo "Warning: apache2 failed to restart." >&2
|
|
fi
|
|
|
|
|
|
|
|
# on upgrade, add an ENABLED line if it's not already present
|
|
if dpkg --compare-versions "$2" lt-nl "3.7.0"
|
|
then
|
|
if [ -f /etc/default/dump1090-fa ]
|
|
then
|
|
if ! grep -q -E '^ENABLED=' /etc/default/dump1090-fa
|
|
then
|
|
echo "Setting ENABLED=yes in /etc/default/dump1090-fa.." >&2
|
|
echo "# Automatically added by upgrade from $2" >>/etc/default/dump1090-fa
|
|
echo "ENABLED=yes" >>/etc/default/dump1090-fa
|
|
fi
|
|
fi
|
|
fi
|
|
|
|
# Enable and start dump1090-fa
|
|
echo "Enabling the dump1090-fa service..." >&2
|
|
systemctl enable dump1090-fa
|
|
echo "Starting the dump1090-fa service..." >&2
|
|
systemctl start dump1090-fa
|
|
|
|
;;
|
|
|
|
abort-upgrade|abort-remove|abort-deconfigure)
|
|
;;
|
|
|
|
*)
|
|
echo "postinst called with unknown argument \`$1'" >&2
|
|
exit 1
|
|
;;
|
|
esac
|
|
|
|
# dh_installdeb will replace this with shell code automatically
|
|
# generated by other debhelper scripts.
|
|
|
|
#DEBHELPER#
|
|
|
|
if [ "$1" = "configure" ]; then db_stop; fi
|
|
exit 0
|