2021-01-09 12:31:07 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC START
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
source _common.sh
|
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# LOAD SETTINGS
|
|
|
|
#=================================================
|
2021-01-09 23:03:18 +01:00
|
|
|
ynh_script_progression --message="Loading installation settings..." --weight=1
|
2021-01-09 12:31:07 +01:00
|
|
|
|
|
|
|
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)
|
2021-01-13 21:58:03 +01:00
|
|
|
password=$(ynh_app_setting_get --app=$app --key=password)
|
2021-01-09 23:03:18 +01:00
|
|
|
port=$(ynh_app_setting_get --app=$app --key=port)
|
2021-02-27 14:29:14 +01:00
|
|
|
turnserver_port=$(ynh_app_setting_get --app=$app --key=turnserver_port)
|
2021-01-13 21:58:03 +01:00
|
|
|
turnserver_pwd=$(ynh_app_setting_get --app=$app --key=turnserver_pwd)
|
2021-01-10 14:40:27 +01:00
|
|
|
architecture=$(ynh_detect_arch)
|
2021-01-09 12:31:07 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CHECK VERSION
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
upgrade_type=$(ynh_check_app_version_changed)
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# ENSURE DOWNWARD COMPATIBILITY
|
|
|
|
#=================================================
|
2021-01-09 23:03:18 +01:00
|
|
|
ynh_script_progression --message="Ensuring downward compatibility..." --weight=1
|
2021-01-09 12:31:07 +01:00
|
|
|
|
|
|
|
# If final_path doesn't exist, create it
|
2021-01-09 23:03:18 +01:00
|
|
|
if [ -z "$final_path" ]; then
|
|
|
|
final_path=/opt/yunohost/$app
|
|
|
|
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
|
|
|
|
fi
|
2021-01-09 12:31:07 +01:00
|
|
|
|
2021-03-01 20:59:15 +01:00
|
|
|
if [ -z "$turnserver_port" ]; then
|
|
|
|
turnserver_port=$(ynh_find_port --port=1194)
|
|
|
|
ynh_app_setting_set --app=$app --key=turnserver_port --value=$turnserver_port
|
|
|
|
ynh_exec_warn_less yunohost firewall allow Both $turnserver_port
|
|
|
|
fi
|
|
|
|
|
2021-03-15 10:14:32 +01:00
|
|
|
# Cleaning legacy permissions
|
|
|
|
if ynh_legacy_permissions_exists; then
|
|
|
|
ynh_legacy_permissions_delete_all
|
|
|
|
|
|
|
|
ynh_app_setting_delete --app=$app --key=is_public
|
|
|
|
fi
|
|
|
|
|
2021-01-09 12:31:07 +01:00
|
|
|
#=================================================
|
|
|
|
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
|
|
|
|
#=================================================
|
2021-01-15 16:34:46 +01:00
|
|
|
ynh_script_progression --message="Backing up Galène before upgrading (may take a while)..." --weight=1
|
2021-01-09 12:31:07 +01:00
|
|
|
|
|
|
|
# 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 SERVICE
|
|
|
|
#=================================================
|
2021-01-09 23:03:18 +01:00
|
|
|
ynh_script_progression --message="Stopping a systemd service..." --weight=3
|
2021-01-09 12:31:07 +01:00
|
|
|
|
2021-01-25 16:01:55 +01:00
|
|
|
ynh_systemd_action --service_name=$app --action=stop --log_path="/var/log/$app/$app.log"
|
2021-01-09 12:31:07 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
if [ "$upgrade_type" == "UPGRADE_APP" ]
|
|
|
|
then
|
2021-01-09 23:03:18 +01:00
|
|
|
ynh_script_progression --message="Upgrading source files..." --weight=2
|
|
|
|
|
|
|
|
# Create a temporary directory
|
|
|
|
tmpdir="$(mktemp -d)"
|
|
|
|
|
|
|
|
# Backup the config file in the temp dir
|
|
|
|
cp -ar "$final_path/groups" "$tmpdir/groups"
|
|
|
|
|
|
|
|
# Remove the app directory securely
|
|
|
|
ynh_secure_remove --file="$final_path"
|
|
|
|
|
2021-01-10 14:40:27 +01:00
|
|
|
ynh_setup_source --dest_dir="$final_path" --source_id="$architecture"
|
2021-01-09 23:03:18 +01:00
|
|
|
|
2021-02-25 10:12:39 +01:00
|
|
|
groups="$final_path/groups"
|
|
|
|
data="$final_path/data"
|
|
|
|
|
|
|
|
mkdir -p "$groups"
|
|
|
|
mkdir -p "$data"
|
|
|
|
|
2021-01-09 23:03:18 +01:00
|
|
|
# Copy the admin saved settings from tmp directory to final path
|
2021-02-25 10:12:39 +01:00
|
|
|
cp -ar "$tmpdir/groups" "$final_path"
|
2021-01-09 23:03:18 +01:00
|
|
|
|
|
|
|
# Remove the tmp directory securely
|
|
|
|
ynh_secure_remove --file="$tmpdir"
|
2021-01-09 12:31:07 +01:00
|
|
|
|
2021-02-25 10:12:39 +01:00
|
|
|
ynh_backup_if_checksum_is_different --file="$final_path/data/passwd"
|
|
|
|
ynh_add_config --template="../conf/passwd" --destination="$final_path/data/passwd"
|
|
|
|
ynh_store_file_checksum --file="$final_path/data/passwd"
|
|
|
|
|
|
|
|
ynh_backup_if_checksum_is_different --file="$final_path/data/ice-servers.json"
|
|
|
|
ynh_add_config --template="../conf/ice-servers.json" --destination="$final_path/data/ice-servers.json"
|
|
|
|
ynh_store_file_checksum --file="$final_path/data/ice-servers.json"
|
|
|
|
|
2021-01-09 23:03:18 +01:00
|
|
|
# Recreate certificates
|
2021-02-25 10:12:39 +01:00
|
|
|
pushd "$final_path/data"
|
2021-02-27 10:09:46 +01:00
|
|
|
ynh_exec_warn_less openssl req -newkey rsa:2048 -nodes -keyout key.pem -x509 -days 365 -out cert.pem \
|
|
|
|
-subj "/C=/ST=/L=/O=/OU=/CN=/emailAddress="
|
2021-02-25 10:12:39 +01:00
|
|
|
chmod 640 {key.pem,cert.pem}
|
2021-01-10 14:48:30 +01:00
|
|
|
popd
|
2021-01-09 12:31:07 +01:00
|
|
|
fi
|
|
|
|
|
2021-01-13 21:58:03 +01:00
|
|
|
#=================================================
|
|
|
|
# MULTINSTANCE SUPPORT
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
if [ ! -e /etc/$app/coturn.conf ]
|
|
|
|
then
|
2021-01-15 16:34:46 +01:00
|
|
|
ynh_script_progression --message="Creating an independant service for Coturn..." --weight=1
|
2021-01-13 21:58:03 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CREATE AN INDEPENDANT SERVICE FOR COTURN
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Disable default config for turnserver and create a new service
|
|
|
|
systemctl stop coturn.service
|
|
|
|
|
|
|
|
# Set by default the system config for coturn
|
|
|
|
echo "" > /etc/turnserver.conf
|
|
|
|
ynh_replace_string --match_string="TURNSERVER_ENABLED=1" --replace_string="TURNSERVER_ENABLED=0" --target_file=/etc/default/coturn
|
|
|
|
|
|
|
|
# Set a port for each service in turnserver
|
2021-02-27 14:51:38 +01:00
|
|
|
turnserver_port=$(ynh_find_port --port=1194)
|
2021-03-01 10:17:43 +01:00
|
|
|
ynh_app_setting_set --app=$app --key=turnserver_port --value=$turnserver_port
|
2021-02-27 14:51:38 +01:00
|
|
|
ynh_exec_warn_less yunohost firewall allow Both $turnserver_port
|
2021-01-13 21:58:03 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# MAKE A CLEAN LOGROTATE CONFIG
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_use_logrotate --logfile /var/log/$app --nonappend
|
|
|
|
fi
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CREATE A DH FILE
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Creating a dhparam file..." --weight=3
|
|
|
|
|
|
|
|
# WARNING : theses command are used in INSTALL, UPGRADE, RESTORE
|
|
|
|
# For any update do it in all files
|
|
|
|
|
2021-02-28 15:01:36 +01:00
|
|
|
# Make dhparam cert for Coturn if it doesn't exist
|
2021-01-13 21:58:03 +01:00
|
|
|
if [ ! -e /etc/ssl/private/dh2048.pem ]
|
|
|
|
then
|
|
|
|
ynh_exec_warn_less openssl dhparam -out /etc/ssl/private/dh2048.pem -outform PEM -2 2048 -dsaparam
|
|
|
|
chown root:ssl-cert /etc/ssl/private/dh2048.pem
|
|
|
|
chmod 640 /etc/ssl/private/dh2048.pem
|
|
|
|
fi
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SPECIFIC UPGRADE
|
|
|
|
#=================================================
|
|
|
|
# UPDATE COTURN CONFIG
|
|
|
|
#=================================================
|
2021-01-15 16:34:46 +01:00
|
|
|
ynh_script_progression --message="Updating Coturn config..." --weight=1
|
2021-01-13 21:58:03 +01:00
|
|
|
|
|
|
|
# WARNING : theses command are used in INSTALL, UPGRADE
|
|
|
|
# For any update do it in all files
|
|
|
|
|
|
|
|
coturn_config_path="/etc/$app/coturn.conf"
|
|
|
|
|
2021-02-25 10:12:39 +01:00
|
|
|
ynh_add_config --template="../conf/coturn/turnserver.conf" --destination="$coturn_config_path"
|
2021-01-13 21:58:03 +01:00
|
|
|
|
|
|
|
# Get public IP and set as external IP for coturn
|
|
|
|
# note : '|| true' is used to ignore the errors if we can't get the public ipv4 or ipv6
|
2021-03-01 00:58:01 +01:00
|
|
|
public_ip4="$(curl -s ip.yunohost.org)" || true
|
|
|
|
public_ip6="$(curl -s ipv6.yunohost.org)" || true
|
2021-01-13 21:58:03 +01:00
|
|
|
|
2021-01-25 15:58:19 +01:00
|
|
|
if ( [[ -n "$public_ip4" ]] && ynh_validate_ip4 --ip_address="$public_ip4" || [[ -n "$public_ip6" ]] && ynh_validate_ip6 --ip_address="$public_ip6" )
|
2021-01-13 21:58:03 +01:00
|
|
|
then
|
2021-01-25 15:58:19 +01:00
|
|
|
echo "external-ip=${public_ip4}/${public_ip6}" >> "$coturn_config_path"
|
2021-01-13 21:58:03 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
ynh_store_file_checksum --file="$coturn_config_path"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# ADD SCRIPT FOR COTURN CRON AND APP SERVICE
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# WARNING : theses command are used in INSTALL, UPGRADE
|
|
|
|
# For any update do it in all files
|
|
|
|
|
2021-01-15 17:05:04 +01:00
|
|
|
cp ../sources/Coturn_config_rotate.sh $final_path/Coturn_config_rotate.sh
|
2021-01-25 15:58:19 +01:00
|
|
|
ynh_replace_string --match_string=__APP__ --replace_string=$app --target_file="$final_path/Coturn_config_rotate.sh"
|
|
|
|
chmod +x $final_path/Coturn_config_rotate.sh
|
2021-01-13 21:58:03 +01:00
|
|
|
|
2021-01-09 12:31:07 +01:00
|
|
|
#=================================================
|
|
|
|
# NGINX CONFIGURATION
|
|
|
|
#=================================================
|
2021-01-09 23:03:18 +01:00
|
|
|
ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=3
|
2021-01-09 12:31:07 +01:00
|
|
|
|
|
|
|
# Create a dedicated NGINX config
|
|
|
|
ynh_add_nginx_config
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# UPGRADE DEPENDENCIES
|
|
|
|
#=================================================
|
2021-01-13 21:58:03 +01:00
|
|
|
ynh_script_progression --message="Upgrading dependencies..." --weight=1
|
2021-01-09 12:31:07 +01:00
|
|
|
|
2021-01-13 21:58:03 +01:00
|
|
|
ynh_install_app_dependencies $pkg_dependencies
|
2021-01-09 12:31:07 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CREATE DEDICATED USER
|
|
|
|
#=================================================
|
2021-01-09 23:03:18 +01:00
|
|
|
ynh_script_progression --message="Making sure dedicated system user exists..." --weight=1
|
2021-01-09 12:31:07 +01:00
|
|
|
|
|
|
|
# Create a dedicated user (if not existing)
|
|
|
|
ynh_system_user_create --username=$app
|
2021-03-01 10:17:43 +01:00
|
|
|
ynh_system_user_create --username=turnserver
|
2021-01-13 21:58:03 +01:00
|
|
|
adduser turnserver ssl-cert
|
2021-01-09 12:31:07 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SETUP SYSTEMD
|
|
|
|
#=================================================
|
2021-01-09 23:03:18 +01:00
|
|
|
ynh_script_progression --message="Upgrading systemd configuration..." --weight=1
|
2021-01-09 12:31:07 +01:00
|
|
|
|
|
|
|
# Create a dedicated systemd config
|
|
|
|
ynh_add_systemd_config
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC FINALIZATION
|
|
|
|
#=================================================
|
|
|
|
# SECURE FILES AND DIRECTORIES
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Set permissions on app files
|
2021-03-10 09:20:58 +01:00
|
|
|
chown -R $app: $final_path
|
2021-01-09 23:03:18 +01:00
|
|
|
chmod -R 755 $final_path
|
2021-03-10 09:20:58 +01:00
|
|
|
chown -R $app /var/log/$app
|
2021-01-13 21:58:03 +01:00
|
|
|
chown -R $app:root /etc/$app
|
2021-01-25 15:58:19 +01:00
|
|
|
chown turnserver:root $coturn_config_path
|
2021-01-13 21:58:03 +01:00
|
|
|
chmod -R u=rwX,g=rX,o= /etc/$app
|
|
|
|
chmod 770 $final_path/Coturn_config_rotate.sh
|
|
|
|
setfacl -R -m user:turnserver:rX /etc/$app
|
|
|
|
setfacl -R -m user:turnserver:rwX /var/log/$app
|
2021-01-09 12:31:07 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SETUP LOGROTATE
|
|
|
|
#=================================================
|
2021-01-13 21:58:03 +01:00
|
|
|
ynh_script_progression --message="Upgrading logrotate configuration..." --weight=1
|
2021-01-09 12:31:07 +01:00
|
|
|
|
2021-01-09 21:34:33 +01:00
|
|
|
# # Use logrotate to manage app-specific logfile(s)
|
2021-01-13 21:58:03 +01:00
|
|
|
ynh_use_logrotate --non-append
|
2021-01-09 12:31:07 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# INTEGRATE SERVICE IN YUNOHOST
|
|
|
|
#=================================================
|
2021-01-13 21:58:03 +01:00
|
|
|
ynh_script_progression --message="Integrating service in YunoHost..." --weight=2
|
2021-01-09 12:31:07 +01:00
|
|
|
|
2021-03-01 20:42:12 +01:00
|
|
|
yunohost service add $app --description="Videoconferencing server" --log="/var/log/$app/$app.log" --needs_exposed_ports $port
|
|
|
|
yunohost service add coturn-$app --description="Coturn TURN server" --log="/var/log/$app/turnserver.log" --needs_exposed_ports $turnserver_port
|
2021-01-09 12:31:07 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# START SYSTEMD SERVICE
|
|
|
|
#=================================================
|
2021-01-09 23:03:18 +01:00
|
|
|
ynh_script_progression --message="Starting a systemd service..." --weight=1
|
2021-01-09 12:31:07 +01:00
|
|
|
|
2021-01-25 20:06:57 +01:00
|
|
|
ynh_systemd_action --service_name=coturn-$app.service --action=restart --log_path="/var/log/$app/turnserver.log"
|
2021-01-13 21:58:03 +01:00
|
|
|
ynh_systemd_action --service_name=$app --action=restart --log_path="/var/log/$app/$app.log"
|
2021-01-09 12:31:07 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RELOAD NGINX
|
|
|
|
#=================================================
|
2021-01-09 23:03:18 +01:00
|
|
|
ynh_script_progression --message="Reloading NGINX web server..." --weight=2
|
2021-01-09 12:31:07 +01:00
|
|
|
|
|
|
|
ynh_systemd_action --service_name=nginx --action=reload
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
|
|
|
|
2021-01-15 16:34:46 +01:00
|
|
|
ynh_script_progression --message="Upgrade of Galène completed" --last
|