diff --git a/.github/workflows/updater.sh b/.github/workflows/updater.sh new file mode 100644 index 0000000..4c4e177 --- /dev/null +++ b/.github/workflows/updater.sh @@ -0,0 +1,127 @@ +#!/bin/bash + +#================================================= +# PACKAGE UPDATING HELPER +#================================================= + +# This script is meant to be run by GitHub Actions +# The YunoHost-Apps organisation offers a template Action to run this script periodically +# Since each app is different, maintainers can adapt its contents so as to perform +# automatic actions when a new upstream release is detected. + +#================================================= +# FETCHING LATEST RELEASE AND ITS ASSETS +#================================================= + +# Fetching information +current_version=$(cat manifest.json | jq -j '.version|split("~")[0]') +# Some jq magic is needed, because the latest upstream release is not always the latest version (e.g. security patches for older versions) +version=$(curl --silent "https://dev.funkwhale.audio/api/v4/projects/17/repository/tags" | jq -r '.[] | select( .prerelease != true ) | .name' | sort -V | tail -1) +assets=("https://dev.funkwhale.audio/funkwhale/funkwhale/-/jobs/artifacts/$version/download?job=build_api" "https://dev.funkwhale.audio/funkwhale/funkwhale/builds/artifacts/$version/download?job=build_front") + +# Later down the script, we assume the version has only digits and dots +# Sometimes the release name starts with a "v", so let's filter it out. +# You may need more tweaks here if the upstream repository has different naming conventions. +if [[ ${version:0:1} == "v" || ${version:0:1} == "V" ]]; then + version=${version:1} +fi + +# Setting up the environment variables +echo "Current version: $current_version" +echo "Latest release from upstream: $version" +echo "VERSION=$version" >> $GITHUB_ENV +echo "REPO=$repo" >> $GITHUB_ENV +# For the time being, let's assume the script will fail +echo "PROCEED=false" >> $GITHUB_ENV + +# Proceed only if the retrieved version is greater than the current one +if ! dpkg --compare-versions "$current_version" "lt" "$version" ; then + echo "::warning ::No new version available" + exit 0 +# Proceed only if a PR for this new version does not already exist +elif git ls-remote -q --exit-code --heads https://github.com/$GITHUB_REPOSITORY.git ci-auto-update-v$version ; then + echo "::warning ::A branch already exists for this update" + exit 0 +fi + +# Each release can hold multiple assets (e.g. binaries for different architectures, source code, etc.) +echo "${#assets[@]} available asset(s)" + +#================================================= +# UPDATE SOURCE FILES +#================================================= + +# Here we use the $assets variable to get the resources published in the upstream release. +# Here is an example for Grav, it has to be adapted in accordance with how the upstream releases look like. + +# Let's loop over the array of assets URLs +for asset_url in ${assets[@]}; do + + echo "Handling asset at $asset_url" + + # Assign the asset to a source file in conf/ directory + # Here we base the source file name upon a unique keyword in the assets url (admin vs. update) + # Leave $src empty to ignore the asset + case $asset_url in + *"build_api"*) + src="api" + ;; + *"build_front"*) + src="front" + ;; + *) + src="" + ;; + esac + + # If $src is not empty, let's process the asset + if [ ! -z "$src" ]; then + + # Create the temporary directory + tempdir="$(mktemp -d)" + + # Download sources and calculate checksum + filename=${asset_url##*/} + curl --silent -4 -L $asset_url -o "$tempdir/$filename" + checksum=$(sha256sum "$tempdir/$filename" | head -c 64) + + # Delete temporary directory + rm -rf $tempdir + + # Rewrite source file + cat < conf/$src.src +SOURCE_URL=$asset_url +SOURCE_SUM=$checksum +SOURCE_SUM_PRG=sha256sum +SOURCE_FORMAT=zip +SOURCE_IN_SUBDIR=true +SOURCE_FILENAME= +SOURCE_EXTRACT=true +EOT + echo "... conf/$src.src updated" + + else + echo "... asset ignored" + fi + +done + +#================================================= +# SPECIFIC UPDATE STEPS +#================================================= + +# Any action on the app's source code can be done. +# The GitHub Action workflow takes care of committing all changes after this script ends. + +#================================================= +# GENERIC FINALIZATION +#================================================= + +# Replace new version in manifest +echo "$(jq -s --indent 4 ".[] | .version = \"$version~ynh1\"" manifest.json)" > manifest.json + +# No need to update the README, yunohost-bot takes care of it + +# The Action will proceed only if the PROCEED environment variable is set to true +echo "PROCEED=true" >> $GITHUB_ENV +exit 0 diff --git a/.github/workflows/updater.yml b/.github/workflows/updater.yml new file mode 100644 index 0000000..fb72ba0 --- /dev/null +++ b/.github/workflows/updater.yml @@ -0,0 +1,49 @@ +# This workflow allows GitHub Actions to automagically update your app whenever a new upstream release is detected. +# You need to enable Actions in your repository settings, and fetch this Action from the YunoHost-Apps organization. +# This file should be enough by itself, but feel free to tune it to your needs. +# It calls updater.sh, which is where you should put the app-specific update steps. +name: Check for new upstream releases +on: + # Allow to manually trigger the workflow + workflow_dispatch: + # Run it every day at 6:00 UTC + schedule: + - cron: '0 6 * * *' +jobs: + updater: + runs-on: ubuntu-latest + steps: + - name: Fetch the source code + uses: actions/checkout@v2 + with: + token: ${{ secrets.GITHUB_TOKEN }} + - name: Run the updater script + id: run_updater + run: | + # Setting up Git user + git config --global user.name 'yunohost-bot' + git config --global user.email 'yunohost-bot@users.noreply.github.com' + # Run the updater script + /bin/bash .github/workflows/updater.sh + - name: Commit changes + id: commit + if: ${{ env.PROCEED == 'true' }} + run: | + git commit -am "Upgrade to v$VERSION" + - name: Create Pull Request + id: cpr + if: ${{ env.PROCEED == 'true' }} + uses: peter-evans/create-pull-request@v3 + with: + token: ${{ secrets.GITHUB_TOKEN }} + commit-message: Update to version ${{ env.VERSION }} + committer: 'yunohost-bot ' + author: 'yunohost-bot ' + signoff: false + base: testing + branch: ci-auto-update-v${{ env.VERSION }} + delete-branch: true + title: 'Upgrade to version ${{ env.VERSION }}' + body: | + Upgrade to v${{ env.VERSION }} + draft: false diff --git a/README.md b/README.md index 2e0a797..17f9c37 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ If you don't have YunoHost, please consult [the guide](https://yunohost.org/#/in Funkwhale is a community-driven project that lets you listen and share music and audio within a decentralized, open network. -**Shipped version:** 1.2.8~ynh1 +**Shipped version:** 1.2.8~ynh2 *(:warning: This is the `upgrade` branch. The [`master` branch](https://github.com/YunoHost-Apps/funkwhale_ynh/tree/master) used in the catalog is currently on version 1.2.8\~ynh1.)* **Demo:** https://demo.funkwhale.audio @@ -31,9 +31,8 @@ Funkwhale is a community-driven project that lets you listen and share music and * Installation requires a dedicated domain or subdomain. Installing in a subpath is not supported by the upstream project due to dependency requirements. * Admin - -The admin uses the login you provided at installation. The password is the same you use for YunoHost. -The admin interface is accessible at the address: `your.domain.fr/api/admin` + * The admin uses the login you provided at installation. The password is the same you use for YunoHost. + * The admin interface is accessible at the address: `your.domain.fr/api/admin` To add a collection of music files to a library in your YunoHost installation of Funkwhale, create a symlink to your collection titled "music" in `/home/yunohost.app/funkwhale/data` ```console diff --git a/README_fr.md b/README_fr.md index f983a60..616927e 100644 --- a/README_fr.md +++ b/README_fr.md @@ -17,7 +17,7 @@ Si vous n'avez pas YunoHost, regardez [ici](https://yunohost.org/#/install) pour Funkwhale est un projet communautaire qui vous permet d'écouter et de partager de la musique et de l'audio au sein d'un réseau ouvert et décentralisé. -**Version incluse :** 1.2.8~ynh1 +**Version incluse :** 1.2.8~ynh2 *(:warning: Il s'agit de la branche `upgrade`. La [branche `master`](https://github.com/YunoHost-Apps/funkwhale_ynh/tree/master) utilisée dans le catalogue est actuellement en 1.2.8\~ynh1.)* **Démo :** https://demo.funkwhale.audio @@ -31,10 +31,9 @@ Funkwhale est un projet communautaire qui vous permet d'écouter et de partager * L'installation nécessite un domaine ou un sous-domaine dédié. L'installation dans un chemin du domaine n'est pas prise en charge par le projet en amont en raison des exigences de dépendance. * Admin + * L'administrateur utilise le login que vous avez fourni lors de l'installation. Le mot de passe est le même que celui que vous utilisez pour YunoHost. + * L'interface d'administration est accessible à l'adresse : votre.domaine.fr/api/admin -L'administrateur utilise le login que vous avez fourni lors de l'installation. Le mot de passe est le même que celui que vous utilisez pour YunoHost. - -L'interface d'administration est accessible à l'adresse : votre.domaine.fr/api/admin Pour ajouter une collection de fichiers musicaux à une bibliothèque dans votre installation YunoHost de Funkwhale, créez un lien symbolique vers votre collection intitulée "music" dans `/home/yunohost.app/funkwhale/data/`. `foo@bar:~$sudo ln -s /your/music/collection /home/yunohost.app/funkwhale/data/music` Les fichiers peuvent ensuite être ajoutés à votre bibliothèque à partir de l'onglet *Envoi* dans une bibliothèque musicale sous la rubrique **Importer de la musique de votre serveur**. diff --git a/check_process b/check_process index cd58f26..536630a 100644 --- a/check_process +++ b/check_process @@ -1,8 +1,8 @@ ;; Test complet ; Manifest domain="domain.tld" - admin="john" is_public=1 + admin="john" ; Checks pkg_linter=1 setup_sub_dir=0 @@ -38,24 +38,3 @@ ;;; Options Email=cda@rootkey.co.uk Notification=all -;;; Upgrade options - ; commit=8172790fb461d16f09089593fdac380f0d499c83 - name=1.1~ynh1 - ; commit=fa9587f61e4bb4f9db8667b1c6701ede37ac8e91 - name=1.1.1~ynh1 - ; commit=74255c1c278562eb174fb13ce538d4754f01186c - name=1.1.2~ynh1 - ; commit=313335d5aa851a497fa92cd7ac264f989e1052d9 - name=1.1.4~ynh2 - ; commit=9fc8b84ba24260e28f791aa9c47688c1a1f085c2 - name=1.2.1~ynh1 - ; commit=192afe93f66bb08cc7d487db02dc4d187e5b29e2 - name=1.2.2~ynh2 - ; commit=1c1b64b8b04ee917a63580dce21d149182ee319d - name=1.2.3~ynh1 - ; commit=5961e7283e52963329e30ca22df4d5505adfc256 - name=1.2.4~ynh1 - ; commit=a070baf105a94ac6fefc280f0335b044db643ec8 - name=1.2.5~ynh1 - ; commit=557386e0c1306f78c43ccf2e5ec7b3b46a07ab56 - name=1.2.7~ynh1 diff --git a/conf/api.src b/conf/api.src index 15bafb7..4f46b19 100644 --- a/conf/api.src +++ b/conf/api.src @@ -3,5 +3,5 @@ SOURCE_SUM=70b2da23960531082ecd0db259fefe25cbbb4c7e88f5578739ce0bccc2b8cf69 SOURCE_SUM_PRG=sha256sum SOURCE_FORMAT=zip SOURCE_IN_SUBDIR=true -SOURCE_FILENAME=api_stable.zip +SOURCE_FILENAME= SOURCE_EXTRACT=true diff --git a/conf/env.prod b/conf/env.prod index e0cfde9..5b32746 100644 --- a/conf/env.prod +++ b/conf/env.prod @@ -58,9 +58,9 @@ LOGLEVEL=error # `python3 -c 'import urllib.parse; print(urllib.parse.quote_plus # ("noreply@youremail.host"))'` # (returns `noreply%40youremail.host`) -# EMAIL_CONFIG=smtp://user@:password@youremail.host:25 -# EMAIL_CONFIG=smtp+ssl://user@:password@youremail.host:465 -# EMAIL_CONFIG=smtp+tls://user@:password@youremail.host:587 +# EMAIL_CONFIG=smtp://user:password@youremail.host:25 +# EMAIL_CONFIG=smtp+ssl://user:password@youremail.host:465 +# EMAIL_CONFIG=smtp+tls://user:password@youremail.host:587 # Make e-mail verification mandatory before using the service # Doesn't apply to admins. @@ -192,3 +192,15 @@ NGINX_MAX_BODY_SIZE=100M # valid. The default value is 3600 (60 minutes). The maximum accepted value is 604800 (7 days) # AWS_QUERYSTRING_EXPIRE= + +# If you are using an S3-compatible object storage provider, and need to provide a default +# ACL for object uploads that is different from the default applied by boto3, you may +# override it here. Example: +# AWS_DEFAULT_ACL=public-read +# Available options can be found here: https://docs.aws.amazon.com/AmazonS3/latest/userguide/acl-overview.html#canned-acl + +# AWS_DEFAULT_ACL= + +# Funkwhale allows collecting errors using Sentry compatible APIs. If you want +# to help us improving Funkwhale, feel free to use our instance: +#FUNKWHALE_SENTRY_DSN=https://5840197379c64f65aad3c5c09274994d@am.funkwhale.audio/1 diff --git a/conf/front.src b/conf/front.src index 4f875b7..4692862 100644 --- a/conf/front.src +++ b/conf/front.src @@ -3,5 +3,5 @@ SOURCE_SUM=bd110dee284f5332aa00a3be53a61a65dbd8a20c10d4229287dec9f0bfd8c2f7 SOURCE_SUM_PRG=sha256sum SOURCE_FORMAT=zip SOURCE_IN_SUBDIR=true -SOURCE_FILENAME=front_stable.zip +SOURCE_FILENAME= SOURCE_EXTRACT=true diff --git a/doc/DISCLAIMER.md b/doc/DISCLAIMER.md index e5b11b6..8e16d23 100644 --- a/doc/DISCLAIMER.md +++ b/doc/DISCLAIMER.md @@ -1,9 +1,8 @@ * Installation requires a dedicated domain or subdomain. Installing in a subpath is not supported by the upstream project due to dependency requirements. * Admin - -The admin uses the login you provided at installation. The password is the same you use for YunoHost. -The admin interface is accessible at the address: `your.domain.fr/api/admin` + * The admin uses the login you provided at installation. The password is the same you use for YunoHost. + * The admin interface is accessible at the address: `your.domain.fr/api/admin` To add a collection of music files to a library in your YunoHost installation of Funkwhale, create a symlink to your collection titled "music" in `/home/yunohost.app/funkwhale/data` ```console diff --git a/doc/DISCLAIMER_fr.md b/doc/DISCLAIMER_fr.md index c8de072..30590da 100644 --- a/doc/DISCLAIMER_fr.md +++ b/doc/DISCLAIMER_fr.md @@ -1,10 +1,9 @@ * L'installation nécessite un domaine ou un sous-domaine dédié. L'installation dans un chemin du domaine n'est pas prise en charge par le projet en amont en raison des exigences de dépendance. * Admin + * L'administrateur utilise le login que vous avez fourni lors de l'installation. Le mot de passe est le même que celui que vous utilisez pour YunoHost. + * L'interface d'administration est accessible à l'adresse : votre.domaine.fr/api/admin -L'administrateur utilise le login que vous avez fourni lors de l'installation. Le mot de passe est le même que celui que vous utilisez pour YunoHost. - -L'interface d'administration est accessible à l'adresse : votre.domaine.fr/api/admin Pour ajouter une collection de fichiers musicaux à une bibliothèque dans votre installation YunoHost de Funkwhale, créez un lien symbolique vers votre collection intitulée "music" dans `/home/yunohost.app/funkwhale/data/`. `foo@bar:~$sudo ln -s /your/music/collection /home/yunohost.app/funkwhale/data/music` Les fichiers peuvent ensuite être ajoutés à votre bibliothèque à partir de l'onglet *Envoi* dans une bibliothèque musicale sous la rubrique **Importer de la musique de votre serveur**. diff --git a/manifest.json b/manifest.json index faef11a..32d32ff 100644 --- a/manifest.json +++ b/manifest.json @@ -6,7 +6,7 @@ "en": "Modern, convivial and free music server", "fr": "Serveur de musique moderne, convivial et gratuit" }, - "version": "1.2.8~ynh1", + "version": "1.2.8~ynh2", "url": "https://funkwhale.audio", "upstream": { "license": "AGPL-3.0-or-later", @@ -21,10 +21,12 @@ "name": "Ciarán Ainsworth", "email": "cda@rootkey.co.uk" }, - "previous_maintainers": [{ - "name": "Jean-Baptiste Holcroft", - "email": "jean-baptiste@holcroft.fr" - }], + "previous_maintainers": [ + { + "name": "Jean-Baptiste Holcroft", + "email": "jean-baptiste@holcroft.fr" + } + ], "requirements": { "yunohost": ">= 4.3.0" }, @@ -33,15 +35,11 @@ "nginx" ], "arguments": { - "install" : [ + "install": [ { "name": "domain", "type": "domain" }, - { - "name": "admin", - "type": "user" - }, { "name": "is_public", "type": "boolean", @@ -50,6 +48,10 @@ "fr": "Si cette case est cochée, Funkwhale sera accessible par Funkwhale for Android et par les utilisateurs n’ayant pas de compte YunoHost. Vous pourrez changer cela dans la webadmin." }, "default": true + }, + { + "name": "admin", + "type": "user" } ] } diff --git a/scripts/_common.sh b/scripts/_common.sh index dc8c79b..e031277 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -4,7 +4,7 @@ # COMMON VARIABLES #================================================= -# dependencies used by the app +# dependencies used by the app (must be on a single line) pkg_dependencies="curl python3-pip python3-venv git unzip libldap2-dev libsasl2-dev gettext-base zlib1g-dev libffi-dev libssl-dev \ build-essential ffmpeg libjpeg-dev libmagic-dev libpq-dev postgresql postgresql-contrib python3-dev make \ redis-server \ diff --git a/scripts/backup b/scripts/backup index 66dfe55..52b125d 100644 --- a/scripts/backup +++ b/scripts/backup @@ -15,7 +15,7 @@ source /usr/share/yunohost/helpers #================================================= ynh_clean_setup () { - ynh_clean_check_starting + true } # Exit if an error occurs during the execution of the script ynh_abort_if_errors diff --git a/scripts/change_url b/scripts/change_url index f1d5769..f2e5947 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -24,7 +24,7 @@ app=$YNH_APP_INSTANCE_NAME #================================================= # LOAD SETTINGS #================================================= -ynh_script_progression --message="Loading installation settings..." +ynh_script_progression --message="Loading installation settings..." --weight=1 # Needed for helper "ynh_add_nginx_config" final_path=$(ynh_app_setting_get --app=$app --key=final_path) @@ -34,7 +34,7 @@ redis_db=$(ynh_app_setting_get --app=$app --key=redis_db) port=$(ynh_app_setting_get --app=$app --key=port) db_name=$(ynh_app_setting_get --app=$app --key=db_name) db_user=$db_name -db_pwd=$(ynh_app_setting_get --app=$app --key=db_pwd) +db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd) datadir=$(ynh_app_setting_get --app=$app --key=datadir) redis_db=$(ynh_app_setting_get --app=$app --key=redis_db) key=$(ynh_app_setting_get --app=$app --key=key) @@ -42,7 +42,7 @@ key=$(ynh_app_setting_get --app=$app --key=key) #================================================= # BACKUP BEFORE CHANGE URL THEN ACTIVE TRAP #================================================= -ynh_script_progression --message="Backing up the app before changing its URL (may take a while)..." +ynh_script_progression --message="Backing up the app before changing its URL (may take a while)..." --weight=1 # Backup the current version of the app ynh_backup_before_upgrade @@ -77,7 +77,7 @@ fi #================================================= # STOP SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Stopping a systemd service..." +ynh_script_progression --message="Stopping a systemd service..." --weight=1 ynh_systemd_action --service_name="$app-beat" --action=stop --log_path="/var/log/$app/$app.log" ynh_systemd_action --service_name="$app-server" --action=stop --log_path="/var/log/$app/$app.log" @@ -86,7 +86,7 @@ ynh_systemd_action --service_name="$app-worker" --action=stop --log_path="/var/l #================================================= # MODIFY URL IN NGINX CONF #================================================= -ynh_script_progression --message="Updating NGINX web server configuration..." +ynh_script_progression --message="Updating NGINX web server configuration..." --weight=1 nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf @@ -115,7 +115,7 @@ fi #================================================= # MODIFY THE CONFIG FILE #================================================= -ynh_script_progression --message="Modifying a config file..." +ynh_script_progression --message="Modifying a config file..." --weight=1 domain=$new_domain ynh_add_config --template="../conf/env.prod" --destination="$final_path/config/.env" @@ -130,7 +130,7 @@ python3 $final_path/api/manage.py fix_federation_ids https://$old_domain https:/ #================================================= # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting a systemd service..." +ynh_script_progression --message="Starting a systemd service..." --weight=1 ynh_systemd_action --service_name="$app-beat" --action="start" --log_path="/var/log/$app/$app.log" ynh_systemd_action --service_name="$app-server" --action="start" --log_path="/var/log/$app/$app.log" @@ -139,7 +139,7 @@ ynh_systemd_action --service_name="$app-worker" --action="start" --log_path="/va #================================================= # SETUP FAIL2BAN #================================================= -ynh_script_progression --message="Configuring Fail2Ban..." +ynh_script_progression --message="Configuring Fail2Ban..." --weight=1 # Create a dedicated Fail2Ban config ynh_add_fail2ban_config --logpath="/var/log/nginx/$new_domain-access.log" --failregex=".* \"POST /api/v1/token/ HTTP/1.1\" 400 68.*$" --max_retry=5 @@ -147,7 +147,7 @@ ynh_add_fail2ban_config --logpath="/var/log/nginx/$new_domain-access.log" --fail #================================================= # RELOAD NGINX #================================================= -ynh_script_progression --message="Reloading NGINX web server..." +ynh_script_progression --message="Reloading NGINX web server..." --weight=1 ynh_systemd_action --service_name=nginx --action=reload @@ -155,4 +155,4 @@ ynh_systemd_action --service_name=nginx --action=reload # END OF SCRIPT #================================================= -ynh_script_progression --message="Change of URL completed for $app" +ynh_script_progression --message="Change of URL completed for $app" --last diff --git a/scripts/install b/scripts/install index 281a190..65c38df 100644 --- a/scripts/install +++ b/scripts/install @@ -14,7 +14,7 @@ source /usr/share/yunohost/helpers #================================================= ynh_clean_setup () { - ynh_clean_check_starting + true } # Exit if an error occurs during the execution of the script ynh_abort_if_errors @@ -25,17 +25,17 @@ ynh_abort_if_errors domain=$YNH_APP_ARG_DOMAIN path_url="/" -admin=$YNH_APP_ARG_ADMIN is_public=$YNH_APP_ARG_IS_PUBLIC - -admin_mail=$(ynh_user_get_info --username="$admin" --key="mail") +admin=$YNH_APP_ARG_ADMIN app=$YNH_APP_INSTANCE_NAME +admin_mail=$(ynh_user_get_info --username="$admin" --key="mail") + #================================================= # CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS #================================================= -ynh_script_progression --message="Validating installation parameters..." +ynh_script_progression --message="Validating installation parameters..." --weight=1 final_path=/var/www/$app test ! -e "$final_path" || ynh_die --message="This path already contains a folder" @@ -48,7 +48,7 @@ ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url #================================================= # STORE SETTINGS FROM MANIFEST #================================================= -ynh_script_progression --message="Storing installation settings..." +ynh_script_progression --message="Storing installation settings..." --weight=1 ynh_app_setting_set --app=$app --key=domain --value=$domain ynh_app_setting_set --app=$app --key=path --value=$path_url @@ -59,46 +59,43 @@ ynh_app_setting_set --app=$app --key=admin --value=$admin #================================================= # FIND AND OPEN A PORT #================================================= -ynh_script_progression --message="Finding an available port..." +ynh_script_progression --message="Finding an available port..." --weight=1 # Find an available port -port=$(ynh_find_port --port=5000) +port=$(ynh_find_port --port=8095) ynh_app_setting_set --app=$app --key=port --value=$port #================================================= # INSTALL DEPENDENCIES #================================================= -ynh_script_progression --message="Installing dependencies..." +ynh_script_progression --message="Installing dependencies..." --weight=1 ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies #================================================= # CREATE DEDICATED USER #================================================= -ynh_script_progression --message="Configuring system user..." +ynh_script_progression --message="Configuring system user..." --weight=1 # Create a system user -ynh_system_user_create --username=$app --home_dir=$final_path +ynh_system_user_create --username=$app --home_dir="$final_path" #================================================= # CREATE A POSTGRESQL DATABASE #================================================= -ynh_script_progression --message="Creating a PostgreSQL database..." +ynh_script_progression --message="Creating a PostgreSQL database..." --weight=1 ynh_psql_test_if_first_run db_name=$(ynh_sanitize_dbid --db_name=$app) db_user=$db_name -db_pwd=$(ynh_string_random) ynh_app_setting_set --app=$app --key=db_name --value=$db_name -ynh_app_setting_set --app=$app --key=db_pwd --value=$db_pwd - -# Initialize database and store postgres password for upgrade -ynh_psql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd +ynh_psql_setup_db --db_user=$db_user --db_name=$db_name +db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd) #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= -ynh_script_progression --message="Setting up source files..." +ynh_script_progression --message="Setting up source files..." --weight=1 ynh_app_setting_set --app=$app --key=final_path --value=$final_path # Download, check integrity, uncompress and patch the source from app.src @@ -114,7 +111,7 @@ chown -R $app:www-data "$final_path" #================================================= # NGINX CONFIGURATION #================================================= -ynh_script_progression --message="Configuring NGINX web server..." +ynh_script_progression --message="Configuring NGINX web server..." --weight=1 # Create a dedicated NGINX config ynh_add_nginx_config @@ -124,7 +121,7 @@ ynh_add_nginx_config #================================================= # CREATE DATA DIRECTORY #================================================= -ynh_script_progression --message="Creating a data directory..." +ynh_script_progression --message="Creating a data directory..." --weight=1 ynh_app_setting_set --app=$app --key=datadir --value=$datadir @@ -138,7 +135,7 @@ chown -R $app:www-data "$datadir" #================================================= # ADD A CONFIGURATION #================================================= -ynh_script_progression --message="Adding a configuration file..." +ynh_script_progression --message="Adding a configuration file..." --weight=1 key=$(ynh_string_random --length=45 | base64) redis_db=$(ynh_redis_get_free_db) @@ -154,7 +151,7 @@ chown $app:$app "$final_path/config/.env" #================================================= # SETUP SYSTEMD #================================================= -ynh_script_progression --message="Configuring a systemd service..." +ynh_script_progression --message="Configuring a systemd service..." --weight=1 ynh_add_config --template="../conf/funkwhale.target" --destination="/etc/systemd/system/$app.target" @@ -166,7 +163,7 @@ ynh_add_systemd_config --service="${app}-beat" --template="funkwhale-beat.serv #================================================= # INSTALL PYTHON DEPENDENCIES #================================================= -ynh_script_progression --message="Installing Python dependencies..." +ynh_script_progression --message="Installing Python dependencies..." --weight=1 pushd $final_path python3 -m venv $final_path/virtualenv @@ -182,7 +179,7 @@ popd #================================================= # BUILDING FUNKWHALE #================================================= -ynh_script_progression --message="Building funkwhale..." +ynh_script_progression --message="Building funkwhale..." --weight=1 pushd $final_path source $final_path/virtualenv/bin/activate @@ -204,7 +201,7 @@ chown -R $app:www-data "$final_path" #================================================= # INTEGRATE SERVICE IN YUNOHOST #================================================= -ynh_script_progression --message="Integrating service in YunoHost..." +ynh_script_progression --message="Integrating service in YunoHost..." --weight=1 yunohost service add "${app}-beat" yunohost service add "${app}-server" @@ -213,7 +210,7 @@ yunohost service add "${app}-worker" #================================================= # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting a systemd service..." +ynh_script_progression --message="Starting a systemd service..." --weight=1 # Start a systemd service ynh_systemd_action --service_name="${app}-beat" --action="start" --log_path="systemd" --line_match="Started" @@ -223,7 +220,7 @@ ynh_systemd_action --service_name="${app}-worker" --action="start" --log_path="s #================================================= # SETUP FAIL2BAN #================================================= -ynh_script_progression --message="Configuring Fail2Ban..." +ynh_script_progression --message="Configuring Fail2Ban..." --weight=1 # Create a dedicated Fail2Ban config ynh_add_fail2ban_config --logpath="/var/log/nginx/${domain}-access.log" --failregex=".* \"POST /api/v1/token/ HTTP/1.1\" 400 68.*$" --max_retry=5 @@ -231,7 +228,7 @@ ynh_add_fail2ban_config --logpath="/var/log/nginx/${domain}-access.log" --failre #================================================= # SETUP SSOWAT #================================================= -ynh_script_progression --message="Configuring permissions..." +ynh_script_progression --message="Configuring permissions..." --weight=1 # Make app public if necessary if [ $is_public -eq 1 ] @@ -244,7 +241,7 @@ fi #================================================= # RELOAD NGINX #================================================= -ynh_script_progression --message="Reloading NGINX web server..." +ynh_script_progression --message="Reloading NGINX web server..." --weight=1 ynh_systemd_action --service_name=nginx --action=reload @@ -252,4 +249,4 @@ ynh_systemd_action --service_name=nginx --action=reload # END OF SCRIPT #================================================= -ynh_script_progression --message="Installation of $app completed" +ynh_script_progression --message="Installation of $app completed" --last diff --git a/scripts/remove b/scripts/remove index 071eac5..1271cb7 100644 --- a/scripts/remove +++ b/scripts/remove @@ -12,7 +12,7 @@ source /usr/share/yunohost/helpers #================================================= # LOAD SETTINGS #================================================= -ynh_script_progression --message="Loading installation settings..." +ynh_script_progression --message="Loading installation settings..." --weight=1 app=$YNH_APP_INSTANCE_NAME @@ -52,7 +52,7 @@ fi #================================================= # STOP AND REMOVE SERVICE #================================================= -ynh_script_progression --message="Stopping and removing the systemd service..." +ynh_script_progression --message="Stopping and removing the systemd service..." --weight=1 ynh_systemd_action --service_name="${app}-beat" --action="stop" --log_path="systemd" --line_match="Stopped $app" ynh_systemd_action --service_name="${app}-server" --action="stop" --log_path="systemd" --line_match="Stopped $app" @@ -68,7 +68,7 @@ ynh_secure_remove --file="/etc/systemd/system/$app.target" #================================================= # REMOVE THE POSTGRESQL DATABASE #================================================= -ynh_script_progression --message="Removing the PostgreSQL database..." +ynh_script_progression --message="Removing the PostgreSQL database..." --weight=1 # Remove a database if it exists, along with the associated user ynh_psql_remove_db --db_user=$db_user --db_name=$db_name @@ -76,7 +76,7 @@ ynh_psql_remove_db --db_user=$db_user --db_name=$db_name #================================================= # REMOVE APP MAIN DIR #================================================= -ynh_script_progression --message="Removing app main directory..." +ynh_script_progression --message="Removing app main directory..." --weight=1 # Remove the app directory securely ynh_secure_remove --file="$final_path" @@ -88,14 +88,14 @@ ynh_secure_remove --file="$final_path" # Remove the data directory if --purge option is used if [ "${YNH_APP_PURGE:-0}" -eq 1 ] then - ynh_script_progression --message="Removing app data directory..." + ynh_script_progression --message="Removing app data directory..." --weight=1 ynh_secure_remove --file="$datadir" fi #================================================= # REMOVE NGINX CONFIGURATION #================================================= -ynh_script_progression --message="Removing NGINX web server configuration..." +ynh_script_progression --message="Removing NGINX web server configuration..." --weight=1 # Remove the dedicated NGINX config ynh_remove_nginx_config @@ -103,7 +103,7 @@ ynh_remove_nginx_config #================================================= # REMOVE DEPENDENCIES #================================================= -ynh_script_progression --message="Removing dependencies..." +ynh_script_progression --message="Removing dependencies..." --weight=1 # Remove metapackage and its dependencies ynh_remove_app_dependencies @@ -111,7 +111,7 @@ ynh_remove_app_dependencies #================================================= # REMOVE FAIL2BAN CONFIGURATION #================================================= -ynh_script_progression --message="Removing Fail2Ban configuration..." +ynh_script_progression --message="Removing Fail2Ban configuration..." --weight=1 # Remove the dedicated Fail2Ban config ynh_remove_fail2ban_config @@ -121,7 +121,7 @@ ynh_remove_fail2ban_config #================================================= # REMOVE THE REDIS DATABASE #================================================= -ynh_script_progression --message="Removing the Redis database..." +ynh_script_progression --message="Removing the Redis database..." --weight=1 # Remove a database if it exists, along with the associated user ynh_redis_remove_db $redis_db @@ -131,7 +131,7 @@ ynh_redis_remove_db $redis_db #================================================= # REMOVE DEDICATED USER #================================================= -ynh_script_progression --message="Removing the dedicated system user..." +ynh_script_progression --message="Removing the dedicated system user..." --weight=1 # Delete a system user ynh_system_user_delete --username=$app @@ -140,4 +140,4 @@ ynh_system_user_delete --username=$app # END OF SCRIPT #================================================= -ynh_script_progression --message="Removal of $app completed" +ynh_script_progression --message="Removal of $app completed" --last diff --git a/scripts/restore b/scripts/restore index 658b02f..848bdd7 100644 --- a/scripts/restore +++ b/scripts/restore @@ -15,7 +15,7 @@ source /usr/share/yunohost/helpers #================================================= ynh_clean_setup () { - ynh_clean_check_starting + true } # Exit if an error occurs during the execution of the script ynh_abort_if_errors @@ -23,7 +23,7 @@ ynh_abort_if_errors #================================================= # LOAD SETTINGS #================================================= -ynh_script_progression --message="Loading installation settings..." +ynh_script_progression --message="Loading installation settings..." --weight=1 app=$YNH_APP_INSTANCE_NAME @@ -37,32 +37,25 @@ datadir=$(ynh_app_setting_get --app=$app --key=datadir) #================================================= # CHECK IF THE APP CAN BE RESTORED #================================================= -ynh_script_progression --message="Validating restoration parameters..." +ynh_script_progression --message="Validating restoration parameters..." --weight=1 test ! -d $final_path \ || ynh_die --message="There is already a directory: $final_path " #================================================= # STANDARD RESTORATION STEPS -#================================================= -# RESTORE THE NGINX CONFIGURATION -#================================================= -ynh_script_progression --message="Restoring the NGINX web server configuration..." - -ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" - #================================================= # RECREATE THE DEDICATED USER #================================================= -ynh_script_progression --message="Recreating the dedicated system user..." +ynh_script_progression --message="Recreating the dedicated system user..." --weight=1 # Create the dedicated user (if not existing) -ynh_system_user_create --username=$app --home_dir=$final_path +ynh_system_user_create --username=$app --home_dir="$final_path" #================================================= # RESTORE THE APP MAIN DIR #================================================= -ynh_script_progression --message="Restoring the app main directory..." +ynh_script_progression --message="Restoring the app main directory..." --weight=1 ynh_restore_file --origin_path="$final_path" @@ -73,7 +66,7 @@ chown -R $app:www-data "$final_path" #================================================= # RESTORE THE DATA DIRECTORY #================================================= -ynh_script_progression --message="Restoring the data directory..." +ynh_script_progression --message="Restoring the data directory..." --weight=1 ynh_restore_file --origin_path="$datadir" --not_mandatory @@ -85,28 +78,37 @@ chmod 750 "$datadir" chmod -R o-rwx "$datadir" chown -R $app:www-data "$datadir" +#================================================= +# SPECIFIC RESTORATION #================================================= # REINSTALL DEPENDENCIES #================================================= -ynh_script_progression --message="Reinstalling dependencies..." +ynh_script_progression --message="Reinstalling dependencies..." --weight=1 # Define and install dependencies ynh_install_app_dependencies $pkg_dependencies +#================================================= +# RESTORE THE NGINX CONFIGURATION +#================================================= +ynh_script_progression --message="Restoring the NGINX web server configuration..." --weight=1 + +ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" + #================================================= # RESTORE THE POSTGRESQL DATABASE #================================================= -ynh_script_progression --message="Restoring the PostgreSQL database..." +ynh_script_progression --message="Restoring the PostgreSQL database..." --weight=1 -db_pwd=$(ynh_app_setting_get --app=$app --key=db_pwd) ynh_psql_test_if_first_run +db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd) ynh_psql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd ynh_psql_execute_file_as_root --file="./db.sql" --database=$db_name #================================================= # RESTORE SYSTEMD #================================================= -ynh_script_progression --message="Restoring the systemd configuration..." +ynh_script_progression --message="Restoring the systemd configuration..." --weight=1 ynh_restore_file --origin_path="/etc/systemd/system/${app}-beat.service" ynh_restore_file --origin_path="/etc/systemd/system/${app}-server.service" @@ -120,7 +122,7 @@ systemctl enable "${app}-worker.service" --quiet #================================================= # INTEGRATE SERVICE IN YUNOHOST #================================================= -ynh_script_progression --message="Integrating service in YunoHost..." +ynh_script_progression --message="Integrating service in YunoHost..." --weight=1 yunohost service add "${app}-beat" yunohost service add "${app}-server" @@ -129,7 +131,7 @@ yunohost service add "${app}-worker" #================================================= # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting a systemd service..." +ynh_script_progression --message="Starting a systemd service..." --weight=1 ynh_systemd_action --service_name="${app}-beat" --action="start" --log_path="systemd" --line_match="Started" ynh_systemd_action --service_name="${app}-server" --action="start" --log_path="systemd" --line_match="Application startup complete" @@ -140,7 +142,7 @@ ynh_systemd_action --service_name="${app}-worker" --action="start" --log_path="s #================================================= # RELOAD NGINX #================================================= -ynh_script_progression --message="Reloading NGINX web server..." +ynh_script_progression --message="Reloading NGINX web server..." --weight=1 ynh_systemd_action --service_name=nginx --action=reload @@ -148,4 +150,4 @@ ynh_systemd_action --service_name=nginx --action=reload # END OF SCRIPT #================================================= -ynh_script_progression --message="Restoration completed for $app" +ynh_script_progression --message="Restoration completed for $app" --last diff --git a/scripts/upgrade b/scripts/upgrade index c424e35..9763ca9 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -12,7 +12,7 @@ source /usr/share/yunohost/helpers #================================================= # LOAD SETTINGS #================================================= -ynh_script_progression --message="Loading installation settings..." +ynh_script_progression --message="Loading installation settings..." --weight=1 app=$YNH_APP_INSTANCE_NAME @@ -30,20 +30,19 @@ key=$(ynh_app_setting_get --app=$app --key=key) #================================================= # CHECK VERSION #================================================= -ynh_script_progression --message="Checking version..." +ynh_script_progression --message="Checking version..." --weight=1 upgrade_type=$(ynh_check_app_version_changed) #================================================= # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP #================================================= -ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." +ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=1 # Backup the current version of the app ynh_backup_before_upgrade ynh_clean_setup () { # Restore it if the upgrade fails - ynh_clean_check_starting ynh_restore_upgradebackup } # Exit if an error occurs during the execution of the script @@ -54,7 +53,7 @@ ynh_abort_if_errors #================================================= # STOP SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Stopping a systemd service..." +ynh_script_progression --message="Stopping a systemd service..." --weight=1 ynh_systemd_action --action="stop" --service_name="${app}-beat" --log_path="systemd" --line_match="Stopped" ynh_systemd_action --action="stop" --service_name="${app}-server" --log_path="systemd" --line_match="Stopped" @@ -63,7 +62,7 @@ ynh_systemd_action --action="stop" --service_name="${app}-worker" --log_path="sy #================================================= # ENSURE DOWNWARD COMPATIBILITY #================================================= -ynh_script_progression --message="Ensuring downward compatibility..." +ynh_script_progression --message="Ensuring downward compatibility..." --weight=1 # If redis_db doesn't exist, create it if [ -z "$redis_db" ]; then @@ -94,7 +93,7 @@ if [ -z "$datadir" ]; then yunohost backup create --apps $app datadir="/home/yunohost.app/${app}/data" - ynh_script_progression --message="Moving datas to $datadir..." + ynh_script_progression --message="Moving datas to $datadir..." --weight=1 mkdir -p $datadir mkdir -p $datadir/{static,media,music} @@ -144,10 +143,10 @@ fi #================================================= # CREATE DEDICATED USER #================================================= -ynh_script_progression --message="Making sure dedicated system user exists..." +ynh_script_progression --message="Making sure dedicated system user exists..." --weight=1 # Create a dedicated user (if not existing) -ynh_system_user_create --username=$app --home_dir=$final_path +ynh_system_user_create --username=$app --home_dir="$final_path" #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE @@ -155,7 +154,7 @@ ynh_system_user_create --username=$app --home_dir=$final_path if [ "$upgrade_type" == "UPGRADE_APP" ] then - ynh_script_progression --message="Upgrading source files..." + ynh_script_progression --message="Upgrading source files..." --weight=1 ynh_secure_remove --file="$final_path/api" ynh_secure_remove --file="$final_path/front" @@ -168,27 +167,27 @@ chmod 750 "$final_path" chmod -R o-rwx "$final_path" chown -R $app:www-data "$final_path" +#================================================= +# UPGRADE DEPENDENCIES +#================================================= +ynh_script_progression --message="Upgrading dependencies..." --weight=1 + +ynh_install_app_dependencies $pkg_dependencies + #================================================= # NGINX CONFIGURATION #================================================= -ynh_script_progression --message="Upgrading NGINX web server configuration..." +ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=1 # Create a dedicated NGINX config ynh_add_nginx_config -#================================================= -# UPGRADE DEPENDENCIES -#================================================= -ynh_script_progression --message="Upgrading dependencies..." - -ynh_install_app_dependencies $pkg_dependencies - #================================================= # SPECIFIC UPGRADE #================================================= # INSTALL PYTHON DEPENDENCIES #================================================= -ynh_script_progression --message="Installing Python dependencies..." +ynh_script_progression --message="Installing Python dependencies..." --weight=1 pushd $final_path ynh_secure_remove --file="$final_path/virtualenv" @@ -205,7 +204,7 @@ popd #================================================= # UPDATE A CONFIG FILE #================================================= -ynh_script_progression --message="Updating a configuration file..." +ynh_script_progression --message="Updating a configuration file..." --weight=1 ynh_add_config --template="../conf/env.prod" --destination="$final_path/config/.env" @@ -215,35 +214,17 @@ chown $app:$app "$final_path/config/.env" #================================================= # UPGRADE FUNKWHALE #================================================= -ynh_script_progression --message="Upgrading Funkwhale..." +ynh_script_progression --message="Upgrading Funkwhale..." --weight=1 pushd $final_path source $final_path/virtualenv/bin/activate + echo "yes" | ynh_exec_warn_less python api/manage.py collectstatic --clear --noinput + # needed for enabling the 'unaccent' extension ynh_psql_execute_as_root --sql="ALTER USER $db_user WITH SUPERUSER;" --database="$db_name" ynh_exec_warn_less python api/manage.py migrate ynh_psql_execute_as_root --sql="ALTER USER $db_user WITH NOSUPERUSER;" --database="$db_name" - - echo "yes" | ynh_exec_warn_less python api/manage.py collectstatic --clear --noinput - - # https://code.eliotberriot.com/funkwhale/funkwhale/tags/0.16 # users-now-have-an-activitypub-actor-manual-action-required - # python api/manage.py script create_actors --no-input - # https://code.eliotberriot.com/funkwhale/funkwhale/tags/0.16 #image-thumbnails-manual-action-required - # python api/manage.py script create_image_variations --no-input - - # https://docs.funkwhale.audio/upgrading/0.17.html#upgrade-instructions - # python api/manage.py script migrate_to_user_libraries --no-input - - # Delete pre 0.17 federated tracks [manual action suggested] - # https://dev.funkwhale.audio/funkwhale/funkwhale/tags/0.18 - # python api/manage.py script delete_pre_017_federated_uploads --no-input - - # Delete the original thumbnails and generate new ones for - # higher quality images - # https://docs.funkwhale.audio/changelog.html#increased-quality-of-jpeg-thumbnails-manual-action-required - ynh_secure_remove --file="$final_path/media/__sized__" - ynh_exec_warn_less python api/manage.py fw media generate-thumbnails popd chmod 750 "$final_path" @@ -253,7 +234,7 @@ chown -R $app:www-data "$final_path" #================================================= # SETUP SYSTEMD #================================================= -ynh_script_progression --message="Upgrading systemd configuration..." +ynh_script_progression --message="Upgrading systemd configuration..." --weight=1 ynh_add_config --template="../conf/funkwhale.target" --destination="/etc/systemd/system/$app.target" @@ -267,7 +248,7 @@ ynh_add_systemd_config --service="${app}-beat" --template="funkwhale-beat.serv #================================================= # INTEGRATE SERVICE IN YUNOHOST #================================================= -ynh_script_progression --message="Integrating service in YunoHost..." +ynh_script_progression --message="Integrating service in YunoHost..." --weight=1 yunohost service add "${app}-beat" yunohost service add "${app}-server" @@ -276,7 +257,7 @@ yunohost service add "${app}-worker" #================================================= # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting a systemd service..." +ynh_script_progression --message="Starting a systemd service..." --weight=1 # Start a systemd service ynh_systemd_action --service_name="${app}-beat" --action="start" --log_path="systemd" --line_match="Started" @@ -286,7 +267,7 @@ ynh_systemd_action --service_name="${app}-worker" --action="start" --log_path="s #================================================= # UPGRADE FAIL2BAN #================================================= -ynh_script_progression --message="Reconfiguring Fail2Ban..." +ynh_script_progression --message="Reconfiguring Fail2Ban..." --weight=1 # Create a dedicated Fail2Ban config ynh_add_fail2ban_config --logpath="/var/log/nginx/$domain-access.log" --failregex=".* \"POST /api/v1/token/ HTTP/1.1\" 400 68.*$" --max_retry=5 @@ -294,7 +275,7 @@ ynh_add_fail2ban_config --logpath="/var/log/nginx/$domain-access.log" --failrege #================================================= # RELOAD NGINX #================================================= -ynh_script_progression --message="Reloading NGINX web server..." +ynh_script_progression --message="Reloading NGINX web server..." --weight=1 ynh_systemd_action --service_name=nginx --action=reload @@ -302,4 +283,4 @@ ynh_systemd_action --service_name=nginx --action=reload # END OF SCRIPT #================================================= -ynh_script_progression --message="Upgrade of $app completed" +ynh_script_progression --message="Upgrade of $app completed" --last