diff --git a/pkg-scripts/deb-functions b/pkg-scripts/deb-functions new file mode 100644 index 0000000000..9267f37112 --- /dev/null +++ b/pkg-scripts/deb-functions @@ -0,0 +1,64 @@ +#!/bin/sh +# functions to assist with deb management + +getAthenaEnabled() +{ + return systemctl list-units --state=loaded \ + | grep -P "(athena-assignment-client|athena-domain-server|athena-server)" \ + | cut -d' ' -f 1 \ + | xargs -I {} sh -c 'if systemctl is-enabled {} >/dev/null ; then echo {} ; fi' \ + | paste -s -d'|' +} + +getVircadiaEnabled() +{ + return systemctl list-units --state=loaded \ + | grep -P "(vircadia-assignment-client|vircadia-domain-server|vircadia-server)" \ + | cut -d' ' -f 1 \ + | xargs -I {} sh -c 'if systemctl is-enabled {} >/dev/null ; then echo {} ; fi' \ + | paste -s -d'|' +} + +getAthenaActive() +{ + return systemctl list-units \ + | grep -P "(athena-assignment-client|athena-domain-server|athena-server)" \ + | cut -d' ' -f 1 \ + | paste -s -d'|' +} + +getVircadiaActive() +{ + return systemctl list-units \ + | grep -P "(vircadia-assignment-client|vircadia-domain-server|vircadia-server)" \ + | cut -d' ' -f 1 \ + | paste -s -d'|' +} + +disableList() +{ + echo $1 \ + | xargs -d'|' \ + | systemctl disable +} + +enableList() +{ + echo $1 \ + | xargs -d'|' \ + | systemctl enable +} + +stopList() +{ + echo $1 \ + | xargs -d'|' \ + | systemctl stop +} + +startList() +{ + echo $1 \ + | xargs -d'|' \ + | systemctl start +} diff --git a/pkg-scripts/make-deb-server b/pkg-scripts/make-deb-server index 70eda96411..aaa0c2f26f 100755 --- a/pkg-scripts/make-deb-server +++ b/pkg-scripts/make-deb-server @@ -59,6 +59,7 @@ cp $ATHENA/source/pkg-scripts/vircadia-server@.target debian cp $ATHENA/source/pkg-scripts/server-control debian/control cp $ATHENA/source/pkg-scripts/server-prerm debian/prerm cp $ATHENA/source/pkg-scripts/server-postinst debian/postinst +cp $ATHENA/source/pkg-scripts/server-postrm debian/postrm cp $ATHENA/source/LICENSE debian/copyright echo /etc/opt/vircadia > debian/dirs diff --git a/pkg-scripts/new-server b/pkg-scripts/new-server index 22d6c0c9e8..a2ce9b330d 100755 --- a/pkg-scripts/new-server +++ b/pkg-scripts/new-server @@ -28,8 +28,6 @@ if [ -d "/var/lib/vircadia/$1" ]; then fi mkdir -p /var/lib/vircadia/$1/.local/share -ln -s ../.. /var/lib/vircadia/$1/.local/share/Project\ Athena\ -\ dev -ln -s ../.. /var/lib/vircadia/$1/.local/share/Project\ Athena ln -s ../.. /var/lib/vircadia/$1/.local/share/Vircadia\ -\ dev ln -s ../.. /var/lib/vircadia/$1/.local/share/Vircadia mkdir -p /var/lib/vircadia/$1/domain-server diff --git a/pkg-scripts/server-postinst b/pkg-scripts/server-postinst index b115e7a778..01b4a59e22 100755 --- a/pkg-scripts/server-postinst +++ b/pkg-scripts/server-postinst @@ -2,6 +2,7 @@ # postinst script for vircadia-server # # see: dh_installdeb(1) +. ./deb-functions set -e @@ -26,9 +27,31 @@ case "$1" in chown vircadia:vircadia /var/lib/vircadia chmod 775 /var/lib/vircadia if [ ! -d "/var/lib/vircadia/default" ]; then - /opt/vircadia/new-server default 40100 - systemctl enable vircadia-server@default.target - systemctl start vircadia-server@default.target + if [ -d "/var/lib/athena" ]; then + getAthenaActive # get list of active Athena services + ATHENA_ACTIVE=$? + getAthenaEnabled # get list of enabled Athena services + ATHENA_ENABLED=$? + stopList $ATHENA_ACTIVE # shutdown active Athena servers + + # 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/athena -maxdepth 3 -path "*\.local/share" -execdir sh -c 'cd share; ln -s ../.. Vircadia - dev' ';' + find /var/lib/athena -maxdepth 3 -path "*\.local/share" -execdir sh -c 'cd share; ln -s ../.. Vircadia' ';' + + VIRCADIA_ACTIVE=`echo $ATHENA_ACTIVE | sed 's/athena/vircadia/g'` + VIRCADIA_ENABLED=`echo $ATHENA_ENABLED | sed 's/athena/vircadia/g'` + + disableList $ATHENA_ENABLED + enableList $VIRCADIA_ENABLED + startList $VIRCADIA_ACTIVE + else + /opt/vircadia/new-server default 40100 + systemctl enable vircadia-server@default.target + systemctl start vircadia-server@default.target + fi fi ;; diff --git a/pkg-scripts/server-postrm b/pkg-scripts/server-postrm new file mode 100755 index 0000000000..82a9fb3a97 --- /dev/null +++ b/pkg-scripts/server-postrm @@ -0,0 +1,42 @@ +#!/bin/sh +# postrm script for vircadia-server +# +# see: dh_installdeb(1) +. ./deb-functions + +set -e + +# summary of how this script can be called: +# * `remove' +# * `purge' +# * `upgrade' +# * `failed-upgrade' +# * `disappear' +# * `abort-install; +# * `abort-install' +# * `abort-upgrade' +# for details, see https://www.debian.org/doc/debian-policy/ or +# the debian-policy package + + +case "$1" in + purge) + rm -r /etc/opt/vircadia + rm -r /var/lib/vircadia + ;; + + remove|upgrade|failed-upgrade|disappear|abort-install|abort-upgrade) + ;; + + *) + echo "postrm 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