1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/guacamole_ynh.git synced 2024-09-03 19:16:03 +02:00
guacamole_ynh/scripts/upgrade
tituspijean 114df1e934
Testing (#10)
* [autopatch] Update issue and PR templates (#6)

Co-authored-by: Yunohost-Bot <>

* Update to tomcat 9.0.31-1~deb10u4 (#8)

* Update to tomcat 9.0.31-1~deb10u4

- It is annoying that older builds are getting removed from source server
- Let's rename the downloaded archive to simplify the code

* Silence make warnings

* Bump package version

Co-authored-by: YunoHost Bot <yunohost-bot@users.noreply.github.com>
2021-07-30 02:25:22 -04:00

256 lines
10 KiB
Bash

#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# LOAD SETTINGS
#=================================================
ynh_script_progression --message="Loading installation settings..." --weight=1
app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get --app=$app --key=domain)
path_url=$(ynh_app_setting_get --app=$app --key=path)
admin=$(ynh_app_setting_get --app=$app --key=admin)
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
port=$(ynh_app_setting_get --app=$app --key=port)
guacd_port=$(ynh_app_setting_get --app=$app --key=guacd_port)
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
db_user=$db_name
db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd)
#=================================================
# CHECK VERSION
#=================================================
upgrade_type=$(ynh_check_app_version_changed)
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=1
# Backup the current version of the app
ynh_backup_before_upgrade
ynh_clean_setup () {
# Restore it if the upgrade fails
ynh_restore_upgradebackup
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# STANDARD UPGRADE STEPS
#=================================================
# STOP SYSTEMD SERVICES
#=================================================
ynh_script_progression --message="Stopping systemd services..." --weight=1
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"
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
if [ "$upgrade_type" == "UPGRADE_APP" ]; then
ynh_script_progression --message="Upgrading source files..." --weight=1
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --source_id="server" --dest_dir="$final_path/.guacd-src"
tomcat_guac_dir="$path_url"
if [ "$path_url" == "/" -o -z "$path_url" ]; then
tomcat_guac_dir="ROOT"
fi
ynh_setup_source --source_id="client" --dest_dir="$final_path/var/lib/tomcat9/webapps/$tomcat_guac_dir"
ynh_setup_source --source_id="auth-ldap" --dest_dir="$final_path/etc/guacamole/extensions/ldap"
mv "$final_path/etc/guacamole/extensions/ldap/guacamole-auth-ldap-1.3.0.jar" "$final_path/etc/guacamole/extensions/guacamole-auth-ldap.jar"
ynh_secure_remove --file="$final_path/etc/guacamole/extensions/ldap"
ynh_setup_source --source_id="auth-header" --dest_dir="$final_path/etc/guacamole/extensions/header"
mv "$final_path/etc/guacamole/extensions/header/guacamole-auth-header-1.2.0.jar" "$final_path/etc/guacamole/extensions/guacamole-auth-header.jar"
ynh_secure_remove --file="$final_path/etc/guacamole/extensions/header"
ynh_setup_source --source_id="auth-jdbc" --dest_dir="$final_path/etc/guacamole/extensions/jdbc"
mv "$final_path/etc/guacamole/extensions/jdbc/mysql/guacamole-auth-jdbc-mysql-1.3.0.jar" "$final_path/etc/guacamole/extensions/guacamole-auth-jdbc-mysql.jar"
mv "$final_path/etc/guacamole/extensions/jdbc/mysql/schema" "$final_path/etc/guacamole/extensions/mysql-schema"
ynh_secure_remove --file="$final_path/etc/guacamole/extensions/jdbc"
ynh_setup_source --source_id="mariadb-java-client" --dest_dir="$final_path/etc/guacamole/lib/"
mv "$final_path/etc/guacamole/lib/mariadb-java-client-2.7.2.jar" "$final_path/etc/guacamole/lib/mariadb-java-client.jar"
ynh_setup_source --source_id="tomcat9_deb" --dest_dir="$final_path/"
pushd "$final_path" || ynh_die
ar x "$final_path/tomcat9.deb" "data.tar.xz"
popd || ynh_die
ynh_secure_remove --file="$final_path/tomcat9.deb"
mkdir -p "$final_path/tomcat9-data"
tar -C "$final_path/tomcat9-data" -xJf "$final_path/data.tar.xz"
cp -r "$final_path/tomcat9-data/usr/share/tomcat9/etc" -T "$final_path/etc/tomcat9/"
cp -r "$final_path/tomcat9-data/etc/tomcat9/" -T "$final_path/etc/tomcat9/"
ynh_secure_remove --file="$final_path/data.tar.xz"
ynh_secure_remove --file="$final_path/tomcat9-data"
fi
#=================================================
# NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=1
# Create a dedicated NGINX config
ynh_add_nginx_config
#=================================================
# UPGRADE DEPENDENCIES
#=================================================
ynh_script_progression --message="Upgrading dependencies..." --weight=1
# Guacamole depends on Apache Tomcat.
# 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
ynh_install_app_dependencies $pkg_dependencies
if [ ! $tomcat_enabled ]; then
systemctl disable tomcat9 --quiet
fi
if [ ! $tomcat_active ]; then
systemctl stop tomcat9 --quiet
fi
#=================================================
# CREATE DEDICATED USERS
#=================================================
ynh_script_progression --message="Making sure dedicated system user exists..." --weight=1
# Create dedicated users (if not existing)
ynh_system_user_create --username="$app-guacd"
ynh_system_user_create --username="$app-tomcat"
#=================================================
# SPECIFIC UPGRADE
#=================================================
# COMPILE GUACD
#=================================================
ynh_script_progression --message="Compiling guacd..." --weight=30
pushd "$final_path/.guacd-src" || ynh_die
./configure --enable-allow-freerdp-snapshots --prefix="$final_path" --datadir="$final_path" --with-freerdp-plugin-dir="$final_path/lib/x86_64-linux-gnu/freerdp2"
ynh_exec_warn_less make
ynh_exec_warn_less make install
popd || ynh_die
#=================================================
# SETUP TOMCAT
#=================================================
mkdir -p "$final_path/etc/"
ln -s -f "$final_path/etc/tomcat9" "$final_path/var/lib/tomcat9/conf"
ln -s -f "/var/log/$app/tomcat/" "$final_path/var/lib/tomcat9/logs"
ln -s -f "/var/cache/$app-tomcat9" "$final_path/var/lib/tomcat9/work"
#=================================================
# CREATE LOG DIRS
#=================================================
mkdir -p "/var/log/$app/tomcat/" "/var/log/$app/guacd/" "/var/log/$app/tomcat/"
#=================================================
# 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" -v guacd_port
ynh_add_systemd_config --service="$app-tomcat" --template="tomcat.service"
#=================================================
# UPDATE CONFIG FILES
#=================================================
ynh_add_config --template="guacamole.properties" --destination="$final_path/etc/guacamole/guacamole.properties"
ynh_replace_string --match_string="8080" --replace_string="$port" --target_file="$final_path/etc/tomcat9/server.xml"
#=================================================
# GENERIC FINALIZATION
#=================================================
# SECURE FILES AND DIRECTORIES
#=================================================
# Set permissions on app files
chown -R root:root $final_path
chmod -R o-rwx $final_path
setfacl -n -R -m user:$app-guacd:rx -m default:user:$app-guacd:rx $final_path
setfacl -n -R -m user:$app-tomcat:rx -m default:user:$app-tomcat:rx $final_path
chown -R $app-guacd:$app-guacd "/var/log/$app/guacd/"
chown -R $app-tomcat:$app-tomcat "/var/log/$app/tomcat/"
chown -R root:$app-tomcat "$final_path/etc/tomcat9/" "$final_path/etc/guacamole/"
chown -R "$app-tomcat":"$app-tomcat" "$final_path/var/lib/tomcat9/webapps"
setfacl -n -R -m user:$app-guacd:- -m default:user:$app-guacd:- "$final_path/var/lib/tomcat9/" "$final_path/etc/guacamole/" "$final_path/etc/tomcat9/"
#=================================================
# SETUP LOGROTATE
#=================================================
ynh_script_progression --message="Upgrading logrotate configuration..." --weight=1
# Use logrotate to manage app-specific logfile(s)
ynh_use_logrotate --logfile="/var/log/$app/tomcat/catalina.out" --non-append --specific_user="$app-tomcat/$app-tomcat"
#=================================================
# INTEGRATE SERVICES IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrating services in YunoHost..." --weight=1
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"
#=================================================
# START SYSTEMD SERVICES
#=================================================
ynh_script_progression --message="Starting systemd services..." --weight=1
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"
#=================================================
# UPGRADE FAIL2BAN
#=================================================
ynh_script_progression --message="Reconfiguring Fail2Ban..." --weight=1
# Create a dedicated Fail2Ban config
ynh_add_fail2ban_config --logpath="/var/log/syslog" --failregex='o.a.g.r.auth.AuthenticationService - Authentication attempt from <HOST> for user "[^"]*" failed\.$'
#=================================================
# RELOAD NGINX
#=================================================
ynh_script_progression --message="Reloading NGINX web server..." --weight=1
ynh_systemd_action --service_name=nginx --action=reload
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Upgrade of $app completed" --last