mirror of
https://github.com/YunoHost-Apps/wekan_ynh.git
synced 2024-09-03 20:36:09 +02:00
148 lines
4.7 KiB
Bash
148 lines
4.7 KiB
Bash
#!/bin/bash
|
|
|
|
#=================================================
|
|
# GENERIC START
|
|
#=================================================
|
|
# IMPORT GENERIC HELPERS
|
|
#=================================================
|
|
|
|
source _common.sh
|
|
source ynh_package_version
|
|
source ynh_systemd_action
|
|
source /usr/share/yunohost/helpers
|
|
|
|
#=================================================
|
|
# LOAD SETTINGS
|
|
#=================================================
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
domain=$(ynh_app_setting_get $app domain)
|
|
path_url=$(ynh_app_setting_get $app path)
|
|
is_public=$(ynh_app_setting_get $app is_public)
|
|
final_path=$(ynh_app_setting_get $app final_path)
|
|
db_name=$(ynh_app_setting_get $app db_name)
|
|
port=$(ynh_app_setting_get $app port)
|
|
|
|
if [ -z "$db_name" ]
|
|
then
|
|
db_name=$app
|
|
ynh_app_setting_set "$app" db_name "$db_name"
|
|
fi
|
|
|
|
#=================================================
|
|
# CHECK VERSION
|
|
#=================================================
|
|
|
|
abort_if_up_to_date
|
|
# previous function is what defines 'version', more precisely the 'previous version'
|
|
previous_version="${version}"
|
|
|
|
#=================================================
|
|
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
|
|
#=================================================
|
|
|
|
# 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
|
|
|
|
#=================================================
|
|
# ENSURE DOWNWARD COMPATIBILITY
|
|
#=================================================
|
|
|
|
if ynh_version_gt "0.45-2" "${previous_version}" ; then
|
|
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
|
|
|
|
if ynh_version_gt "0.45-3" "${previous_version}" ; then
|
|
yunohost service add $app
|
|
fi
|
|
|
|
if ynh_version_gt "0.77-2" "${previous_version}" ; then
|
|
ynh_install_nodejs 8.9.3
|
|
ynh_use_nodejs
|
|
# Create a dedicated systemd config
|
|
ynh_replace_string "__ENV_PATH__" "$nodejs_path" "../conf/systemd.service"
|
|
ynh_replace_string "__DB_NAME__" "$db_name" "../conf/systemd.service"
|
|
ynh_replace_string "__DOMAIN_URI__" "$domain$path_url" "../conf/systemd.service"
|
|
ynh_replace_string "__PORT__" "$port" "../conf/systemd.service"
|
|
ynh_add_systemd_config
|
|
fi
|
|
|
|
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"
|
|
ynh_use_nodejs
|
|
|
|
# Gotta regen the systemd config because mongodb service name changed
|
|
ynh_replace_string "__ENV_PATH__" "$nodejs_path" "../conf/systemd.service"
|
|
ynh_replace_string "__DB_NAME__" "$db_name" "../conf/systemd.service"
|
|
ynh_replace_string "__DOMAIN_URI__" "$domain$path_url" "../conf/systemd.service"
|
|
ynh_replace_string "__PORT__" "$port" "../conf/systemd.service"
|
|
ynh_add_systemd_config
|
|
fi
|
|
|
|
#=================================================
|
|
# CHECK THE PATH
|
|
#=================================================
|
|
|
|
# Normalize the URL path syntax
|
|
path_url=$(ynh_normalize_url_path $path_url)
|
|
|
|
#=================================================
|
|
# STANDARD UPGRADE STEPS
|
|
#=================================================
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
#=================================================
|
|
|
|
# Download, check integrity, uncompress and patch the source from app.src
|
|
ynh_setup_source "$final_path"
|
|
|
|
#=================================================
|
|
# CREATE DEDICATED USER
|
|
#=================================================
|
|
|
|
# Create a dedicated user (if not existing)
|
|
ynh_system_user_create $app
|
|
|
|
#=================================================
|
|
# GENERIC FINALIZATION
|
|
#=================================================
|
|
# SECURE FILES AND DIRECTORIES
|
|
#=================================================
|
|
|
|
# Set permissions on app files
|
|
chown -R $app: "$final_path"
|
|
chmod -R 640 "$final_path"
|
|
find "$final_path" -type d -print0 | xargs -0 chmod 750
|
|
|
|
# Relaunch a npm install
|
|
pushd $final_path/programs/server
|
|
ynh_use_nodejs
|
|
npm install
|
|
popd
|
|
|
|
#=================================================
|
|
# RELOAD NGINX
|
|
#=================================================
|
|
|
|
systemctl reload nginx
|
|
|
|
#=================================================
|
|
# START SERVICE
|
|
#=================================================
|
|
|
|
ynh_systemd_action --action=start --service_name=$app --log_path="systemd"
|
|
sleep 10
|