2015-05-02 16:36:51 +02:00
|
|
|
#!/bin/bash
|
2016-06-18 00:06:53 +02:00
|
|
|
|
2021-05-21 01:10:01 +02:00
|
|
|
#=================================================
|
|
|
|
# GENERIC START
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
2016-06-18 10:36:18 +02:00
|
|
|
|
2021-05-21 01:10:01 +02:00
|
|
|
source _common.sh
|
|
|
|
source /usr/share/yunohost/helpers
|
2016-06-18 10:36:18 +02:00
|
|
|
|
2021-05-21 01:10:01 +02:00
|
|
|
#=================================================
|
|
|
|
# CHECK VERSION
|
|
|
|
#=================================================
|
2022-03-13 16:02:11 +01:00
|
|
|
ynh_script_progression --message="Checking version..."
|
2021-05-21 01:10:01 +02:00
|
|
|
|
|
|
|
upgrade_type=$(ynh_check_app_version_changed)
|
|
|
|
|
|
|
|
if ynh_compare_current_package_version --comparison le --version "4.1.5~ynh2"; then
|
2023-09-06 09:53:43 +02:00
|
|
|
upgrade_from_opt=true
|
2021-05-21 01:10:01 +02:00
|
|
|
else
|
2023-09-06 09:53:43 +02:00
|
|
|
upgrade_from_opt=false
|
2021-05-21 01:10:01 +02:00
|
|
|
fi
|
2018-12-18 18:24:07 +01:00
|
|
|
|
2021-05-21 01:10:01 +02:00
|
|
|
#=================================================
|
|
|
|
# STANDARD UPGRADE STEPS
|
|
|
|
#=================================================
|
|
|
|
# STOP SYSTEMD SERVICE
|
|
|
|
#=================================================
|
2015-05-02 16:36:51 +02:00
|
|
|
|
2021-05-21 01:10:01 +02:00
|
|
|
if [[ "$upgrade_from_opt" == "false" ]]; then
|
2023-09-06 09:53:43 +02:00
|
|
|
ynh_script_progression --message="Stopping a systemd service..." --weight=1
|
2017-06-21 13:30:48 +02:00
|
|
|
|
2023-09-06 12:18:24 +02:00
|
|
|
ynh_systemd_action --service_name="$app" --action="stop"
|
2017-06-21 13:30:48 +02:00
|
|
|
fi
|
|
|
|
|
2021-05-21 01:10:01 +02:00
|
|
|
#=================================================
|
|
|
|
# ENSURE DOWNWARD COMPATIBILITY
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Ensuring downward compatibility..." --weight=1
|
2018-02-17 00:20:10 +01:00
|
|
|
|
|
|
|
|
2021-05-21 01:10:01 +02:00
|
|
|
# MIGRATION: Remove old code (from pre-4.1.5 versions, not using venv)
|
|
|
|
if [[ "$upgrade_from_opt" == "true" ]]; then
|
2015-05-02 16:36:51 +02:00
|
|
|
|
2023-09-06 09:53:43 +02:00
|
|
|
# Remove legacy install dir
|
|
|
|
ynh_secure_remove /opt/yunohost/ihatemoney
|
2018-04-02 00:54:39 +02:00
|
|
|
|
2023-09-06 09:53:43 +02:00
|
|
|
# Remove legacy Supervisor config
|
|
|
|
rm -f /etc/supervisor/conf.d/ihatemoney.conf
|
2018-12-18 18:24:07 +01:00
|
|
|
|
2023-09-06 09:53:43 +02:00
|
|
|
if [ -e /etc/ihatemoney/settings.py ]; then
|
|
|
|
# Strip out the no longer used part of the settings
|
|
|
|
python3 -c "d = open('/etc/ihatemoney/settings.py').read().replace('try:\n from settings import *\nexcept ImportError:\n pass\n', ''); open('/etc/ihatemoney/settings.py', 'w').write(d)"
|
|
|
|
# Rename
|
|
|
|
mv /etc/ihatemoney/settings.py "/etc/ihatemoney/ihatemoney.cfg"
|
|
|
|
fi
|
2018-06-24 01:24:15 +02:00
|
|
|
|
2023-09-06 09:53:43 +02:00
|
|
|
for old_file in "/etc/ihatemoney/ihatemoney.cfg" "/etc/$app/gunicorn.conf.py"; do
|
|
|
|
ynh_backup_if_checksum_is_different --file="$old_file"
|
|
|
|
ynh_delete_file_checksum --file="$old_file"
|
|
|
|
done
|
2023-06-10 22:38:45 +02:00
|
|
|
|
2023-09-06 09:53:43 +02:00
|
|
|
install_dir=/var/www/$app
|
2023-09-06 12:18:24 +02:00
|
|
|
ynh_app_setting_set --app="$app" --key=install_dir --value="$install_dir"
|
2018-06-24 01:24:15 +02:00
|
|
|
|
2023-09-06 09:53:43 +02:00
|
|
|
db_name=ihatemoney
|
|
|
|
db_user=$db_name
|
2023-09-06 12:18:24 +02:00
|
|
|
ynh_app_setting_set --app="$app" --key=db_name --value="$db_name"
|
2021-05-21 01:10:01 +02:00
|
|
|
fi
|
2018-06-24 01:24:15 +02:00
|
|
|
|
2022-06-14 00:13:19 +02:00
|
|
|
# If secret_key doesn't exist, create it
|
2023-06-10 22:38:45 +02:00
|
|
|
if [ -z "${secret_key:-}" ]; then
|
2023-09-06 09:53:43 +02:00
|
|
|
secret_key=$(ynh_string_random --length=32)
|
2023-09-06 12:18:24 +02:00
|
|
|
ynh_app_setting_set --app="$app" --key=secret_key --value="$secret_key"
|
2022-06-14 00:13:19 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
# If hashed_password doesn't exist, create it
|
2023-09-05 21:14:47 +02:00
|
|
|
if [ -z "${hashed_password:-}" ]; then
|
2023-09-06 09:53:43 +02:00
|
|
|
password=$(ynh_string_random --length=16)
|
|
|
|
hashed_password=$(_hash_password "$password")
|
2023-09-06 12:18:24 +02:00
|
|
|
ynh_app_setting_set --app="$app" --key=hashed_password --value="$hashed_password"
|
2022-06-14 00:13:19 +02:00
|
|
|
fi
|
|
|
|
|
2023-06-12 16:53:23 +02:00
|
|
|
if [ ! -d "/var/log/$app" ]; then
|
2023-09-06 09:53:43 +02:00
|
|
|
# Configure log directory
|
|
|
|
mkdir -p "/var/log/$app"
|
2023-09-06 12:18:24 +02:00
|
|
|
chown -R "$app:$app" "/var/log/$app"
|
2023-06-12 16:53:23 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
|
2021-05-21 01:10:01 +02:00
|
|
|
#=================================================
|
|
|
|
# SPECIFIC UPGRADE
|
|
|
|
#=================================================
|
2022-06-14 00:13:19 +02:00
|
|
|
# BUILD VENV
|
2021-05-21 01:10:01 +02:00
|
|
|
#=================================================
|
2022-06-14 00:13:19 +02:00
|
|
|
ynh_script_progression --message="Building venv..." --weight=6
|
2018-04-02 00:54:39 +02:00
|
|
|
|
2023-06-10 22:38:45 +02:00
|
|
|
ynh_secure_remove --file="$install_dir/venv"
|
2023-06-10 21:45:19 +02:00
|
|
|
__ynh_python_venv_setup --venv_dir="$install_dir/venv" --packages "${pip_dependencies[*]}"
|
|
|
|
python_venv_site_packages=$(__ynh_python_venv_get_site_packages_dir -d "$install_dir/venv")
|
2018-06-24 01:24:15 +02:00
|
|
|
|
2021-05-21 01:10:01 +02:00
|
|
|
#=================================================
|
|
|
|
# NGINX CONFIGURATION
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=1
|
2018-06-24 01:24:15 +02:00
|
|
|
|
2021-05-21 01:10:01 +02:00
|
|
|
# Create a dedicated NGINX config
|
|
|
|
## Needs $python_venv_site_packages
|
2022-06-14 00:13:19 +02:00
|
|
|
ynh_add_nginx_config
|
2018-06-24 01:24:15 +02:00
|
|
|
|
2021-05-21 01:10:01 +02:00
|
|
|
#=================================================
|
2022-06-14 00:13:19 +02:00
|
|
|
# UPDATE A CONFIG FILE
|
2021-05-21 01:10:01 +02:00
|
|
|
#=================================================
|
2022-06-14 00:13:19 +02:00
|
|
|
ynh_script_progression --message="Updating a configuration file..."
|
2018-06-24 01:24:15 +02:00
|
|
|
|
2021-05-21 01:10:01 +02:00
|
|
|
# Allows to comment some config lines if not using sub path
|
2023-06-10 21:45:19 +02:00
|
|
|
sub_path_only="$(if [[ "$path" == "/" ]]; then echo '# ' ; else echo ''; fi)"
|
2018-06-24 01:24:15 +02:00
|
|
|
|
2023-09-06 12:18:24 +02:00
|
|
|
ynh_add_config --template="../conf/gunicorn.conf.py" --destination="$install_dir/gunicorn.conf.py"
|
2023-06-10 21:45:19 +02:00
|
|
|
ynh_add_config --template="../conf/ihatemoney.cfg" --destination="$install_dir/ihatemoney.cfg"
|
2023-09-06 12:18:24 +02:00
|
|
|
|
2023-09-08 22:53:08 +02:00
|
|
|
chown -R "$app:www-data" "$install_dir"
|
2018-06-24 01:24:15 +02:00
|
|
|
|
2021-05-21 01:10:01 +02:00
|
|
|
#=================================================
|
|
|
|
# SETUP SYSTEMD
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Upgrading systemd configuration..." --weight=1
|
2018-06-24 01:24:15 +02:00
|
|
|
|
2021-05-21 01:10:01 +02:00
|
|
|
ynh_add_systemd_config
|
2018-06-24 01:24:15 +02:00
|
|
|
|
2021-05-21 01:10:01 +02:00
|
|
|
#=================================================
|
|
|
|
# GENERIC FINALIZATION
|
|
|
|
#=================================================
|
|
|
|
# INTEGRATE SERVICE IN YUNOHOST
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
|
2018-06-24 01:24:15 +02:00
|
|
|
|
2023-09-06 12:18:24 +02:00
|
|
|
yunohost service add "$app" --description="$app daemon for IHateMoney" --log=systemd
|
2018-06-24 01:24:15 +02:00
|
|
|
|
2021-05-21 01:10:01 +02:00
|
|
|
#=================================================
|
|
|
|
# START SYSTEMD SERVICE
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Starting a systemd service..." --weight=1
|
2018-06-24 01:24:15 +02:00
|
|
|
|
2023-09-06 12:18:24 +02:00
|
|
|
ynh_systemd_action --service_name="$app" --action="start" --line_match="Listening at"
|
2023-06-10 23:09:04 +02:00
|
|
|
wait_gunicorn_start
|
2018-06-24 01:24:15 +02:00
|
|
|
|
2021-05-21 01:10:01 +02:00
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_script_progression --message="Upgrade of $app completed" --last
|