2016-09-09 11:07:28 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
2018-04-14 22:02:50 +02:00
|
|
|
#=================================================
|
|
|
|
# GENERIC START
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
source _common.sh
|
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
2020-12-13 21:40:17 +01:00
|
|
|
#=================================================
|
|
|
|
# LOAD SETTINGS
|
|
|
|
#=================================================
|
2022-10-03 08:37:22 +02:00
|
|
|
ynh_script_progression --message="Loading installation settings..." --weight=1
|
2016-09-09 11:07:28 +02:00
|
|
|
|
2020-12-13 21:40:17 +01:00
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
2020-04-11 14:18:16 +02:00
|
|
|
|
2020-12-13 21:40:17 +01: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)
|
|
|
|
port=$(ynh_app_setting_get --app=$app --key=port)
|
|
|
|
salt=$(ynh_app_setting_get --app=$app --key=salt)
|
|
|
|
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
|
|
|
|
db_user=$db_name
|
|
|
|
db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd)
|
2018-04-15 00:27:48 +02:00
|
|
|
|
2022-02-09 00:51:15 +01:00
|
|
|
#=================================================
|
|
|
|
# CHECK VERSION
|
|
|
|
#=================================================
|
2022-10-03 08:37:22 +02:00
|
|
|
ynh_script_progression --message="Checking version..." --weight=1
|
2022-02-09 00:51:15 +01:00
|
|
|
|
|
|
|
upgrade_type=$(ynh_check_app_version_changed)
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
|
|
|
|
#=================================================
|
2022-10-03 08:37:22 +02:00
|
|
|
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=1
|
2022-02-09 00:51:15 +01:00
|
|
|
|
|
|
|
# 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
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# STANDARD UPGRADE STEPS
|
|
|
|
#=================================================
|
|
|
|
# STOP SYSTEMD SERVICE
|
|
|
|
#=================================================
|
2022-10-03 08:37:22 +02:00
|
|
|
ynh_script_progression --message="Stopping a systemd service..." --weight=1
|
2022-02-09 00:51:15 +01:00
|
|
|
|
|
|
|
ynh_systemd_action --service_name=$app --action="stop" --log_path=systemd --line_match="Stopped"
|
|
|
|
|
2018-04-15 00:27:48 +02:00
|
|
|
#=================================================
|
|
|
|
# ENSURE DOWNWARD COMPATIBILITY
|
|
|
|
#=================================================
|
2022-10-03 08:37:22 +02:00
|
|
|
ynh_script_progression --message="Ensuring downward compatibility..." --weight=1
|
2018-04-15 00:27:48 +02:00
|
|
|
|
2020-12-17 20:25:46 +01:00
|
|
|
# Previous versions did not set the DB name as a setting, so we need to set it now (will be used on
|
|
|
|
# remove).
|
|
|
|
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
|
|
|
|
db_user=$db_name
|
|
|
|
fi
|
|
|
|
|
2018-04-15 00:27:48 +02:00
|
|
|
# If final_path doesn't exist, create it
|
2020-12-13 21:40:17 +01:00
|
|
|
if [ -z "$final_path" ]
|
|
|
|
then
|
2018-04-15 00:27:48 +02:00
|
|
|
final_path=/var/www/$app
|
2019-02-27 22:56:36 +01:00
|
|
|
ynh_app_setting_set "$app" final_path "$final_path"
|
2018-04-15 00:27:48 +02:00
|
|
|
fi
|
|
|
|
|
2020-12-13 21:40:17 +01:00
|
|
|
if [ -d "/home/ynh$app" ]
|
|
|
|
then
|
2018-07-30 22:53:00 +02:00
|
|
|
mv "/home/ynh$app/data" "$final_path/data"
|
2020-04-11 14:18:16 +02:00
|
|
|
ynh_secure_remove --file="/home/ynh$app"
|
2018-07-30 22:53:00 +02:00
|
|
|
fi
|
|
|
|
|
2020-12-13 21:40:17 +01:00
|
|
|
if [ -z "$salt" ]
|
|
|
|
then
|
2019-02-27 22:56:36 +01:00
|
|
|
salt=$(ynh_string_random 40)
|
|
|
|
ynh_app_setting_set "$app" salt "$salt"
|
|
|
|
fi
|
|
|
|
|
2022-10-03 08:37:22 +02:00
|
|
|
usermod -d $final_path $app
|
|
|
|
|
2018-04-15 00:27:48 +02:00
|
|
|
#=================================================
|
2022-02-09 00:51:15 +01:00
|
|
|
# CREATE DEDICATED USER
|
2018-04-15 00:27:48 +02:00
|
|
|
#=================================================
|
2022-10-03 08:37:22 +02:00
|
|
|
ynh_script_progression --message="Making sure dedicated system user exists..." --weight=1
|
2018-04-15 00:27:48 +02:00
|
|
|
|
2022-02-09 00:51:15 +01:00
|
|
|
# Create a dedicated user (if not existing)
|
|
|
|
ynh_system_user_create --username=$app --home_dir="$final_path"
|
2018-04-15 00:27:48 +02:00
|
|
|
|
|
|
|
#=================================================
|
2022-02-09 00:51:15 +01:00
|
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
2018-04-15 00:27:48 +02:00
|
|
|
#=================================================
|
|
|
|
|
2022-02-09 00:51:15 +01:00
|
|
|
if [ "$upgrade_type" == "UPGRADE_APP" ]
|
2020-12-13 21:40:17 +01:00
|
|
|
then
|
2022-10-03 08:37:22 +02:00
|
|
|
ynh_script_progression --message="Upgrading source files..." --weight=1
|
2020-12-13 21:40:17 +01:00
|
|
|
|
2022-10-03 08:37:22 +02:00
|
|
|
tmpdir="$(mktemp -d)"
|
|
|
|
cp "$final_path/config.ini" "$tmpdir/config.ini"
|
|
|
|
ynh_secure_remove --file="$final_path"
|
2022-07-15 17:02:41 +02:00
|
|
|
|
2022-02-09 00:51:15 +01:00
|
|
|
# Download, check integrity, uncompress and patch the source from app.src
|
|
|
|
ynh_setup_source --dest_dir="$final_path"
|
2020-12-13 21:40:17 +01:00
|
|
|
|
2022-10-03 08:37:22 +02:00
|
|
|
cp "$tmpdir/config.ini" "$final_path/config.ini"
|
|
|
|
ynh_secure_remove --file="$tmpdir"
|
|
|
|
|
|
|
|
mkdir -p "$final_path/data"
|
2020-12-13 21:40:17 +01:00
|
|
|
fi
|
2018-04-15 00:27:48 +02:00
|
|
|
|
2022-02-09 00:51:15 +01:00
|
|
|
chmod 750 "$final_path"
|
|
|
|
chmod -R o-rwx "$final_path"
|
|
|
|
chown -R $app:www-data "$final_path"
|
|
|
|
|
2018-04-15 00:27:48 +02:00
|
|
|
#=================================================
|
2022-02-09 00:51:15 +01:00
|
|
|
# UPGRADE DEPENDENCIES
|
2018-04-15 00:27:48 +02:00
|
|
|
#=================================================
|
2022-10-03 08:37:22 +02:00
|
|
|
ynh_script_progression --message="Upgrading dependencies..." --weight=1
|
2018-04-15 00:27:48 +02:00
|
|
|
|
2022-02-09 00:51:15 +01:00
|
|
|
ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies
|
|
|
|
ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version
|
2022-10-03 08:37:22 +02:00
|
|
|
ynh_exec_warn_less ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ stable main" --package="yarn" --key="https://dl.yarnpkg.com/debian/pubkey.gpg"
|
2022-02-09 00:51:15 +01:00
|
|
|
|
|
|
|
# Now that postgresql is installed, check the db exists and the user is set up
|
|
|
|
if [ -z "$db_pwd" ]
|
|
|
|
then
|
|
|
|
ynh_script_progression --message="Setting up database"
|
|
|
|
ynh_psql_test_if_first_run
|
|
|
|
ynh_psql_setup_db --db_user=$db_user --db_name=$db_name
|
|
|
|
db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd)
|
|
|
|
fi
|
2018-04-15 00:27:48 +02:00
|
|
|
|
2022-06-15 01:48:45 +02:00
|
|
|
#=================================================
|
|
|
|
# NGINX CONFIGURATION
|
|
|
|
#=================================================
|
2022-10-03 08:37:22 +02:00
|
|
|
ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=1
|
2022-06-15 01:48:45 +02:00
|
|
|
|
|
|
|
# Create a dedicated NGINX config
|
|
|
|
ynh_add_nginx_config
|
|
|
|
|
2018-04-15 00:27:48 +02:00
|
|
|
#=================================================
|
|
|
|
# SPECIFIC UPGRADE
|
|
|
|
#=================================================
|
2022-02-09 00:51:15 +01:00
|
|
|
# INSTALL WOOB WITH PIP
|
2018-04-15 00:27:48 +02:00
|
|
|
#=================================================
|
2022-10-03 08:37:22 +02:00
|
|
|
ynh_script_progression --message="Installing woob..." --weight=1
|
2020-12-13 21:40:17 +01:00
|
|
|
|
2022-10-03 08:37:22 +02:00
|
|
|
locale-gen C.UTF-8
|
|
|
|
update-locale C.UTF-8
|
2020-04-11 14:18:16 +02:00
|
|
|
ynh_secure_remove --file="${final_path}/venv"
|
2022-10-03 08:37:22 +02:00
|
|
|
ynh_exec_as $app virtualenv --python=python3 --system-site-packages "${final_path}/venv"
|
2018-04-15 00:27:48 +02:00
|
|
|
(
|
|
|
|
set +o nounset
|
|
|
|
source "${final_path}/venv/bin/activate"
|
|
|
|
set -o nounset
|
|
|
|
|
2022-10-03 08:37:22 +02:00
|
|
|
ynh_exec_warn_less ynh_exec_as $app RUSTUP_HOME="$final_path"/.rustup CARGO_HOME="$final_path"/.cargo bash -c 'curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -q -y'
|
|
|
|
export PATH="$final_path/.cargo/bin:$PATH"
|
|
|
|
ynh_exec_warn_less ynh_exec_as $app env PATH=$PATH pip install --upgrade pip
|
|
|
|
ynh_exec_warn_less ynh_exec_as $app env PATH=$PATH pip install --upgrade setuptools
|
|
|
|
ynh_exec_warn_less ynh_exec_as $app env PATH=$PATH pip install woob simplejson BeautifulSoup4 PyExecJS typing-extensions pdfminer.six Pillow --ignore-installed
|
|
|
|
ynh_secure_remove --file="$final_path/.cargo"
|
|
|
|
ynh_secure_remove --file="$final_path/.rustup"
|
|
|
|
ynh_secure_remove --file="$final_path/.cache"
|
|
|
|
ynh_secure_remove --file="$final_path/.local"
|
2018-04-15 00:27:48 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
#=================================================
|
2022-02-09 00:51:15 +01:00
|
|
|
# INSTALL KRESUS WITH NPM
|
2018-04-15 00:27:48 +02:00
|
|
|
#=================================================
|
2022-10-03 08:37:22 +02:00
|
|
|
ynh_script_progression --message="Installing app..." --weight=1
|
2020-12-13 21:40:17 +01:00
|
|
|
|
2018-04-15 00:27:48 +02:00
|
|
|
ynh_use_nodejs
|
|
|
|
(
|
|
|
|
cd "$final_path"
|
2020-04-11 14:18:16 +02:00
|
|
|
|
|
|
|
# In case of nodejs upgrade, remove the current node_modules to make sure there are no errors
|
|
|
|
# linked to modules compiled for the previous version.
|
|
|
|
ynh_secure_remove --file="$final_path/node_modules"
|
|
|
|
|
2022-10-03 08:37:22 +02:00
|
|
|
ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH yarn install
|
|
|
|
ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH yarn build:prod
|
|
|
|
ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH yarn cache clean --all
|
|
|
|
ynh_secure_remove --file="$final_path/.cache"
|
|
|
|
ynh_secure_remove --file="$final_path/.yarn"
|
2018-04-15 00:27:48 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
#=================================================
|
2022-02-09 00:51:15 +01:00
|
|
|
# UPDATE A CONFIG FILE
|
2018-04-15 00:27:48 +02:00
|
|
|
#=================================================
|
2022-10-03 08:37:22 +02:00
|
|
|
ynh_script_progression --message="Updating a configuration file..." --weight=1
|
2018-04-15 00:27:48 +02:00
|
|
|
|
2022-02-09 00:51:15 +01:00
|
|
|
ynh_add_config --template="../conf/config.ini" --destination="$final_path/config.ini"
|
2018-04-15 00:27:48 +02:00
|
|
|
|
2022-02-09 00:51:15 +01:00
|
|
|
chmod 400 "$final_path/config.ini"
|
|
|
|
chown $app:$app "$final_path/config.ini"
|
2018-04-15 00:27:48 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SETUP SYSTEMD
|
|
|
|
#=================================================
|
2022-10-03 08:37:22 +02:00
|
|
|
ynh_script_progression --message="Upgrading systemd configuration..." --weight=1
|
2018-04-15 00:27:48 +02:00
|
|
|
|
|
|
|
# Create a dedicated systemd config
|
|
|
|
ynh_add_systemd_config
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC FINALIZATION
|
|
|
|
#=================================================
|
2022-02-09 00:51:15 +01:00
|
|
|
# SETUP LOGROTATE
|
2018-04-15 00:27:48 +02:00
|
|
|
#=================================================
|
2022-10-03 08:37:22 +02:00
|
|
|
ynh_script_progression --message="Upgrading logrotate configuration..." --weight=1
|
2018-04-15 00:27:48 +02:00
|
|
|
|
2022-02-09 00:51:15 +01:00
|
|
|
mkdir -p "/var/log/$app/"
|
|
|
|
touch "/var/log/$app/$app.log"
|
|
|
|
chown -R $app:$app "/var/log/$app/"
|
|
|
|
# Use logrotate to manage app-specific logfile(s)
|
|
|
|
ynh_use_logrotate --non-append
|
2018-08-08 23:28:10 +02:00
|
|
|
|
2022-02-09 00:51:15 +01:00
|
|
|
#=================================================
|
|
|
|
# INTEGRATE SERVICE IN YUNOHOST
|
|
|
|
#=================================================
|
2022-10-03 08:37:22 +02:00
|
|
|
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
|
2019-02-27 13:39:34 +01:00
|
|
|
|
2022-02-09 00:51:15 +01:00
|
|
|
yunohost service add $app --log="/var/log/$app/$app.log"
|
2018-04-15 00:27:48 +02:00
|
|
|
|
2020-12-13 21:40:17 +01:00
|
|
|
#=================================================
|
2022-02-09 00:51:15 +01:00
|
|
|
# START SYSTEMD SERVICE
|
2020-12-13 21:40:17 +01:00
|
|
|
#=================================================
|
2022-10-03 08:37:22 +02:00
|
|
|
ynh_script_progression --message="Starting a systemd service..." --weight=1
|
2020-12-13 21:40:17 +01:00
|
|
|
|
2022-02-09 00:51:15 +01:00
|
|
|
ynh_systemd_action --service_name=$app --action="start" --log_path=systemd --line_match="Server is ready"
|
2020-12-13 21:40:17 +01:00
|
|
|
|
2018-04-15 00:27:48 +02:00
|
|
|
#=================================================
|
|
|
|
# RELOAD NGINX
|
|
|
|
#=================================================
|
2022-10-03 08:37:22 +02:00
|
|
|
ynh_script_progression --message="Reloading NGINX web server..." --weight=1
|
2016-09-09 11:07:28 +02:00
|
|
|
|
2020-12-13 21:40:17 +01:00
|
|
|
ynh_systemd_action --service_name=nginx --action=reload
|
2018-08-08 23:35:41 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SEND README TO ADMIN
|
|
|
|
#=================================================
|
2022-10-03 08:37:22 +02:00
|
|
|
ynh_script_progression --message="Sending ReadMe to admin..." --weight=1
|
2018-08-08 23:35:41 +02:00
|
|
|
|
|
|
|
message="
|
2020-05-03 11:25:46 +02:00
|
|
|
Kresus was successfully updated!
|
2018-08-08 23:35:41 +02:00
|
|
|
|
|
|
|
Domain: $domain
|
|
|
|
Path : $path_url
|
|
|
|
Config: $final_path/config.ini
|
|
|
|
|
2018-08-08 23:43:20 +02:00
|
|
|
Note about config.ini: this package will regenerate the config file on upgrade.
|
|
|
|
If you changed it manually and upgrade Kresus, you'll find a backup in $final_path.
|
|
|
|
|
2018-08-08 23:35:41 +02:00
|
|
|
Are you facing an issue, want to improve this app or say thank you?
|
|
|
|
Please open a new issue in this project: https://github.com/YunoHost-Apps/kresus_ynh
|
|
|
|
"
|
2019-07-14 18:24:00 +02:00
|
|
|
ynh_send_readme_to_admin "$message"
|
2020-05-03 14:03:03 +02:00
|
|
|
|
2020-12-13 21:40:17 +01:00
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
|
|
|
|
2022-10-03 08:37:22 +02:00
|
|
|
ynh_script_progression --message="Upgrade of $app completed" --last
|