2017-10-02 02:07:41 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC START
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
|
|
|
|
2019-02-05 21:08:32 +01:00
|
|
|
source _common.sh
|
2019-02-05 23:33:38 +01:00
|
|
|
source ynh_package_version
|
2019-02-05 17:38:12 +01:00
|
|
|
source ynh_systemd_action
|
2017-10-02 02:07:41 +02:00
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# LOAD SETTINGS
|
|
|
|
#=================================================
|
2019-02-20 17:45:11 +01:00
|
|
|
ynh_print_info "Loading installation settings..."
|
2017-10-02 02:07:41 +02:00
|
|
|
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
|
|
|
|
domain=$(ynh_app_setting_get $app domain)
|
2018-02-26 12:47:15 +01:00
|
|
|
path_url=$(ynh_app_setting_get $app path)
|
2017-10-02 02:07:41 +02:00
|
|
|
is_public=$(ynh_app_setting_get $app is_public)
|
|
|
|
final_path=$(ynh_app_setting_get $app final_path)
|
2019-02-05 21:57:12 +01:00
|
|
|
db_name=$(ynh_app_setting_get $app db_name)
|
2017-11-08 21:25:42 +01:00
|
|
|
port=$(ynh_app_setting_get $app port)
|
2017-10-02 02:07:41 +02:00
|
|
|
|
2019-02-05 21:57:12 +01:00
|
|
|
if [ -z "$db_name" ]
|
|
|
|
then
|
|
|
|
db_name=$app
|
|
|
|
ynh_app_setting_set "$app" db_name "$db_name"
|
|
|
|
fi
|
|
|
|
|
2017-10-02 02:07:41 +02:00
|
|
|
#=================================================
|
2019-02-05 22:24:26 +01:00
|
|
|
# CHECK VERSION
|
2017-10-02 02:07:41 +02:00
|
|
|
#=================================================
|
2019-02-05 22:24:26 +01:00
|
|
|
|
2019-02-05 23:28:45 +01:00
|
|
|
abort_if_up_to_date
|
2018-07-01 19:28:26 +02:00
|
|
|
# previous function is what defines 'version', more precisely the 'previous version'
|
|
|
|
previous_version="${version}"
|
2017-10-02 02:07:41 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
|
|
|
|
#=================================================
|
2019-02-20 17:45:11 +01:00
|
|
|
ynh_print_info "Backing up the app before upgrading (may take a while)..."
|
2017-10-02 02:07:41 +02:00
|
|
|
|
2019-02-05 22:24:26 +01:00
|
|
|
# Backup the current version of the app
|
|
|
|
ynh_backup_before_upgrade
|
2017-10-02 02:07:41 +02:00
|
|
|
ynh_clean_setup () {
|
2019-02-05 22:24:26 +01:00
|
|
|
# restore it if the upgrade fails
|
|
|
|
ynh_restore_upgradebackup
|
2017-10-02 02:07:41 +02:00
|
|
|
}
|
2019-02-05 22:24:26 +01:00
|
|
|
# Exit if an error occurs during the execution of the script
|
|
|
|
ynh_abort_if_errors
|
2017-10-02 02:07:41 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# ENSURE DOWNWARD COMPATIBILITY
|
|
|
|
#=================================================
|
2019-02-20 17:45:11 +01:00
|
|
|
ynh_print_info "Ensuring downward compatibility..."
|
2017-10-02 02:07:41 +02:00
|
|
|
|
2018-07-01 19:28:26 +02:00
|
|
|
if ynh_version_gt "0.45-2" "${previous_version}" ; then
|
2017-11-08 21:25:42 +01:00
|
|
|
ynh_replace_string "Environment=ROOT_URL=http://127.0.0.1:$port$path_url" "Environment=ROOT_URL=https://$domain$path_url/" "/etc/systemd/system/$app.service"
|
|
|
|
systemctl daemon-reload
|
|
|
|
fi
|
2019-02-05 22:24:26 +01:00
|
|
|
|
2018-07-01 19:28:26 +02:00
|
|
|
if ynh_version_gt "0.45-3" "${previous_version}" ; then
|
2017-11-09 12:13:38 +01:00
|
|
|
yunohost service add $app
|
2017-11-08 21:43:16 +01:00
|
|
|
fi
|
2019-02-05 22:24:26 +01:00
|
|
|
|
2018-07-01 19:28:26 +02:00
|
|
|
if ynh_version_gt "0.77-2" "${previous_version}" ; then
|
2019-03-06 05:29:12 +01:00
|
|
|
ynh_remove_nodejs
|
2019-03-06 20:26:15 +01:00
|
|
|
ynh_install_nodejs 8.15.1
|
2019-03-06 05:29:12 +01:00
|
|
|
ynh_use_nodejs
|
2018-02-25 02:09:31 +01:00
|
|
|
# Create a dedicated systemd config
|
2019-03-07 03:58:49 +01:00
|
|
|
ynh_replace_string "__NODEJS_PATH__" "$nodejs_path" "../conf/systemd.service"
|
2018-02-25 02:09:31 +01:00
|
|
|
ynh_add_systemd_config
|
2019-03-06 04:05:48 +01:00
|
|
|
# Create a dedicated .env config
|
|
|
|
ynh_backup_if_checksum_is_different "$final_path/.env"
|
|
|
|
cp "../conf/.env" "$final_path/.env"
|
|
|
|
ynh_replace_string "__NODEJS_PATH__" "$nodejs_path" "$final_path/.env"
|
|
|
|
ynh_replace_string "__DB_NAME__" "$db_name" "$final_path/.env"
|
|
|
|
ynh_replace_string "__DOMAIN_URI__" "$domain$path_url" "$final_path/.env"
|
|
|
|
ynh_replace_string "__PORT__" "$port" "$final_path/.env"
|
|
|
|
ynh_store_file_checksum "$final_path/.env"
|
2018-02-25 02:09:31 +01:00
|
|
|
fi
|
2019-02-05 22:24:26 +01:00
|
|
|
|
2018-07-01 19:28:26 +02:00
|
|
|
if ynh_version_gt "1.07~ynh2" "${previous_version}" ; then
|
|
|
|
|
|
|
|
# Replace mongodb packages
|
|
|
|
# Assume no other app needs it >.>
|
|
|
|
rm -f /etc/apt/sources.list.d/mongodb-org-3.2.list
|
|
|
|
ynh_remove_app_dependencies
|
|
|
|
ynh_install_app_dependencies "mongodb mongodb-server"
|
|
|
|
yunohost service remove mongod
|
|
|
|
yunohost service add mongodb --log "/var/log/mongodb/mongodb.log"
|
2019-02-05 22:45:13 +01:00
|
|
|
ynh_use_nodejs
|
2018-07-01 19:28:26 +02:00
|
|
|
|
|
|
|
# Gotta regen the systemd config because mongodb service name changed
|
2019-02-05 22:45:13 +01:00
|
|
|
ynh_replace_string "__ENV_PATH__" "$nodejs_path" "../conf/systemd.service"
|
2019-02-05 21:57:12 +01:00
|
|
|
ynh_replace_string "__DB_NAME__" "$db_name" "../conf/systemd.service"
|
2019-02-05 22:49:19 +01:00
|
|
|
ynh_replace_string "__DOMAIN_URI__" "$domain$path_url" "../conf/systemd.service"
|
2018-07-01 19:28:26 +02:00
|
|
|
ynh_replace_string "__PORT__" "$port" "../conf/systemd.service"
|
|
|
|
ynh_add_systemd_config
|
|
|
|
fi
|
2018-02-25 02:09:31 +01:00
|
|
|
|
2019-02-05 22:24:26 +01:00
|
|
|
#=================================================
|
|
|
|
# CHECK THE PATH
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Normalize the URL path syntax
|
|
|
|
path_url=$(ynh_normalize_url_path $path_url)
|
2017-10-02 02:07:41 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# STANDARD UPGRADE STEPS
|
|
|
|
#=================================================
|
|
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
|
|
#=================================================
|
2019-02-20 17:45:11 +01:00
|
|
|
ynh_print_info "Upgrading source files..."
|
2017-10-02 02:07:41 +02:00
|
|
|
|
|
|
|
# Download, check integrity, uncompress and patch the source from app.src
|
|
|
|
ynh_setup_source "$final_path"
|
|
|
|
|
2019-02-05 22:24:26 +01:00
|
|
|
#=================================================
|
|
|
|
# CREATE DEDICATED USER
|
|
|
|
#=================================================
|
2019-02-20 17:45:11 +01:00
|
|
|
ynh_print_info "Making sure dedicated system user exists..."
|
2019-02-05 22:24:26 +01:00
|
|
|
|
|
|
|
# Create a dedicated user (if not existing)
|
|
|
|
ynh_system_user_create $app
|
|
|
|
|
2017-10-02 02:07:41 +02:00
|
|
|
#=================================================
|
|
|
|
# GENERIC FINALIZATION
|
|
|
|
#=================================================
|
|
|
|
# SECURE FILES AND DIRECTORIES
|
|
|
|
#=================================================
|
2018-02-25 02:09:31 +01:00
|
|
|
|
2019-02-05 22:24:26 +01:00
|
|
|
# Set permissions on app files
|
2017-10-02 02:07:41 +02:00
|
|
|
chown -R $app: "$final_path"
|
|
|
|
chmod -R 640 "$final_path"
|
|
|
|
find "$final_path" -type d -print0 | xargs -0 chmod 750
|
|
|
|
|
2019-02-20 17:45:11 +01:00
|
|
|
#=================================================
|
|
|
|
# SETUP SSOWAT
|
|
|
|
#=================================================
|
|
|
|
ynh_print_info "Upgrading SSOwat configuration..."
|
|
|
|
|
|
|
|
# Make app public if necessary
|
|
|
|
if [ $is_public -eq 1 ]
|
|
|
|
then
|
|
|
|
# unprotected_uris allows SSO credentials to be passed anyway
|
|
|
|
ynh_app_setting_set $app unprotected_uris "/"
|
|
|
|
fi
|
|
|
|
|
2017-10-02 02:07:41 +02:00
|
|
|
#=================================================
|
|
|
|
# RELOAD NGINX
|
|
|
|
#=================================================
|
2019-02-20 17:45:11 +01:00
|
|
|
ynh_print_info "Reloading nginx web server..."
|
2019-02-05 17:41:18 +01:00
|
|
|
|
2017-10-02 02:07:41 +02:00
|
|
|
systemctl reload nginx
|
2019-02-05 17:41:18 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# START SERVICE
|
|
|
|
#=================================================
|
|
|
|
|
2019-03-07 18:52:06 +01:00
|
|
|
ynh_systemd_action --action=restart --service_name=$app --log_path="systemd" --line_match="Kadira: completed instrumenting the app"
|
2019-02-20 17:45:11 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_print_info "Upgrade of $app completed"
|