diff --git a/check_process b/check_process index 994acd9..174f75b 100644 --- a/check_process +++ b/check_process @@ -16,7 +16,7 @@ setup_nourl=0 setup_private=1 setup_public=1 - upgrade=0 + upgrade=1 backup_restore=1 multi_instance=0 incorrect_path=0 diff --git a/scripts/install b/scripts/install index 494f77b..0c738a4 100644 --- a/scripts/install +++ b/scripts/install @@ -1,4 +1,3 @@ - #!/bin/bash #================================================= @@ -84,11 +83,11 @@ ynh_psql_test_if_first_run db_name=$(ynh_sanitize_dbid "$app") db_user=$db_name -db_user_pwd=$(ynh_string_random) +db_pwd=$(ynh_string_random) # Initialize database and store postgres password for upgrade -ynh_psql_create_db "$db_name" "$db_user" "$db_user_pwd" +ynh_psql_create_db "$db_name" "$db_user" "$db_pwd" ynh_app_setting_set "$app" db_name "$db_name" -ynh_app_setting_set "$app" psqlpwd "$db_user_pwd" +ynh_app_setting_set "$app" psqlpwd "$db_pwd" systemctl reload postgresql @@ -164,7 +163,7 @@ ynh_app_setting_set "$app" key "$key" ynh_replace_string "__PORT__" "$port" "$configfile" ynh_replace_string "__DOMAIN__" "$domain" "$configfile" ynh_replace_string "__DBUSER__" "$db_name" "$configfile" -ynh_replace_string "__DBPWD__" "$db_user_pwd" "$configfile" +ynh_replace_string "__DBPWD__" "$db_pwd" "$configfile" ynh_replace_string "__DBNAME__" "$app" "$configfile" ynh_replace_string "__FINALPATH__" "$final_path" "$configfile" ynh_replace_string "__KEY__" "$key" "$configfile" @@ -184,7 +183,6 @@ admin_mail=$(ynh_user_get_info "$admin" "mail") ( set +o nounset source "${final_path}/virtualenv/bin/activate" - cat "${final_path}/load_env" source "${final_path}/load_env" set -o nounset cd "$final_path" diff --git a/scripts/upgrade b/scripts/upgrade new file mode 100644 index 0000000..8506de9 --- /dev/null +++ b/scripts/upgrade @@ -0,0 +1,189 @@ +#!/bin/bash + +#================================================= +# GENERIC START +#================================================= +# IMPORT GENERIC HELPERS +#================================================= + +source _common.sh +source /usr/share/yunohost/helpers + +#================================================= +# LOAD SETTINGS +#================================================= + +app=$YNH_APP_INSTANCE_NAME + +domain=$(ynh_app_setting_get "$app" domain) +path_url=$(ynh_app_setting_get "$app" path) +is_public=$(ynh_app_setting_get "$app" is_public) +final_path=$(ynh_app_setting_get "$app" final_path) +db_name=$(ynh_app_setting_get "$app" db_name) +db_user=$db_name +port=$(ynh_app_setting_get "$app" port) +db_pwd=$(ynh_app_setting_get "$app" psqlpwd) + +#================================================= +# ENSURE DOWNWARD COMPATIBILITY +#================================================= + +# Not yet needed + +#================================================= +# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP +#================================================= + +# 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 + +#================================================= +# CHECK THE PATH +#================================================= + +# Normalize the URL path syntax +path_url=$(ynh_normalize_url_path "$path_url") + +#================================================= +# STANDARD UPGRADE STEPS +#================================================= +# DOWNLOAD, CHECK AND UNPACK SOURCE +#================================================= + +ynh_app_setting_set "$app" final_path "$final_path" +# Download, check integrity, uncompress and patch the source from app.src +ynh_setup_source "$final_path" +ynh_setup_source "$final_path" "app-frontend" + +( + cd "$final_path" + mkdir -p config api data/static data/media data/music front +) + +#================================================= +# NGINX CONFIGURATION +#================================================= + +# there is no need to change the global configuration yet + +# Create a dedicated nginx config +ynh_add_nginx_config + +#================================================= +# CREATE DEDICATED USER +#================================================= + +# Create a system user +ynh_system_user_create "$app" + +#================================================= +# SPECIFIC UPGRADE +# PYTHON DEPENDENCIES +#================================================= + +python3 -m venv "$final_path/virtualenv" +( + set +o nounset + source "${final_path}/virtualenv/bin/activate" + set -o nounset + pip install --upgrade pip + pip install --upgrade setuptools + pip install wheel + pip install -r "${final_path}/api/requirements.txt" +) + +#================================================= +# MODIFY THE CONFIG FILE +#================================================= + +configfile="$final_path/config/.env" + +cp ../conf/env.prod "$configfile" + +key=$(ynh_string_random) + +ynh_app_setting_set "$app" key "$key" + +ynh_replace_string "__PORT__" "$port" "$configfile" +ynh_replace_string "__DOMAIN__" "$domain" "$configfile" +ynh_replace_string "__DBUSER__" "$db_name" "$configfile" +ynh_replace_string "__DBPWD__" "$db_pwd" "$configfile" +ynh_replace_string "__DBNAME__" "$app" "$configfile" +ynh_replace_string "__FINALPATH__" "$final_path" "$configfile" +ynh_replace_string "__KEY__" "$key" "$configfile" + +cat > "$final_path/load_env" <<'EOL' +#!/bin/bash +export $(cat "$final_path/config/.env" | grep -v ^# | xargs) +EOL + +chmod +x "$final_path/load_env" + +#================================================= +# MIGRATE +#================================================= + +( + set +o nounset + source "${final_path}/virtualenv/bin/activate" + source "${final_path}/load_env" + set -o nounset + cd "$final_path" + + # needed for enabling the 'unaccent' extension + ynh_psql_execute_as_root "ALTER USER $db_user WITH SUPERUSER;" + python api/manage.py migrate + ynh_psql_execute_as_root "ALTER USER $db_user WITH NOSUPERUSER;" + + python api/manage.py collectstatic --clear --noinput +) + +#================================================= +# SETUP SYSTEMD +#================================================= + +cp ../conf/funkwhale.target "/etc/systemd/system/$app.target" +ynh_replace_string "__APP__" "$app" "/etc/systemd/system/$app.target" + +# Create a dedicated systemd config +ynh_add_systemd_config "$app-server" "funkwhale-server.service" +ynh_add_systemd_config "$app-worker" "funkwhale-worker.service" +ynh_add_systemd_config "$app-beat" "funkwhale-beat.service" + +systemctl restart "$app".target + +#================================================= +# GENERIC FINALIZATION +#================================================= +# SECURE FILES AND DIRECTORIES +#================================================= + +# Set right permissions for curl installation +chown -R "$app": "$final_path" + +#================================================= +# SETUP SSOWAT +#================================================= + +if [ "$is_public" -eq 0 ] +then # Remove the public access + ynh_app_setting_delete "$app" skipped_uris +fi +# Make app public if necessary +if [ "$is_public" -eq 1 ] +then + # unprotected_uris allows SSO credentials to be passed anyway + ynh_app_setting_set "$app" unprotected_uris "/" +fi + +#================================================= +# RELOAD NGINX +#================================================= + +systemctl reload nginx \ No newline at end of file diff --git a/sources/patches/app-001.patch b/sources/patches/app-001.patch index c6374e5..5e56695 100644 --- a/sources/patches/app-001.patch +++ b/sources/patches/app-001.patch @@ -33,10 +33,3 @@ index 773d60f38ebec50dd46cda63b05b37ac4659573c..f067a2a8b44b4bfbd61b8f7af8682930 return self.subsonic_api_token def set_password(self, raw_password): -diff --git a/changes/changelog.d/198.bugfix b/changes/changelog.d/198.bugfix -new file mode 100644 -index 0000000000000000000000000000000000000000..dd2f4e8fc59c36fa232366e10c0723089345889d ---- /dev/null -+++ b/changes/changelog.d/198.bugfix -@@ -0,0 +1 @@ -+Removed Python 3.6 dependency (secrets module) (#198)