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)
|
2019-03-27 23:39:07 +01:00
|
|
|
|
2019-05-15 14:00:19 +02:00
|
|
|
is_public=$(ynh_app_setting_get --app=$app --key=is_public)
|
|
|
|
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
|
2019-03-27 23:39:07 +01:00
|
|
|
|
2019-05-15 14:00:19 +02:00
|
|
|
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
|
|
|
|
|
|
|
# Fix is_public as a boolean value
|
|
|
|
if [ "$is_public" = "Yes" ]; then
|
2019-05-15 14:00:19 +02:00
|
|
|
ynh_app_setting_set --app=$app --key=is_public --value=1
|
2019-01-29 21:56:56 +01:00
|
|
|
is_public=1
|
|
|
|
elif [ "$is_public" = "No" ]; then
|
2019-05-15 14:00:19 +02:00
|
|
|
ynh_app_setting_set --app=$app --key=is_public --value=0
|
2019-01-29 21:56:56 +01:00
|
|
|
is_public=0
|
|
|
|
fi
|
|
|
|
|
|
|
|
# If db_name doesn't exist, create it
|
2019-05-15 14:00:19 +02:00
|
|
|
if [ -z "$db_name" ]; then
|
|
|
|
db_name=$(ynh_sanitize_dbid --db_name=$app)
|
|
|
|
ynh_app_setting_set --app=$app --key=db_name --value=$db_name
|
2019-01-29 21:56:56 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
# If final_path doesn't exist, create it
|
2019-05-15 14:00:19 +02:00
|
|
|
if [ -z "$final_path" ]; then
|
2019-01-29 21:56:56 +01:00
|
|
|
final_path=/var/www/$app
|
2019-05-15 14:00:19 +02:00
|
|
|
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
|
2019-01-29 21:56:56 +01:00
|
|
|
fi
|
|
|
|
|
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
|
|
|
|
|
2019-01-29 21:56:56 +01:00
|
|
|
#=================================================
|
|
|
|
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
|
|
|
|
#=================================================
|
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
|
2020-01-05 23:27:00 +01:00
|
|
|
|
|
|
|
#Workaround to be remove in next version
|
2020-01-08 01:06:00 +01:00
|
|
|
ynh_systemd_action --service_name=$app --action="start" --log_path=systemd --line_match="HTTP Server:"
|
2020-01-05 23:27:00 +01:00
|
|
|
|
2019-01-29 21:56:56 +01:00
|
|
|
ynh_clean_setup () {
|
|
|
|
# restore it if the upgrade fails
|
|
|
|
ynh_restore_upgradebackup
|
2019-02-01 22:11:47 +01:00
|
|
|
ynh_clean_check_starting
|
2019-01-29 21:56:56 +01:00
|
|
|
}
|
|
|
|
# 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
|
|
|
|
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
|
|
|
|
2020-01-08 20:29:23 +01:00
|
|
|
config_file="$final_path/config.yml"
|
|
|
|
tmpdir="$(mktemp -d)"
|
|
|
|
|
|
|
|
rsync -a "$config_file" "$tmpdir/."
|
2020-05-22 03:41:54 +02: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
|
2020-01-08 20:29:23 +01:00
|
|
|
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"
|
2020-01-08 20:29:23 +01:00
|
|
|
|
|
|
|
rsync -a "$tmpdir/config.yml" "$final_path/."
|
2020-05-22 03:41:54 +02: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
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# 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
|
|
|
|
|
|
|
# Create a dedicated nginx config
|
|
|
|
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-01-29 21:56:56 +01:00
|
|
|
#=================================================
|
|
|
|
# CREATE DEDICATED USER
|
|
|
|
#=================================================
|
2020-06-03 23:48:48 +02:00
|
|
|
ynh_script_progression --message="Making sure dedicated system user exists..."
|
2019-01-29 21:56:56 +01:00
|
|
|
|
|
|
|
# Create a dedicated user (if not existing)
|
2019-05-15 14:00:19 +02:00
|
|
|
ynh_system_user_create --username=$app --home_dir="$final_path"
|
2019-01-29 21:56:56 +01:00
|
|
|
|
2019-07-07 22:34:33 +02:00
|
|
|
#=================================================
|
|
|
|
# SPECIFIC UPGRADE
|
2019-02-03 02:40:30 +01:00
|
|
|
#=================================================
|
|
|
|
# MODIFY A CONFIG FILE
|
|
|
|
#=================================================
|
2020-06-03 23:48:48 +02:00
|
|
|
ynh_script_progression --message="Modifying a config file..."
|
2019-02-03 02:40:30 +01:00
|
|
|
|
2019-07-07 22:34:33 +02:00
|
|
|
config_file="$final_path/config.yml"
|
|
|
|
ynh_backup_if_checksum_is_different --file=$config_file
|
|
|
|
cp -f ../conf/config.sample.yml $config_file
|
2019-02-03 02:40:30 +01:00
|
|
|
|
2019-12-27 23:53:20 +01:00
|
|
|
ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="$config_file"
|
|
|
|
ynh_replace_string --match_string="__DB_PWD__" --replace_string="$db_pwd" --target_file="$config_file"
|
|
|
|
ynh_replace_string --match_string="__DB_NAME__" --replace_string="$db_name" --target_file="$config_file"
|
2019-05-15 14:00:19 +02:00
|
|
|
|
2019-01-29 21:56:56 +01:00
|
|
|
# Recalculate and store the checksum of the file for the next upgrade.
|
2019-12-27 23:53:20 +01:00
|
|
|
ynh_store_file_checksum --file="$config_file"
|
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
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC FINALIZATION
|
|
|
|
#=================================================
|
|
|
|
# SECURE FILES AND DIRECTORIES
|
|
|
|
#=================================================
|
2020-06-03 23:48:48 +02:00
|
|
|
ynh_script_progression --message="Securing files and directories..."
|
2019-01-29 21:56:56 +01:00
|
|
|
|
|
|
|
# Set permissions on app files
|
2019-02-01 08:55:16 +01:00
|
|
|
chown -R "$app":"$app" "$final_path"
|
2019-01-29 21:56:56 +01:00
|
|
|
|
2020-11-18 17:13:12 +01:00
|
|
|
#=================================================
|
|
|
|
# INTEGRATE SERVICE IN YUNOHOST
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Integrating service in YunoHost..."
|
|
|
|
|
|
|
|
yunohost service add $app --description "$app daemon for Wiki.js" --log_type systemd
|
|
|
|
|
2019-01-29 21:56:56 +01:00
|
|
|
#=================================================
|
|
|
|
# SETUP SSOWAT
|
|
|
|
#=================================================
|
2020-06-03 23:48:48 +02:00
|
|
|
ynh_script_progression --message="Upgrading SSOwat configuration..."
|
2019-01-29 21:56:56 +01:00
|
|
|
|
|
|
|
# Make app public if necessary
|
|
|
|
if [ $is_public -eq 1 ]
|
|
|
|
then
|
|
|
|
# unprotected_uris allows SSO credentials to be passed anyway
|
2019-05-15 14:00:19 +02:00
|
|
|
ynh_app_setting_set --app=$app --key=unprotected_uris --value="/"
|
2019-01-29 21:56:56 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
#=================================================
|
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
|
|
|
|
|
|
|
ynh_replace_string --match_string="__LDAP_USER__" --replace_string="$ldap_user" --target_file="../conf/ldap_message"
|
|
|
|
ynh_replace_string --match_string="__LDAP_PASSWORD__" --replace_string="$ldap_password" --target_file="../conf/ldap_message"
|
|
|
|
ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="../conf/ldap_message"
|
|
|
|
ynh_replace_string --match_string="__PATH_URL__" --replace_string="$path_url" --target_file="../conf/ldap_message"
|
|
|
|
|
|
|
|
ynh_send_readme_to_admin --app_message="../conf/ldap_message" --recipients="root" --type='upgrade'
|
|
|
|
|
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"
|