2021-03-19 04:09:26 +01:00
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# CHECK VERSION
#=================================================
upgrade_type=$(ynh_check_app_version_changed)
#=================================================
# STANDARD UPGRADE STEPS
#=================================================
2021-03-21 05:17:45 +01:00
# STOP SYSTEMD SERVICES
2021-03-19 04:09:26 +01:00
#=================================================
2021-03-21 05:17:45 +01:00
ynh_script_progression --message="Stopping systemd services..." --weight=1
2021-03-19 04:09:26 +01:00
2021-03-21 05:17:45 +01:00
ynh_systemd_action --service_name="$app-guacd" --action="stop" --log_path="/var/log/$app/guacd.log"
ynh_systemd_action --service_name="$app-tomcat" --action="stop" --log_path="/var/log/$app/tomcat.log"
2021-03-19 04:09:26 +01:00
2021-08-07 13:59:24 +02:00
#=================================================
# CREATE DEDICATED USERS
#=================================================
2023-05-29 17:10:43 +02:00
#REMOVEME? ynh_script_progression --message="Making sure dedicated system user exists..." --weight=1
2021-08-07 13:59:24 +02:00
# Create dedicated users (if not existing)
2023-05-29 17:23:44 +02:00
ynh_system_user_create --username="$app-guacd"
ynh_system_user_create --username="$app-tomcat"
2021-08-07 13:59:24 +02:00
2021-03-19 04:09:26 +01:00
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
2021-08-07 13:59:24 +02:00
if [ "$upgrade_type" == "UPGRADE_APP" ]
then
2021-03-21 05:17:45 +01:00
ynh_script_progression --message="Upgrading source files..." --weight=1
2021-03-19 04:09:26 +01:00
# Download, check integrity, uncompress and patch the source from app.src
2022-01-06 21:04:45 +01:00
setup_sources
2021-03-19 04:09:26 +01:00
fi
#=================================================
# NGINX CONFIGURATION
#=================================================
2021-03-21 05:17:45 +01:00
ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=1
2021-03-19 04:09:26 +01:00
# Create a dedicated NGINX config
ynh_add_nginx_config
#=================================================
# UPGRADE DEPENDENCIES
#=================================================
2023-05-29 17:23:44 +02:00
ynh_script_progression --message="Upgrading dependencies..." --weight=1
2021-03-21 05:17:45 +01:00
2021-07-30 08:25:22 +02:00
# Guacamole depends on Apache Tomcat.
2021-03-21 05:17:45 +01:00
# But installing Tomcat from the Debian repos automatically enables and starts it.
# So we stop and disable it, unless Tomcat was already enabled or started by the user beforehand
tomcat_enabled=""
tomcat_active=""
if [ "$(systemctl cat tomcat9 --quiet)" ]; then
if (systemctl is-enabled tomcat9 --quiet); then
tomcat_enabled=1
fi
if (systemctl is-active tomcat9 --quiet); then
tomcat_active=1
fi
fi
2021-03-19 04:09:26 +01:00
2023-05-29 17:10:43 +02:00
#REMOVEME? ynh_install_app_dependencies $pkg_dependencies
2021-03-19 04:09:26 +01:00
2021-03-21 05:17:45 +01:00
if [ ! $tomcat_enabled ]; then
systemctl disable tomcat9 --quiet
fi
if [ ! $tomcat_active ]; then
systemctl stop tomcat9 --quiet
fi
2021-03-19 04:09:26 +01:00
#=================================================
2021-03-21 05:17:45 +01:00
# SPECIFIC UPGRADE
2021-03-19 04:09:26 +01:00
#=================================================
2021-03-21 05:17:45 +01:00
# COMPILE GUACD
#=================================================
ynh_script_progression --message="Compiling guacd..." --weight=30
2021-03-19 04:09:26 +01:00
2023-05-29 17:23:44 +02:00
pushd "$install_dir/.guacd-src"
2023-05-29 17:10:43 +02:00
./configure --enable-allow-freerdp-snapshots --prefix="$install_dir" --data_dir="$install_dir" --with-freerdp-plugin-dir="$install_dir/lib/x86_64-linux-gnu/freerdp2"
2021-07-30 08:25:22 +02:00
ynh_exec_warn_less make
ynh_exec_warn_less make install
2023-05-29 17:23:44 +02:00
popd
2021-03-19 04:09:26 +01:00
#=================================================
2021-03-21 05:17:45 +01:00
# SETUP TOMCAT
#=================================================
2023-05-29 17:10:43 +02:00
mkdir -p "$install_dir/etc/"
ln -s -f "$install_dir/etc/tomcat9" "$install_dir/var/lib/tomcat9/conf"
ln -s -f "/var/log/$app/tomcat/" "$install_dir/var/lib/tomcat9/logs"
ln -s -f "/var/cache/$app-tomcat9" "$install_dir/var/lib/tomcat9/work"
2021-03-21 05:17:45 +01:00
2021-03-19 04:09:26 +01:00
#=================================================
2021-03-21 05:17:45 +01:00
# CREATE LOG DIRS
2021-03-19 04:09:26 +01:00
#=================================================
2023-05-29 17:23:44 +02:00
2021-03-21 05:17:45 +01:00
mkdir -p "/var/log/$app/tomcat/" "/var/log/$app/guacd/" "/var/log/$app/tomcat/"
2021-03-19 04:09:26 +01:00
#=================================================
2021-03-21 05:17:45 +01:00
# UPDATE CONFIG FILES
2021-03-19 04:09:26 +01:00
#=================================================
2023-05-29 17:10:43 +02:00
ynh_add_config --template="guacamole.properties" --destination="$install_dir/etc/guacamole/guacamole.properties"
2021-03-19 04:09:26 +01:00
2023-05-29 17:10:43 +02:00
ynh_replace_string --match_string="8080" --replace_string="$port" --target_file="$install_dir/etc/tomcat9/server.xml"
2021-03-21 05:17:45 +01:00
2021-08-07 13:59:24 +02:00
#=================================================
# SETUP SYSTEMD
#=================================================
ynh_script_progression --message="Upgrading systemd configuration..." --weight=1
# Create dedicated systemd configs
ynh_add_systemd_config --service="$app-guacd" --template="guacd.service"
ynh_add_systemd_config --service="$app-tomcat" --template="tomcat.service"
2021-03-19 04:09:26 +01:00
#=================================================
# GENERIC FINALIZATION
#=================================================
# SECURE FILES AND DIRECTORIES
#=================================================
# Set permissions on app files
2023-05-29 17:10:43 +02:00
chown -R nobody $install_dir
chmod -R o-rwx $install_dir
setfacl -n -R -m user:$app-guacd:rx -m default:user:$app-guacd:rx $install_dir
setfacl -n -R -m user:$app-tomcat:rx -m default:user:$app-tomcat:rx $install_dir
2021-03-22 21:39:41 +01:00
chown -R $app-guacd:$app-guacd "/var/log/$app/guacd/"
chown -R $app-tomcat:$app-tomcat "/var/log/$app/tomcat/"
2023-05-29 17:10:43 +02:00
chown -R nobody:$app-tomcat "$install_dir/etc/tomcat9/" "$install_dir/etc/guacamole/"
chown -R "$app-tomcat":"$app-tomcat" "$install_dir/var/lib/tomcat9/webapps"
setfacl -n -R -m user:$app-guacd:- -m default:user:$app-guacd:- "$install_dir/var/lib/tomcat9/" "$install_dir/etc/guacamole/" "$install_dir/etc/tomcat9/"
2021-03-19 04:09:26 +01:00
#=================================================
# SETUP LOGROTATE
#=================================================
2021-03-21 05:17:45 +01:00
ynh_script_progression --message="Upgrading logrotate configuration..." --weight=1
2021-03-19 04:09:26 +01:00
# Use logrotate to manage app-specific logfile(s)
2021-03-24 23:07:26 +01:00
ynh_use_logrotate --logfile="/var/log/$app/tomcat/catalina.out" --non-append --specific_user="$app-tomcat/$app-tomcat"
2021-03-19 04:09:26 +01:00
#=================================================
2021-03-21 05:17:45 +01:00
# INTEGRATE SERVICES IN YUNOHOST
2021-03-19 04:09:26 +01:00
#=================================================
2021-03-21 05:17:45 +01:00
ynh_script_progression --message="Integrating services in YunoHost..." --weight=1
2021-03-19 04:09:26 +01:00
2021-03-21 05:17:45 +01:00
yunohost service add "$app-guacd" --description="Guacamole server" --log="/var/log/$app/guacd.log"
yunohost service add "$app-tomcat" --description="Guacamole client" --log="/var/log/$app/tomcat.log"
2021-03-19 04:09:26 +01:00
#=================================================
2021-03-21 05:17:45 +01:00
# START SYSTEMD SERVICES
2021-03-19 04:09:26 +01:00
#=================================================
2021-03-21 05:17:45 +01:00
ynh_script_progression --message="Starting systemd services..." --weight=1
2021-03-19 04:09:26 +01:00
2021-03-21 05:17:45 +01:00
ynh_systemd_action --service_name="$app-guacd" --action="start" --log_path="/var/log/$app/guacd.log"
ynh_systemd_action --service_name="$app-tomcat" --action="start" --log_path="/var/log/$app/tomcat.log"
2021-03-19 04:09:26 +01:00
#=================================================
# UPGRADE FAIL2BAN
#=================================================
2021-03-21 05:17:45 +01:00
ynh_script_progression --message="Reconfiguring Fail2Ban..." --weight=1
2021-03-19 04:09:26 +01:00
# Create a dedicated Fail2Ban config
2021-03-21 05:17:45 +01:00
ynh_add_fail2ban_config --logpath="/var/log/syslog" --failregex='o.a.g.r.auth.AuthenticationService - Authentication attempt from <HOST> for user "[^"]*" failed\.$'
2021-03-19 04:09:26 +01:00
#=================================================
# END OF SCRIPT
#=================================================
2021-03-21 05:17:45 +01:00
ynh_script_progression --message="Upgrade of $app completed" --last