From 8656afe8ae24a2e1f8662f29069e34d8f5aa5940 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Wed, 13 Jul 2022 00:48:56 +0200 Subject: [PATCH 1/3] Apply example_ynh --- check_process | 6 +++--- scripts/_common.sh | 9 +++++---- scripts/install | 7 ++++--- scripts/restore | 18 +++++++++--------- scripts/upgrade | 31 +++++++++++++++++++------------ 5 files changed, 40 insertions(+), 31 deletions(-) diff --git a/check_process b/check_process index 12dcbbb..f566996 100644 --- a/check_process +++ b/check_process @@ -2,9 +2,9 @@ ; Manifest domain="domain.tld" path="/path" - admin="john" - password="randompass" is_public=1 + admin="john" + password="1Strong-Password" github_account="myaccount" github_token="myoauthtoken" ; Checks @@ -16,7 +16,7 @@ setup_public=1 upgrade=1 # 4.9~ynh1 - upgrade=1 from_commit=7fec5a47a80e00458a31f1270c4ace822961e7bf + upgrade=1 from_commit=7fec5a47a80e00458a31f1270c4ace822961e7bf backup_restore=1 multi_instance=1 port_already_use=0 diff --git a/scripts/_common.sh b/scripts/_common.sh index a020752..d3179a7 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -17,9 +17,6 @@ borgbackup_dependencies="libacl1-dev libacl1 libssl-dev liblz4-dev libzstd-dev l pkg_dependencies="$weblate_dependencies $borgbackup_dependencies" -# Weblate's version for PIP and settings file -weblate_version="4.13" - debian_maj_version=$(sed 's/\..*//' /etc/debian_version) if [ "$debian_maj_version" -eq 9 ] ; then @@ -30,6 +27,10 @@ elif [ "$debian_maj_version" -eq 11 ] ; then weblate_pypath="python3.9" fi +#================================================= +# PERSONAL HELPERS +#================================================= + #================================================= # EXPERIMENTAL HELPERS #================================================= @@ -141,5 +142,5 @@ ynh_redis_remove_db() { } #================================================= -# EXPERIMENTAL HELPERS +# FUTURE OFFICIAL HELPERS #================================================= diff --git a/scripts/install b/scripts/install index 909b8b5..0cbeb4c 100755 --- a/scripts/install +++ b/scripts/install @@ -25,8 +25,8 @@ ynh_abort_if_errors domain=$YNH_APP_ARG_DOMAIN path_url=$YNH_APP_ARG_PATH -admin=$YNH_APP_ARG_ADMIN is_public=$YNH_APP_ARG_IS_PUBLIC +admin=$YNH_APP_ARG_ADMIN password=$YNH_APP_ARG_PASSWORD github_account=$YNH_APP_ARG_GITHUB_ACCOUNT github_token=$YNH_APP_ARG_GITHUB_TOKEN @@ -83,7 +83,6 @@ ynh_script_progression --message="Creating a PostgreSQL database..." --weight=2 db_name=$(ynh_sanitize_dbid --db_name=$app) db_user=$db_name ynh_app_setting_set --app=$app --key=db_name --value=$db_name - ynh_psql_test_if_first_run ynh_psql_setup_db --db_user=$db_user --db_name=$db_name ynh_psql_execute_as_root --sql="CREATE EXTENSION IF NOT EXISTS pg_trgm;" --database=$db_name @@ -145,7 +144,7 @@ chown -R $app: "$final_path" # Read the "Note" section in https://docs.weblate.org/en/weblate-4.11/admin/install/venv-debian.html#python-modules sudo --user=$app $final_path/venv/bin/pip install --force-reinstall --no-binary :all: cffi # Still needed with latest version of weblate? - sudo --user=$app BORG_OPENSSL_PREFIX=/usr/lib/x86_64-linux-gnu/ $final_path/venv/bin/pip install Weblate=="$weblate_version" + sudo --user=$app BORG_OPENSSL_PREFIX=/usr/lib/x86_64-linux-gnu/ $final_path/venv/bin/pip install Weblate=="$(ynh_app_upstream_version)" sudo --user=$app $final_path/venv/bin/pip install psycopg2-binary ruamel.yaml aeidon phply #pip install pytz python-bidi PyYaML Babel pyuca pylibravatar py3dns psycopg2-binary phply django-redis hiredis aeidon ruamel.yaml # specific to YunoHost package: @@ -245,6 +244,8 @@ ynh_script_progression --message="Configuring permissions..." --weight=1 # Make app public if necessary if [ $is_public -eq 1 ] then + # Everyone can access the app. + # The "main" permission is automatically created before the install script. ynh_permission_update --permission="main" --add="visitors" fi diff --git a/scripts/restore b/scripts/restore index cc91f76..fb55dac 100755 --- a/scripts/restore +++ b/scripts/restore @@ -23,7 +23,7 @@ ynh_abort_if_errors #================================================= # LOAD SETTINGS #================================================= -ynh_script_progression --message="Loading settings..." --weight=1 +ynh_script_progression --message="Loading installation settings..." --weight=1 app=$YNH_APP_INSTANCE_NAME @@ -43,13 +43,6 @@ test ! -d $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 #================================================= @@ -85,7 +78,14 @@ ynh_script_progression --message="Reinstalling dependencies..." --weight=40 ynh_exec_warn_less ynh_install_app_dependencies "$pkg_dependencies" #================================================= -# RESTORE THE PostgreSQL DATABASE +# 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" + +#================================================= +# RESTORE THE POSTGRESQL DATABASE #================================================= ynh_script_progression --message="Restoring the PostgreSQL database..." --weight=5 diff --git a/scripts/upgrade b/scripts/upgrade index 11ad446..c1620c9 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -23,13 +23,20 @@ final_path=$(ynh_app_setting_get --app=$app --key=final_path) 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) - -admin_mail=$(ynh_user_get_info "$admin" mail) github_account=$(ynh_app_setting_get --app=$app --key=github_account) github_token=$(ynh_app_setting_get --app=$app --key=github_token) -key=$(ynh_string_random 50) redis_db=$(ynh_app_setting_get --app=$app --key=redis_db) +admin_mail=$(ynh_user_get_info --username="$admin" --key=mail) +key=$(ynh_string_random --length=50) + +#================================================= +# CHECK VERSION +#================================================= +ynh_script_progression --message="Checking version..." + +upgrade_type=$(ynh_check_app_version_changed) + #================================================= # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP #================================================= @@ -89,6 +96,13 @@ ynh_script_progression --message="Making sure dedicated system user exists..." - # Create a dedicated user (if not existing) ynh_system_user_create --username=$app --home_dir="$final_path" --use_shell +#================================================= +# UPGRADE DEPENDENCIES +#================================================= +ynh_script_progression --message="Upgrading dependencies..." --weight=5 + +ynh_exec_warn_less ynh_install_app_dependencies "$pkg_dependencies" + #================================================= # NGINX CONFIGURATION #================================================= @@ -97,13 +111,6 @@ ynh_script_progression --message="Upgrading NGINX web server configuration..." - # Create a dedicated NGINX config ynh_add_nginx_config -#================================================= -# UPGRADE DEPENDENCIES -#================================================= -ynh_script_progression --message="Upgrading dependencies..." --weight=5 - -ynh_exec_warn_less ynh_install_app_dependencies "$pkg_dependencies" - #================================================= # SPECIFIC UPGRADE #================================================= @@ -210,7 +217,7 @@ upgrade() { # Check the configuration # This may fail in some cases with errors, etc., but the app works and the user can fix issues later. - if [ "$new_version" == "$weblate_version" ]; then + if [ "$new_version" == "$(ynh_app_upstream_version)" ]; then sudo --user=$app $final_path/venv/bin/weblate check --deploy || true fi ) @@ -238,7 +245,7 @@ then upgrade "4.1.1" "../conf/settings.4.1.1.py" fi -upgrade $weblate_version "../conf/settings.py" +upgrade $(ynh_app_upstream_version) "../conf/settings.py" # Set right permissions for curl installation mkdir -p "$final_path/avatar-cache" From 51b2378b16b0d064c3a716b4cd20a7a9c8ed8d5d Mon Sep 17 00:00:00 2001 From: yalh76 Date: Wed, 13 Jul 2022 01:15:44 +0200 Subject: [PATCH 2/3] implement autoupdater --- .github/workflows/updater.sh | 59 +++++++++++++++++++++++++++++++++++ .github/workflows/updater.yml | 49 +++++++++++++++++++++++++++++ 2 files changed, 108 insertions(+) create mode 100644 .github/workflows/updater.sh create mode 100644 .github/workflows/updater.yml diff --git a/.github/workflows/updater.sh b/.github/workflows/updater.sh new file mode 100644 index 0000000..eabb300 --- /dev/null +++ b/.github/workflows/updater.sh @@ -0,0 +1,59 @@ +#!/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]') +repo=$(cat manifest.json | jq -j '.upstream.code|split("https://github.com/")[1]') +# 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://api.github.com/repos/$repo/releases" | jq -r '.[] | select( .prerelease != true ) | .tag_name' | cut -d "-" -f2 | sort -V | tail -1) + +# 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 + + +#================================================= +# 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 From 9e49defa24788b568b76a5201e69a96d132e38ec Mon Sep 17 00:00:00 2001 From: yalh76 Date: Wed, 13 Jul 2022 02:11:01 +0200 Subject: [PATCH 3/3] Fix #58 --- conf/libxxhash.src | 7 +++++++ scripts/install | 15 ++++++++++++++- scripts/remove | 13 +++++++++++++ scripts/restore | 13 +++++++++++++ scripts/upgrade | 15 ++++++++++++++- 5 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 conf/libxxhash.src diff --git a/conf/libxxhash.src b/conf/libxxhash.src new file mode 100644 index 0000000..5d4f0c6 --- /dev/null +++ b/conf/libxxhash.src @@ -0,0 +1,7 @@ +SOURCE_URL=https://github.com/Cyan4973/xxHash/archive/refs/tags/v0.8.1.tar.gz +SOURCE_SUM=3bb6b7d6f30c591dd65aaaff1c8b7a5b94d81687998ca9400082c739a690436c +SOURCE_SUM_PRG=sha256sum +SOURCE_FORMAT=tar.gz +SOURCE_IN_SUBDIR=true +SOURCE_FILENAME= +SOURCE_EXTRACT=true diff --git a/scripts/install b/scripts/install index 0cbeb4c..f376c45 100755 --- a/scripts/install +++ b/scripts/install @@ -112,6 +112,19 @@ ynh_add_nginx_config #================================================= # SPECIFIC SETUP +#================================================= +# INSTALL XXHASH +#================================================= +ynh_script_progression --message="Installing xxHash..." + +tempdir="$(mktemp -d)" +ynh_setup_source --dest_dir=$tempdir --source_id="libxxhash" +pushd $tempdir + make + make install +popd +ynh_secure_remove --file="$tempdir" + #================================================= # CONFIGURE HUB #================================================= @@ -139,7 +152,7 @@ chown -R $app: "$final_path" set -o nounset cd "${final_path}" - sudo --user=$app $final_path/venv/bin/pip install --upgrade pip setuptools wheel pkgconfig + sudo --user=$app $final_path/venv/bin/pip install --upgrade pip setuptools wheel pkgconfig xxhash # Read the "Note" section in https://docs.weblate.org/en/weblate-4.11/admin/install/venv-debian.html#python-modules sudo --user=$app $final_path/venv/bin/pip install --force-reinstall --no-binary :all: cffi diff --git a/scripts/remove b/scripts/remove index e831757..40bb765 100755 --- a/scripts/remove +++ b/scripts/remove @@ -90,6 +90,19 @@ ynh_script_progression --message="Removing dependencies..." --weight=10 # Remove metapackage and its dependencies ynh_exec_warn_less ynh_remove_app_dependencies +#================================================= +# REMOVE XXHASH +#================================================= +ynh_script_progression --message="Removing xxHash..." + +tempdir="$(mktemp -d)" +ynh_setup_source --dest_dir=$tempdir --source_id="libxxhash" +pushd $tempdir + make + make uninstall +popd +ynh_secure_remove --file="$tempdir" + #================================================= # SPECIFIC REMOVE #================================================= diff --git a/scripts/restore b/scripts/restore index fb55dac..79712aa 100755 --- a/scripts/restore +++ b/scripts/restore @@ -95,6 +95,19 @@ ynh_psql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd ynh_psql_execute_as_root --sql="CREATE EXTENSION IF NOT EXISTS pg_trgm;" --database=$db_name ynh_psql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < ./db.sql +#================================================= +# INSTALL XXHASH +#================================================= +ynh_script_progression --message="Installing xxHash..." + +tempdir="$(mktemp -d)" +ynh_setup_source --dest_dir=$tempdir --source_id="libxxhash" +pushd $tempdir + make + make install +popd +ynh_secure_remove --file="$tempdir" + #================================================= # RESTORE VARIOUS FILES #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index c1620c9..1d0351e 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -113,6 +113,19 @@ ynh_add_nginx_config #================================================= # SPECIFIC UPGRADE +#================================================= +# INSTALL XXHASH +#================================================= +ynh_script_progression --message="Installing xxHash..." + +tempdir="$(mktemp -d)" +ynh_setup_source --dest_dir=$tempdir --source_id="libxxhash" +pushd $tempdir + make + make install +popd +ynh_secure_remove --file="$tempdir" + #================================================= # CONFIGURE HUB #================================================= @@ -165,7 +178,7 @@ upgrade() { set -o nounset cd "${final_path}" - sudo --user=$app $final_path/venv/bin/pip install --upgrade pip setuptools wheel pkgconfig + sudo --user=$app $final_path/venv/bin/pip install --upgrade pip setuptools wheel pkgconfig xxhash # Read the "Note" section in https://docs.weblate.org/en/weblate-4.11/admin/install/venv-debian.html#python-modules sudo --user=$app $final_path/venv/bin/pip install --force-reinstall --no-binary :all: cffi