overte-JulianGro/pkg-scripts/server-postinst

85 lines
2.8 KiB
Bash
Executable file

#!/bin/sh
# postinst script for vircadia-server
#
# 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 https://www.debian.org/doc/debian-policy/ or
# the debian-policy package
case "$1" in
configure)
ldconfig -n /opt/vircadia/lib
adduser --system --quiet --gecos "Vircadia" --home /var/lib/vircadia --group --no-create-home vircadia
mkdir -p /var/lib/vircadia
chown vircadia:vircadia /var/lib/vircadia
chmod 775 /var/lib/vircadia
if [ ! -d "/var/lib/vircadia/default" ]; then
if [ -d "/var/lib/athena" ]; then
ATHENA_ACTIVE=`systemctl list-units \
| grep -P -o "(athena-assignment-client|athena-domain-server|athena-server)\S+" \
| paste -s -d'|' \
| head -c -1`
ATHENA_ENABLED=`systemctl list-units --state=loaded \
| grep -P -o "(athena-assignment-client|athena-domain-server|athena-server)\S+" \
| xargs -I {} sh -c 'if systemctl is-enabled {} >/dev/null ; then echo {} ; fi' \
| paste -s -d'|' \
| head -c -1`
# shutdown athena servers
echo -n $ATHENA_ACTIVE | xargs -d'|' systemctl stop
# copy the server files over
cp /etc/opt/athena/* /etc/opt/vircadia
cp -R /var/lib/athena/* /var/lib/vircadia
chown -R vircadia:vircadia /var/lib/vircadia/*
find /var/lib/vircadia -maxdepth 3 -path "*\.local/share" -execdir sh -c 'cd share; ln -s ../.. "Vircadia - dev"' ';'
find /var/lib/vircadia -maxdepth 3 -path "*\.local/share" -execdir sh -c 'cd share; ln -s ../.. Vircadia' ';'
VIRCADIA_ACTIVE=`echo -n $ATHENA_ACTIVE | sed 's/athena/vircadia/g'`
VIRCADIA_ENABLED=`echo -n $ATHENA_ENABLED | sed 's/athena/vircadia/g'`
echo -n $ATHENA_ENABLED | xargs -d'|' systemctl disable
echo -n $VIRCADIA_ENABLED | xargs -d'|' systemctl enable
echo -n $VIRCADIA_ACTIVE | xargs -d'|' systemctl start
else
/opt/vircadia/new-server default 40100
systemctl enable vircadia-server@default.target
systemctl start vircadia-server@default.target
fi
else
systemctl list-units \
| grep -P -o "(vircadia-assignment-client|vircadia-domain-server|vircadia-server)\S+" \
| xargs systemctl restart
fi
;;
abort-remove|abort-deconfigure)
ldconfig -n /opt/vircadia/lib
;;
abort-upgrade)
;;
*)
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#
exit 0