2018-03-26 05:50:46 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC START
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
source _common.sh
|
2019-04-03 03:27:49 +02:00
|
|
|
source /usr/share/yunohost/helpers
|
2018-03-26 05:50:46 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# LOAD SETTINGS
|
|
|
|
#=================================================
|
2020-06-01 03:40:44 +02:00
|
|
|
ynh_script_progression --message="Loading installation settings..."
|
2018-03-26 05:50:46 +02:00
|
|
|
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
|
2019-06-03 22:37:54 +02:00
|
|
|
domain=$(ynh_app_setting_get --app=$app --key=domain)
|
|
|
|
path_url=$(ynh_app_setting_get --app=$app --key=path)
|
|
|
|
is_public=$(ynh_app_setting_get --app=$app --key=is_public)
|
|
|
|
admin_email=$(ynh_app_setting_get --app=$app --key=admin_email)
|
|
|
|
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
|
|
|
|
port=$(ynh_app_setting_get --app=$app --key=port)
|
|
|
|
db_name=$(ynh_app_setting_get --app=$app --key=psql_db)
|
|
|
|
db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd)
|
2020-09-27 19:00:21 +02:00
|
|
|
datadir=$(ynh_app_setting_get --app=$app --key=datadir)
|
2019-06-03 22:37:54 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CHECK VERSION
|
|
|
|
#=================================================
|
2020-06-01 03:40:44 +02:00
|
|
|
ynh_script_progression --message="Checking version..."
|
2019-06-03 22:37:54 +02:00
|
|
|
|
|
|
|
upgrade_type=$(ynh_check_app_version_changed)
|
2018-03-26 05:50:46 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# ENSURE DOWNWARD COMPATIBILITY
|
|
|
|
#=================================================
|
2020-06-01 03:40:44 +02:00
|
|
|
ynh_script_progression --message="Ensuring downward compatibility..."
|
2018-03-26 05:50:46 +02:00
|
|
|
|
|
|
|
# Fix is_public as a boolean value
|
|
|
|
if [ "$is_public" = "Yes" ]; then
|
2019-06-03 22:37:54 +02:00
|
|
|
ynh_app_setting_set --app=$app --key=is_public --value=1
|
2018-03-26 05:50:46 +02:00
|
|
|
is_public=1
|
|
|
|
elif [ "$is_public" = "No" ]; then
|
2019-06-03 22:37:54 +02:00
|
|
|
ynh_app_setting_set --app=$app --key=is_public --value=0
|
2018-03-26 05:50:46 +02:00
|
|
|
is_public=0
|
|
|
|
fi
|
|
|
|
|
2020-09-27 19:00:21 +02:00
|
|
|
if [ -z "$datadir" ];
|
|
|
|
then
|
|
|
|
datadir="/home/yunohost.app/${app}/storage"
|
|
|
|
ynh_app_setting_set --app=$app --key=datadir --value=$datadir
|
|
|
|
fi
|
|
|
|
|
2019-04-03 04:44:26 +02:00
|
|
|
# Close a port
|
|
|
|
if yunohost firewall list | grep -q "\- $port$"
|
|
|
|
then
|
2020-06-01 03:40:44 +02:00
|
|
|
ynh_script_progression --message="Closing port $port"
|
2019-04-03 04:44:26 +02:00
|
|
|
ynh_exec_warn_less yunohost firewall disallow TCP $port
|
|
|
|
fi
|
|
|
|
|
2019-06-03 22:37:54 +02:00
|
|
|
# Add PostgreSQL extension for v1.0.0-beta.10.pre.1
|
|
|
|
ynh_psql_execute_as_root --sql="CREATE EXTENSION IF NOT EXISTS unaccent;" --database=$db_name
|
|
|
|
ynh_psql_execute_as_root --sql="CREATE EXTENSION IF NOT EXISTS pg_trgm;" --database=$db_name
|
|
|
|
|
2019-04-03 02:43:43 +02:00
|
|
|
# Remove repository
|
2019-06-03 22:37:54 +02:00
|
|
|
ynh_secure_remove --file="/etc/apt/sources.list.d/jessie-backports.list"
|
|
|
|
ynh_secure_remove --file="/etc/apt/sources.list.d/yarn.list"
|
2019-04-03 02:43:43 +02:00
|
|
|
|
2018-03-29 23:38:29 +02:00
|
|
|
#=================================================
|
|
|
|
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
|
|
|
|
#=================================================
|
2020-06-01 03:40:44 +02:00
|
|
|
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..."
|
2018-03-29 23:38:29 +02:00
|
|
|
|
2020-10-08 01:33:09 +02:00
|
|
|
# Inform the backup/restore process that it should not save the data directory
|
|
|
|
# Use only for the previous backup script that doesn't set 'is_big'
|
|
|
|
ynh_app_setting_set --app=$app --key=backup_core_only --value=1
|
|
|
|
|
2018-03-29 23:38:29 +02:00
|
|
|
# Backup the current version of the app
|
|
|
|
ynh_backup_before_upgrade
|
2020-10-08 01:33:09 +02:00
|
|
|
|
|
|
|
# Remove the option backup_core_only after the backup.
|
|
|
|
ynh_app_setting_delete --app=$app --key=backup_core_only
|
|
|
|
|
2018-03-29 23:38:29 +02:00
|
|
|
ynh_clean_setup () {
|
|
|
|
# restore it if the upgrade fails
|
2019-04-03 03:21:30 +02:00
|
|
|
ynh_clean_check_starting
|
2018-03-29 23:38:29 +02:00
|
|
|
ynh_restore_upgradebackup
|
|
|
|
}
|
|
|
|
# Exit if an error occurs during the execution of the script
|
|
|
|
ynh_abort_if_errors
|
|
|
|
|
2019-04-03 02:30:56 +02:00
|
|
|
#=================================================
|
|
|
|
# STANDARD UPGRADE STEPS
|
2018-05-21 12:10:41 +02:00
|
|
|
#=================================================
|
2019-06-03 22:37:54 +02:00
|
|
|
# STOP SYSTEMD SERVICE
|
2018-05-21 12:10:41 +02:00
|
|
|
#=================================================
|
2020-06-01 03:40:44 +02:00
|
|
|
ynh_script_progression --message="Stopping a systemd service..."
|
2018-05-21 12:10:41 +02:00
|
|
|
|
2020-02-23 19:42:08 +01:00
|
|
|
ynh_systemd_action --service_name=$app --action="stop" --log_path="systemd"
|
2019-04-03 04:44:26 +02:00
|
|
|
|
2019-04-03 06:24:02 +02:00
|
|
|
#=================================================
|
2019-06-03 22:37:54 +02:00
|
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
2019-04-03 06:24:02 +02:00
|
|
|
#=================================================
|
|
|
|
|
2019-06-03 22:37:54 +02:00
|
|
|
if [ "$upgrade_type" == "UPGRADE_APP" ]
|
|
|
|
then
|
2020-06-01 03:40:44 +02:00
|
|
|
ynh_script_progression --message="Upgrading source files..."
|
2019-06-03 22:37:54 +02:00
|
|
|
|
|
|
|
# Create a temporary directory
|
|
|
|
tmpdir="$(mktemp -d)"
|
|
|
|
|
|
|
|
# Backup the config file in the temp dir
|
|
|
|
cp -a "$final_path/config/production.yaml" "$tmpdir/production.yaml"
|
2020-02-13 20:02:14 +01:00
|
|
|
if [ -s "$final_path/config/local-production.json" ]
|
|
|
|
then
|
|
|
|
cp -a "$final_path/config/local-production.json" "$tmpdir/local-production.json"
|
|
|
|
fi
|
2019-06-03 22:37:54 +02:00
|
|
|
|
|
|
|
# Remove the app directory securely
|
|
|
|
ynh_secure_remove --file="$final_path"
|
|
|
|
|
|
|
|
# Download, check integrity, uncompress and patch the source from app.src
|
|
|
|
ynh_setup_source --dest_dir="$final_path"
|
|
|
|
|
2019-10-16 01:33:56 +02:00
|
|
|
#Copy the admin saved settings from tmp directory to final path
|
|
|
|
cp -a "$tmpdir/production.yaml" "$final_path/config/production.yaml"
|
|
|
|
|
|
|
|
if [ -s "$tmpdir/local-production.json" ]
|
|
|
|
then
|
|
|
|
cp -a "$tmpdir/local-production.json" "$final_path/config/local-production.json"
|
|
|
|
else
|
|
|
|
cp ../conf/local-production.json "$final_path/config/local-production.json"
|
|
|
|
fi
|
2019-06-03 22:37:54 +02:00
|
|
|
|
|
|
|
# Remove the tmp directory securely
|
|
|
|
ynh_secure_remove --file="$tmpdir"
|
|
|
|
fi
|
2018-05-21 12:10:41 +02:00
|
|
|
|
2018-03-26 05:50:46 +02:00
|
|
|
#=================================================
|
|
|
|
# NGINX CONFIGURATION
|
|
|
|
#=================================================
|
2020-09-11 14:20:57 +02:00
|
|
|
ynh_script_progression --message="Upgrading NGINX web server configuration..."
|
2018-03-26 05:50:46 +02:00
|
|
|
|
|
|
|
# Create a dedicated nginx config
|
2020-09-27 19:00:21 +02:00
|
|
|
ynh_add_nginx_config "datadir"
|
2018-03-26 05:50:46 +02:00
|
|
|
|
2019-04-03 02:30:56 +02:00
|
|
|
#=================================================
|
|
|
|
# UPGRADE DEPENDENCIES
|
|
|
|
#=================================================
|
2020-06-01 03:40:44 +02:00
|
|
|
ynh_script_progression --message="Upgrading dependencies..."
|
2019-04-03 02:30:56 +02:00
|
|
|
|
2019-04-03 02:43:43 +02:00
|
|
|
# Install nodejs
|
2020-06-01 03:40:44 +02:00
|
|
|
ynh_install_nodejs --nodejs_version=$YNH_NODEJS_VERSION
|
2019-04-03 02:30:56 +02:00
|
|
|
|
2019-04-03 02:43:43 +02:00
|
|
|
# Install dependencies
|
|
|
|
ynh_install_app_dependencies $pkg_dependencies
|
|
|
|
|
|
|
|
# Install ffmpeg from backports for Debian Jessie and from main for others
|
2019-04-03 02:30:56 +02:00
|
|
|
if [ "$(lsb_release --codename --short)" == "jessie" ]; then
|
2019-04-03 02:43:43 +02:00
|
|
|
ynh_install_extra_app_dependencies --repo="deb http://httpredir.debian.org/debian jessie-backports main" --package="ffmpeg"
|
|
|
|
else
|
|
|
|
ynh_add_app_dependencies --package="ffmpeg"
|
2019-04-03 02:30:56 +02:00
|
|
|
fi
|
|
|
|
|
2019-04-03 02:43:43 +02:00
|
|
|
# Install Yarn
|
|
|
|
ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ stable main" --package="yarn" --key="https://dl.yarnpkg.com/debian/pubkey.gpg"
|
2019-04-03 02:30:56 +02:00
|
|
|
|
2020-06-01 03:40:44 +02:00
|
|
|
# Remove hook
|
|
|
|
ynh_secure_remove --file="/usr/share/yunohost/hooks/conf_regen/15-nginx_$app"
|
|
|
|
yunohost tools regen-conf nginx
|
|
|
|
|
2019-04-03 02:30:56 +02:00
|
|
|
#=================================================
|
|
|
|
# CREATE DEDICATED USER
|
|
|
|
#=================================================
|
2020-06-01 03:40:44 +02:00
|
|
|
ynh_script_progression --message="Making sure dedicated system user exists..."
|
2019-04-03 02:30:56 +02:00
|
|
|
|
2020-02-23 19:42:08 +01:00
|
|
|
# Create a dedicated user (if not existing)
|
|
|
|
ynh_system_user_create --username=$app
|
2019-04-03 02:30:56 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SPECIFIC UPGRADE
|
2018-03-26 05:50:46 +02:00
|
|
|
#=================================================
|
2020-06-01 03:40:44 +02:00
|
|
|
# CREATE THE DATA DIRECTORY
|
2018-03-26 05:50:46 +02:00
|
|
|
#=================================================
|
2020-06-01 03:40:44 +02:00
|
|
|
ynh_script_progression --message="Creating the data directory..."
|
2018-03-26 05:50:46 +02:00
|
|
|
|
2020-06-01 03:40:44 +02:00
|
|
|
if [ ! -d "$datadir" ]
|
|
|
|
then
|
|
|
|
# Create app folders
|
|
|
|
mkdir -p "$datadir"
|
|
|
|
fi
|
2018-03-26 05:50:46 +02:00
|
|
|
|
2020-06-01 03:40:44 +02:00
|
|
|
# Give permission to the datadir
|
|
|
|
chown -R "$app":"$app" "$datadir"
|
2018-03-26 05:50:46 +02:00
|
|
|
|
2019-06-06 23:16:31 +02:00
|
|
|
#=================================================
|
2020-06-01 03:40:44 +02:00
|
|
|
# MODIFY A CONFIG FILE
|
2019-06-06 23:16:31 +02:00
|
|
|
#=================================================
|
2020-06-01 03:40:44 +02:00
|
|
|
ynh_script_progression --message="Modifying a config file..."
|
2019-06-06 23:16:31 +02:00
|
|
|
|
2020-06-01 03:40:44 +02:00
|
|
|
config="$final_path/config/production.yaml"
|
|
|
|
ynh_backup_if_checksum_is_different --file="$config"
|
|
|
|
cp ../conf/production.yaml "$config"
|
|
|
|
ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="$config"
|
|
|
|
ynh_replace_string --match_string="__DB_NAME__" --replace_string="$app" --target_file="$config"
|
|
|
|
ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file="$config"
|
|
|
|
ynh_replace_string --match_string="__DB_PWD__" --replace_string="$db_pwd" --target_file="$config"
|
|
|
|
ynh_replace_string --match_string="__EMAIL__" --replace_string="$admin_email" --target_file="$config"
|
|
|
|
ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="$config"
|
2020-09-27 19:00:21 +02:00
|
|
|
ynh_replace_string --match_string="__DATADIR__" --replace_string="$datadir" --target_file="$config"
|
2020-06-01 03:40:44 +02:00
|
|
|
ynh_store_file_checksum --file="$config"
|
|
|
|
|
|
|
|
local_config="$final_path/config/local-production.json"
|
|
|
|
ynh_backup_if_checksum_is_different --file="$local_config"
|
|
|
|
ynh_store_file_checksum --file="$local_config"
|
2019-06-06 23:16:31 +02:00
|
|
|
|
2019-06-03 22:37:54 +02:00
|
|
|
#=================================================
|
|
|
|
# BUILD YARN DEPENDENCIES
|
|
|
|
#=================================================
|
2020-09-11 14:20:57 +02:00
|
|
|
ynh_script_progression --message="Building Yarn dependencies..."
|
2019-06-03 22:37:54 +02:00
|
|
|
|
2019-06-19 00:43:32 +02:00
|
|
|
chown -R "$app":"$app" $final_path
|
|
|
|
|
2019-06-03 22:37:54 +02:00
|
|
|
pushd "$final_path"
|
2019-06-23 16:13:13 +02:00
|
|
|
ynh_use_nodejs
|
2020-06-01 03:40:44 +02:00
|
|
|
sudo -u $app env $ynh_node_load_PATH yarn install --production --pure-lockfile
|
2019-06-03 22:37:54 +02:00
|
|
|
popd
|
|
|
|
|
2018-03-26 05:50:46 +02:00
|
|
|
#=================================================
|
|
|
|
# SETUP SYSTEMD
|
|
|
|
#=================================================
|
2020-06-01 03:40:44 +02:00
|
|
|
ynh_script_progression --message="Upgrading systemd configuration..."
|
2019-04-03 01:30:38 +02:00
|
|
|
|
2018-03-26 05:50:46 +02:00
|
|
|
# Create a dedicated systemd config
|
2020-06-01 03:40:44 +02:00
|
|
|
ynh_add_systemd_config --others_var="ynh_node_load_PATH"
|
2018-03-26 05:50:46 +02:00
|
|
|
|
2019-04-03 02:30:56 +02:00
|
|
|
#=================================================
|
|
|
|
# GENERIC FINALIZATION
|
|
|
|
#=================================================
|
|
|
|
# SECURE FILES AND DIRECTORIES
|
|
|
|
#=================================================
|
2020-06-01 03:40:44 +02:00
|
|
|
ynh_script_progression --message="Securing files and directories..."
|
2018-03-26 05:50:46 +02:00
|
|
|
|
2019-04-03 04:44:26 +02:00
|
|
|
# Set permissions on app files
|
2020-06-01 03:40:44 +02:00
|
|
|
chown -R $app:$app $final_path
|
2018-03-26 05:50:46 +02:00
|
|
|
|
2021-01-02 20:17:30 +01:00
|
|
|
#=================================================
|
|
|
|
# SETUP LOGROTATE
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Upgrading logrotate configuration..."
|
|
|
|
|
|
|
|
# Use logrotate to manage app-specific logfile(s)
|
|
|
|
ynh_use_logrotate --non-append
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# INTEGRATE SERVICE IN YUNOHOST
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Integrating service in YunoHost..."
|
|
|
|
|
|
|
|
yunohost service add $appyunohost service add $app --description "$app daemon for Peertube" --log "$datadir/logs/peertube.log"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# START SYSTEMD SERVICE
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Starting a systemd service..."
|
|
|
|
|
|
|
|
ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="Server listening on localhost"
|
|
|
|
|
2018-03-26 05:50:46 +02:00
|
|
|
#=================================================
|
|
|
|
# SETUP SSOWAT
|
|
|
|
#=================================================
|
2020-06-01 03:40:44 +02:00
|
|
|
ynh_script_progression --message="Upgrading SSOwat configuration..."
|
2018-03-26 05:50:46 +02:00
|
|
|
|
|
|
|
# Make app public if necessary
|
2019-06-03 22:37:54 +02:00
|
|
|
if [ $is_public -eq 1 ]
|
2018-03-26 05:50:46 +02:00
|
|
|
then
|
|
|
|
# unprotected_uris allows SSO credentials to be passed anyway
|
2019-06-03 22:37:54 +02:00
|
|
|
ynh_app_setting_set --app=$app --key=unprotected_uris --value="/"
|
2018-03-26 05:50:46 +02:00
|
|
|
fi
|
|
|
|
|
2019-04-03 02:30:56 +02:00
|
|
|
#=================================================
|
2019-06-03 22:37:54 +02:00
|
|
|
# RELOAD NGINX
|
2019-04-03 02:30:56 +02:00
|
|
|
#=================================================
|
2020-09-11 14:20:57 +02:00
|
|
|
ynh_script_progression --message="Reloading NGINX web server..."
|
2019-04-03 02:30:56 +02:00
|
|
|
|
2019-06-03 22:37:54 +02:00
|
|
|
ynh_systemd_action --service_name=nginx --action=reload
|
2019-04-03 01:30:38 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
|
|
|
|
2020-06-01 03:40:44 +02:00
|
|
|
ynh_script_progression --message="Upgrade of $app completed"
|