Files

122 lines
5.5 KiB
Bash

#!/bin/bash
#echo "DEBUG: Executing post-install script, swarmops-frontend"
# add system user Swarmops, enable user to write log files
adduser --system --group --no-create-home --quiet swarmops
usermod -a -G syslog swarmops
# Create the log folder
mkdir -p /var/log/swarmops
# make sure the upload folder exists and is writeable by www-data
# do not make any changes to an already existing folder
# We assume a new install if the upload folder didn't exist and
# ask for a few initial settings
if [ ! -e /var/lib/swarmops/upload ]; then
mkdir -p /var/lib/swarmops/upload
chown www-data:www-data /var/lib/swarmops/upload
chmod 777 /var/lib/swarmops/upload
# # If there's only 000-default in apache sites, assume host is fresh
# # and ask if it should be a Swarmops-dedicated host
if [ "$(ls -l /etc/apache2/sites-enabled/ | wc -l)" = "2" ]; then
exec 3>&1;
dialog_selection=$(dialog --title "Swarmops: Autoconfigure Apache?" --menu "This seems to be a new installation of Swarmops Frontend on a newly installed Apache. Would you like to create the necessary site directives and make Swarmops the default Apache site?" 0 0 3 1 "Yes please, make Swarmops the default site for port 80" 2 "Create a Swarmops config, please, but don't enable it" 3 "No thanks, don't touch my Apache, that's for me alone" 2>&1 1>&3);
exec 3>&-;
case "$dialog_selection" in
1 ) echo "Disabling site 000-default; creating/enabling site 000-swarmops."
a2dissite 000-default
cp /usr/share/swarmops/frontend/apache-default-config.txt /etc/apache2/sites-available/000-swarmops.conf
a2ensite 000-swarmops
# # Legacy: we may be asked to start Apache2 by preinst, but we're always doing so, so remove flag
if [ -e /tmp/swarmops-restart-apache.flag ]; then
rm /tmp/swarmops-restart-apache.flag
fi
echo "##################################################################"
echo "# #"
echo "# Swarmops Frontend has been installed. Navigate to this host #"
echo "# using a browser to configure and complete installation. #"
echo "# #"
echo "##################################################################"
;;
2 ) echo "Creating but not enabling the site 'swarmops'. Use a2ensite to enable."
cp /usr/share/swarmops/frontend/apache-default-config.txt /etc/apache2/sites-available/swarmops.conf
echo "##################################################################"
echo "# #"
echo "# Swarmops Frontend has been installed but not enabled. Use #"
echo "# 'a2ensite swarmops' to enable after desired configuration. #"
echo "# #"
echo "##################################################################"
;;
3 ) echo "Neither reconfiguring Apache nor creating configuration file."
echo "##################################################################"
echo "# #"
echo "# Swarmops Frontend has been installed but not activated. When #"
echo "# setting up web server directives, please pay particular #"
echo "# attention to the websocket requirements. #"
echo "# #"
echo "# See /usr/share/swarmops/frontend/Site/apache* for a sample. #"
echo "# #"
echo "##################################################################"
;;
* ) echo "Unknown return code - $dialog_selection"
echo "This should not happen"
;;
esac
else
# If NOT a new fresh host, copy the unactivated Swarmops config to sites-available (option 2 above)
cp /usr/share/swarmops/frontend/apache-default-config.txt /etc/apache2/sites-available/swarmops.conf
echo "##################################################################"
echo "# #"
echo "# Swarmops Frontend has been installed but not enabled. Use #"
echo "# 'a2ensite swarmops' to enable after desired configuration. #"
echo "# #"
echo "##################################################################"
fi
fi
# make sure the web frontend (and its init routine) can write to machineKey.config
# TODO: add test here - only chown if it's the pristine, unedited file
chown www-data:www-data /etc/swarmops/machineKey.config
# make sure the web frontend (and its init) can write to database.config
chown www-data:www-data /etc/swarmops/database.config
# make sure the web frontend (and its init) can write to symmetricKey.config
chown www-data:www-data /etc/swarmops/symmetricKey.config
# Enable required Apache mods and restart Apache (yes, we're always restarting Apache to clear code caches)
a2enmod --quiet proxy
a2enmod --quiet proxy_wstunnel
systemctl restart apache2
# Enable and start the frontend daemon
systemctl enable swarmops-frontend
systemctl start swarmops-frontend
#echo "DEBUG: Exiting post-install script, swarmops-frontend"