2019-02-06 19:37:46 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC START
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
source _common.sh
|
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# LOAD SETTINGS
|
|
|
|
#=================================================
|
2019-05-22 22:10:48 +02:00
|
|
|
ynh_script_progression --message="Loading installation settings..." --weight=1
|
2019-02-06 19:37:46 +01:00
|
|
|
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
|
2019-05-22 22:10:48 +02:00
|
|
|
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)
|
|
|
|
is_public=$(ynh_app_setting_get --app=$app --key=is_public)
|
|
|
|
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
|
|
|
|
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
|
|
|
|
db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd)
|
|
|
|
port=$(ynh_app_setting_get --app=$app --key=port)
|
2019-02-06 19:37:46 +01:00
|
|
|
|
2019-05-22 22:10:48 +02:00
|
|
|
#=================================================
|
|
|
|
# CHECK VERSION
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
upgrade_type=$(ynh_check_app_version_changed)
|
2019-02-06 19:37:46 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# ENSURE DOWNWARD COMPATIBILITY
|
|
|
|
#=================================================
|
2019-05-22 22:10:48 +02:00
|
|
|
ynh_script_progression --message="Ensuring downward compatibility..." --weight=1
|
|
|
|
|
|
|
|
# Fix is_public as a boolean value
|
|
|
|
if [ "$is_public" = "Yes" ]; then
|
|
|
|
ynh_app_setting_set --app=$app --key=is_public --value=1
|
|
|
|
is_public=1
|
|
|
|
elif [ "$is_public" = "No" ]; then
|
|
|
|
ynh_app_setting_set --app=$app --key=is_public --value=0
|
|
|
|
is_public=0
|
|
|
|
fi
|
2019-02-06 19:37:46 +01:00
|
|
|
|
|
|
|
# If db_name doesn't exist, create it
|
2019-05-22 22:10:48 +02:00
|
|
|
if [ -z "$db_name" ]; then
|
|
|
|
# Create postgresql database
|
|
|
|
ynh_psql_test_if_first_run
|
|
|
|
db_name=$(ynh_sanitize_dbid --db_name=$app)
|
|
|
|
db_user=$db_name
|
|
|
|
ynh_app_setting_set --app=$app --key=db_name --value=$db_name
|
|
|
|
# Initialize database and store postgres password for upgrade
|
|
|
|
ynh_psql_setup_db --db_name=$db_name --db_user=$db_user
|
|
|
|
fi
|
|
|
|
|
|
|
|
# If final_path doesn't exist, create it
|
|
|
|
if [ -z "$final_path" ]; then
|
|
|
|
final_path=/opt/yunohost/$app
|
|
|
|
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
|
2019-02-06 19:37:46 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
|
|
|
|
#=================================================
|
2019-05-22 22:10:48 +02:00
|
|
|
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=5
|
2019-02-06 19:37:46 +01:00
|
|
|
|
|
|
|
# Backup the current version of the app
|
|
|
|
ynh_backup_before_upgrade
|
|
|
|
ynh_clean_setup () {
|
2019-05-22 22:10:48 +02:00
|
|
|
ynh_clean_check_starting
|
|
|
|
|
2019-02-06 19:37:46 +01:00
|
|
|
# restore it if the upgrade fails
|
|
|
|
ynh_restore_upgradebackup
|
|
|
|
}
|
|
|
|
# Exit if an error occurs during the execution of the script
|
|
|
|
ynh_abort_if_errors
|
|
|
|
|
|
|
|
#=================================================
|
2019-05-22 22:10:48 +02:00
|
|
|
# STANDARD UPGRADE STEPS
|
|
|
|
#=================================================
|
|
|
|
# STOP SYSTEMD SERVICE
|
2019-02-06 19:37:46 +01:00
|
|
|
#=================================================
|
2019-05-22 22:10:48 +02:00
|
|
|
ynh_script_progression --message="Stopping a systemd service..." --weight=1
|
2019-02-06 19:37:46 +01:00
|
|
|
|
2019-05-22 22:10:48 +02:00
|
|
|
ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/$app.log"
|
2019-02-06 19:37:46 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
|
|
#=================================================
|
|
|
|
|
2019-05-22 22:10:48 +02:00
|
|
|
if [ "$upgrade_type" == "UPGRADE_APP" ]
|
|
|
|
then
|
|
|
|
ynh_script_progression --message="Upgrading source files..." --weight=94
|
|
|
|
|
|
|
|
# Download, check integrity, uncompress and patch the source from app.src
|
|
|
|
ynh_setup_source --dest_dir="$final_path"
|
|
|
|
fi
|
2019-02-06 19:37:46 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# NGINX CONFIGURATION
|
|
|
|
#=================================================
|
2019-05-22 22:10:48 +02:00
|
|
|
ynh_script_progression --message="Upgrading nginx web server configuration..." --weight=1
|
2019-02-06 19:37:46 +01:00
|
|
|
|
|
|
|
# Create a dedicated nginx config
|
|
|
|
ynh_add_nginx_config
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# UPGRADE DEPENDENCIES
|
|
|
|
#=================================================
|
2019-05-22 22:10:48 +02:00
|
|
|
ynh_script_progression --message="Upgrading dependencies..." --weight=4
|
2019-02-06 19:37:46 +01:00
|
|
|
|
2019-05-22 22:10:48 +02:00
|
|
|
ynh_install_app_dependencies $pkg_dependencies
|
2019-02-06 19:37:46 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CREATE DEDICATED USER
|
|
|
|
#=================================================
|
2019-05-22 22:10:48 +02:00
|
|
|
ynh_script_progression --message="Making sure dedicated system user exists..." --weight=1
|
2019-02-06 19:37:46 +01:00
|
|
|
|
|
|
|
# Create a dedicated user (if not existing)
|
2019-05-22 22:10:48 +02:00
|
|
|
ynh_system_user_create --username=$app
|
2019-02-06 19:37:46 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SPECIFIC UPGRADE
|
|
|
|
#=================================================
|
2019-05-22 22:10:48 +02:00
|
|
|
# STORE THE CONFIG FILE CHECKSUM
|
2019-02-06 19:37:46 +01:00
|
|
|
#=================================================
|
|
|
|
|
2019-05-22 22:10:48 +02:00
|
|
|
ynh_backup_if_checksum_is_different --file="$final_path/airsonic.properties"
|
2019-02-06 19:37:46 +01:00
|
|
|
|
2019-05-22 22:10:48 +02:00
|
|
|
cp ../conf/airsonic.properties $final_path/airsonic.properties
|
2019-02-06 19:37:46 +01:00
|
|
|
|
2019-05-22 22:10:48 +02:00
|
|
|
ynh_replace_string --match_string="__DB_NAME__" --replace_string=$db_name --target_file="$final_path/airsonic.properties"
|
|
|
|
ynh_replace_string --match_string="__DB_PASSWORD__" --replace_string=$db_pwd --target_file="$final_path/airsonic.properties"
|
2019-02-06 19:37:46 +01:00
|
|
|
|
|
|
|
# Recalculate and store the checksum of the file for the next upgrade.
|
2019-05-22 22:10:48 +02:00
|
|
|
ynh_store_file_checksum --file="$final_path/airsonic.properties"
|
2019-02-06 19:37:46 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SETUP LOGROTATE
|
|
|
|
#=================================================
|
2019-05-22 22:10:48 +02:00
|
|
|
ynh_script_progression --message="Upgrading logrotate configuration..." --weight=1
|
2019-02-06 19:37:46 +01:00
|
|
|
|
|
|
|
# Use logrotate to manage app-specific logfile(s)
|
2019-05-22 22:10:48 +02:00
|
|
|
ynh_use_logrotate --non-append --logfile="$final_path/airsonic.log"
|
2019-02-06 19:37:46 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SETUP SYSTEMD
|
|
|
|
#=================================================
|
2019-05-22 22:10:48 +02:00
|
|
|
ynh_script_progression --message="Upgrading systemd configuration..." --weight=1
|
|
|
|
|
|
|
|
ynh_replace_string --match_string="__PORT__" --replace_string=$port --target_file="../conf/systemd.service"
|
|
|
|
ynh_replace_string --match_string="__PATH__" --replace_string=$path_url --target_file="../conf/systemd.service"
|
2019-02-06 19:37:46 +01:00
|
|
|
|
|
|
|
# Create a dedicated systemd config
|
|
|
|
ynh_add_systemd_config
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC FINALIZATION
|
|
|
|
#=================================================
|
|
|
|
# SECURE FILES AND DIRECTORIES
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Set permissions on app files
|
|
|
|
chown -R $app: $final_path
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SETUP SSOWAT
|
|
|
|
#=================================================
|
2019-05-22 22:10:48 +02:00
|
|
|
ynh_script_progression --message="Upgrading SSOwat configuration..." --weight=1
|
2019-02-06 19:37:46 +01:00
|
|
|
|
|
|
|
# Make app public if necessary
|
|
|
|
if [ $is_public -eq 1 ]
|
|
|
|
then
|
|
|
|
# unprotected_uris allows SSO credentials to be passed anyway
|
2019-05-22 22:10:48 +02:00
|
|
|
ynh_app_setting_set --app=$app --key=unprotected_uris --value="/"
|
2019-02-06 19:37:46 +01:00
|
|
|
fi
|
|
|
|
|
2019-05-22 22:10:48 +02:00
|
|
|
#=================================================
|
|
|
|
# START SYSTEMD SERVICE
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Starting a systemd service..." --weight=12
|
|
|
|
|
|
|
|
ynh_systemd_action --service_name=$app --action="start" --log_path="$final_path/airsonic.log" --line_match="Started Application in"
|
|
|
|
|
2019-02-06 19:37:46 +01:00
|
|
|
#=================================================
|
|
|
|
# RELOAD NGINX
|
|
|
|
#=================================================
|
2019-05-22 22:10:48 +02:00
|
|
|
ynh_script_progression --message="Reloading nginx web server..." --weight=1
|
|
|
|
|
|
|
|
ynh_systemd_action --service_name=nginx --action=reload
|
2019-02-06 19:37:46 +01:00
|
|
|
|
2019-05-22 22:10:48 +02:00
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
2019-02-06 19:37:46 +01:00
|
|
|
|
2019-05-22 22:10:48 +02:00
|
|
|
ynh_script_progression --message="Upgrade of $app completed" --last
|