#!/bin/bash source _common.sh source /usr/share/yunohost/helpers ynh_script_progression "Checking version..." if ynh_app_upgrading_from_version_before_or_equal_to 4.1.5~ynh2; then upgrade_from_opt=true else upgrade_from_opt=false fi #================================================= # STOP SYSTEMD SERVICE #================================================= if [[ "$upgrade_from_opt" == "false" ]]; then ynh_script_progression "Stopping $app's systemd service..." ynh_systemctl --service="$app" --action="stop" fi #================================================= # ENSURE DOWNWARD COMPATIBILITY #================================================= ynh_script_progression "Ensuring downward compatibility..." # MIGRATION: Remove old code (from pre-4.1.5 versions, not using venv) if [[ "$upgrade_from_opt" == "true" ]]; then # Remove legacy install dir ynh_safe_rm /opt/yunohost/ihatemoney # Remove legacy Supervisor config rm -f /etc/supervisor/conf.d/ihatemoney.conf 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 for old_file in "/etc/ihatemoney/ihatemoney.cfg" "/etc/$app/gunicorn.conf.py"; do ynh_backup_if_checksum_is_different "$old_file" ynh_delete_file_checksum "$old_file" done install_dir=/var/www/$app ynh_app_setting_set --key=install_dir --value="$install_dir" db_name=ihatemoney db_user=$db_name ynh_app_setting_set --key=db_name --value="$db_name" fi # If secret_key doesn't exist, create it # FIXMEhelpers2.1: maybe replace with: ynh_app_setting_set_default --key=secret_key --value=$(ynh_string_random --length=32) if [ -z "${secret_key:-}" ]; then secret_key=$(ynh_string_random --length=32) ynh_app_setting_set --key=secret_key --value="$secret_key" fi # If hashed_password doesn't exist, create it if [ -z "${hashed_password:-}" ]; then password=$(ynh_string_random --length=16) hashed_password=$(_hash_password "$password") ynh_app_setting_set --key=hashed_password --value="$hashed_password" fi if [ ! -d "/var/log/$app" ]; then # Configure log directory mkdir -p "/var/log/$app" #REMOVEME? Assuming ynh_config_add_logrotate is called, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown -R "$app:$app" "/var/log/$app" fi #================================================= # BUILD VENV #================================================= ynh_script_progression "Building venv..." ynh_safe_rm "$install_dir/venv" __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") #================================================= # NGINX CONFIGURATION #================================================= ynh_script_progression "Upgrading NGINX web server configuration..." # Create a dedicated NGINX config ## Needs $python_venv_site_packages ynh_config_add_nginx #================================================= # UPDATE A CONFIG FILE #================================================= ynh_script_progression "Updating configuration..." # Allows to comment some config lines if not using sub path sub_path_only="$(if [[ "$path" == "/" ]]; then echo '# ' ; else echo ''; fi)" ynh_config_add --template="gunicorn.conf.py" --destination="$install_dir/gunicorn.conf.py" ynh_config_add --template="ihatemoney.cfg" --destination="$install_dir/ihatemoney.cfg" #REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown -R "$app:www-data" "$install_dir" #================================================= # SETUP SYSTEMD #================================================= ynh_script_progression "Upgrading systemd configuration..." ynh_config_add_systemd #================================================= # INTEGRATE SERVICE IN YUNOHOST #================================================= ynh_script_progression "Integrating service in YunoHost..." yunohost service add "$app" --description="$app daemon for IHateMoney" --log=systemd #================================================= # START SYSTEMD SERVICE #================================================= ynh_script_progression "Starting $app's systemd service..." ynh_systemctl --service="$app" --action="start" --wait_until="Listening at" wait_gunicorn_start #================================================= # END OF SCRIPT #================================================= ynh_script_progression "Upgrade of $app completed"