1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/wikijs_ynh.git synced 2024-09-03 20:36:09 +02:00
wikijs_ynh/scripts/upgrade

210 lines
7.1 KiB
Text
Raw Normal View History

2019-01-29 21:56:56 +01:00
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
2019-07-07 22:34:33 +02:00
source ynh_send_readme_to_admin__2
2019-01-29 21:56:56 +01:00
source /usr/share/yunohost/helpers
#=================================================
# LOAD SETTINGS
#=================================================
2020-06-03 23:48:48 +02:00
ynh_script_progression --message="Loading installation settings..."
2019-01-29 21:56:56 +01:00
app=$YNH_APP_INSTANCE_NAME
2019-05-15 14:00:19 +02:00
domain=$(ynh_app_setting_get --app=$app --key=domain)
path_url=$(ynh_app_setting_get --app=$app --key=path)
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=db_pwd)
port=$(ynh_app_setting_get --app=$app --key=port)
2019-07-07 22:34:33 +02:00
ldap_user=$(ynh_app_setting_get --app=$app --key=ldap_user)
ldap_password=$(ynh_app_setting_get --app=$app --key=ldap_password)
2019-05-15 14:00:19 +02:00
#=================================================
# CHECK VERSION
#=================================================
2020-06-03 23:48:48 +02:00
ynh_script_progression --message="Checking version..."
2019-05-15 14:00:19 +02:00
upgrade_type=$(ynh_check_app_version_changed)
2019-01-29 21:56:56 +01:00
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
2020-06-03 23:48:48 +02:00
ynh_script_progression --message="Ensuring downward compatibility..."
2019-01-29 21:56:56 +01:00
2019-07-07 22:34:33 +02:00
# If ldap_user doesn't exist, retrieve it or create it
if [[ -z "$ldap_user" ]]; then
2019-07-09 08:30:38 +02:00
ldap_user="svc_${app}_ldap"
2019-07-07 22:34:33 +02:00
ldap_password=$(ynh_string_random --length=8)
ynh_app_setting_set "$app" ldap_user "$ldap_user"
ynh_app_setting_set "$app" ldap_password "$ldap_password"
2019-07-09 08:30:38 +02:00
yunohost user create $ldap_user --firstname "SvcWikijsLdap" --lastname "SvcWikijsLdap" --mail ${ldap_user}@$domain --password $ldap_password -q 0
2019-07-07 22:34:33 +02:00
fi
2019-02-20 18:52:24 +01:00
# Remove yarn repository
2019-05-15 14:00:19 +02:00
ynh_secure_remove --file="/etc/apt/sources.list.d/yarn.list"
2019-02-20 18:52:24 +01:00
2019-02-21 18:34:49 +01:00
# Remove old log file
2019-05-15 14:00:19 +02:00
ynh_secure_remove --file="/var/log/$app/"
2019-02-21 18:34:49 +01:00
2019-03-31 19:27:20 +02:00
# Create PostgreSQL User
ynh_psql_create_user $db_name $db_pwd
2020-01-28 00:45:37 +01:00
# Install pg_trgm extension to provide a PostgreSQL search solution
ynh_psql_test_if_first_run
ynh_psql_execute_as_root --sql="CREATE EXTENSION IF NOT EXISTS pg_trgm;" --database=$db_name
2021-02-26 01:29:18 +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
2019-01-29 21:56:56 +01:00
#=================================================
2021-04-09 23:07:01 +02:00
# BACKUP BEFORE CHANGE URL THEN ACTIVE TRAP
2019-01-29 21:56:56 +01:00
#=================================================
2020-06-03 23:48:48 +02:00
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..."
2019-01-29 21:56:56 +01:00
# Backup the current version of the app
ynh_backup_before_upgrade
ynh_clean_setup () {
2021-02-26 01:29:18 +01:00
# Restore it if the upgrade fails
2019-01-29 21:56:56 +01:00
ynh_restore_upgradebackup
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# STANDARD UPGRADE STEPS
2019-05-15 14:00:19 +02:00
#=================================================
# STOP SYSTEMD SERVICE
#=================================================
2020-06-03 23:48:48 +02:00
ynh_script_progression --message="Stopping a systemd service..."
2019-05-15 14:00:19 +02:00
2020-01-08 01:06:00 +01:00
ynh_systemd_action --service_name=$app --action="stop" --log_path=systemd --line_match="Stopped wikijs service"
2019-05-15 14:00:19 +02:00
2021-04-09 20:18:26 +02:00
#=================================================
# CREATE DEDICATED USER
#=================================================
ynh_script_progression --message="Making sure dedicated system user exists..."
# Create a dedicated user (if not existing)
ynh_system_user_create --username=$app --home_dir="$final_path"
2019-01-29 21:56:56 +01:00
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
2019-05-15 14:07:57 +02:00
if [ "$upgrade_type" == "UPGRADE_APP" ]
then
2020-06-03 23:48:48 +02:00
ynh_script_progression --message="Upgrading source files..."
2019-05-15 14:07:57 +02:00
config_file="$final_path/config.yml"
tmpdir="$(mktemp -d)"
rsync -a "$config_file" "$tmpdir/."
2021-02-26 01:29:18 +01:00
if [ -d "$final_path/.ssh" ]; then
rsync -a "$final_path/.ssh" "$tmpdir/."
fi
if [ -d "$final_path/data" ]; then
rsync -a "$final_path/data" "$tmpdir/."
fi
ynh_secure_remove --file="$final_path"
2019-05-15 14:07:57 +02:00
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="$final_path"
rsync -a "$tmpdir/config.yml" "$final_path/."
2021-02-26 01:29:18 +01:00
if [ -d "$tmpdir/.ssh" ]; then
rsync -a "$tmpdir/.ssh" "$final_path/."
fi
if [ -d "$tmpdir/data" ]; then
rsync -a "$tmpdir/data" "$final_path/."
fi
2019-05-15 14:07:57 +02:00
fi
2019-01-29 21:56:56 +01:00
2021-04-09 20:18:26 +02:00
chmod 750 "$final_path"
chmod -R o-rwx "$final_path"
chown -R root:$app "$final_path"
2019-01-29 21:56:56 +01:00
#=================================================
# NGINX CONFIGURATION
#=================================================
2020-09-22 15:45:01 +02:00
ynh_script_progression --message="Upgrading NGINX web server configuration..."
2019-01-29 21:56:56 +01:00
2021-04-09 20:18:26 +02:00
# Create a dedicated NGINX config
2019-01-29 21:56:56 +01:00
ynh_add_nginx_config
#=================================================
# UPGRADE DEPENDENCIES
#=================================================
2020-06-03 23:48:48 +02:00
ynh_script_progression --message="Upgrading dependencies..."
2019-02-03 05:29:13 +01:00
2020-06-03 23:48:48 +02:00
ynh_install_nodejs --nodejs_version=$NODEJS_VERSION
ynh_use_nodejs
2019-03-14 01:19:10 +01:00
ynh_install_app_dependencies $pkg_dependencies
2019-02-03 05:12:39 +01:00
2019-07-07 22:34:33 +02:00
#=================================================
# SPECIFIC UPGRADE
2019-01-29 21:56:56 +01:00
#=================================================
# SETUP SYSTEMD
#=================================================
2020-06-03 23:48:48 +02:00
ynh_script_progression --message="Upgrading systemd configuration..."
2019-01-29 21:56:56 +01:00
# Create a dedicated systemd config
2020-06-03 23:48:48 +02:00
ynh_add_systemd_config --others_var="ynh_node ynh_node_load_PATH"
2019-01-29 21:56:56 +01:00
#=================================================
2021-04-09 20:18:26 +02:00
# UPDATE A CONFIG FILE
2019-01-29 21:56:56 +01:00
#=================================================
2021-04-09 20:18:26 +02:00
ynh_script_progression --message="Updating a config file..."
2019-01-29 21:56:56 +01:00
2021-04-09 20:18:26 +02:00
ynh_add_config --template="../conf/config.sample.yml" --destination="$final_path/config.yml"
2019-01-29 21:56:56 +01:00
2021-04-09 20:18:26 +02:00
chmod 400 "$final_path/config.yml"
chown $app:$app "$final_path/config.yml"
#=================================================
# GENERIC FINALIZATION
2020-11-18 17:13:12 +01:00
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..."
2020-12-04 18:19:54 +01:00
yunohost service add $app --description="$app daemon for Wiki.js" --log="/var/log/$app/$app.log"
2020-11-18 17:13:12 +01:00
2019-01-29 21:56:56 +01:00
#=================================================
2019-07-07 22:34:33 +02:00
# START SYSTEMD SERVICE
2019-01-29 21:56:56 +01:00
#=================================================
2020-06-03 23:48:48 +02:00
ynh_script_progression --message="Starting a systemd service..."
2019-01-29 21:56:56 +01:00
2020-01-08 01:06:00 +01:00
ynh_systemd_action --service_name=$app --action="start" --log_path=systemd --line_match="HTTP Server:"
2019-02-01 22:11:47 +01:00
#=================================================
2019-05-15 14:00:19 +02:00
# RELOAD NGINX
2019-02-01 22:11:47 +01:00
#=================================================
2020-09-22 15:45:01 +02:00
ynh_script_progression --message="Reloading NGINX web server..."
2019-02-01 22:11:47 +01:00
2019-05-15 14:00:19 +02:00
ynh_systemd_action --service_name=nginx --action=reload
2019-02-28 01:40:45 +01:00
2019-07-07 22:34:33 +02:00
#=================================================
# SEND README TO ADMIN
#=================================================
2020-06-03 23:48:48 +02:00
ynh_script_progression --message="Sending ReadMe to admin..."
2019-07-07 22:34:33 +02:00
2021-02-27 08:34:48 +01:00
ynh_add_config --template="../conf/ldap_message" --destination="../conf/message_upgrade"
ynh_send_readme_to_admin --app_message="../conf/message_upgrade" --recipients="root" --type='upgrade'
2019-07-07 22:34:33 +02:00
2019-02-11 06:05:30 +01:00
#=================================================
# END OF SCRIPT
#=================================================
2020-06-03 23:48:48 +02:00
ynh_script_progression --message="Upgrade of $app completed"