From dad7616ee02b4bfb704db1c119293c68d4c61b62 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Wed, 21 Sep 2022 23:25:32 +0200 Subject: [PATCH] Apply last example_ynh --- .github/workflows/updater.sh | 132 ++++++++++++++++++++++++++++++++++ .github/workflows/updater.yml | 49 +++++++++++++ .gitignore | 1 - check_process | 5 +- conf/ampache.cfg.php | 9 ++- conf/nginx.conf | 80 ++++++++++----------- doc/.DS_Store | Bin 6148 -> 0 bytes manifest.json | 14 ++-- scripts/_common.sh | 12 +++- scripts/backup | 13 +++- scripts/install | 111 +++++++++++++++++----------- scripts/remove | 38 +++++++--- scripts/restore | 40 +++++++---- scripts/upgrade | 71 +++++++++--------- 14 files changed, 422 insertions(+), 153 deletions(-) create mode 100644 .github/workflows/updater.sh create mode 100644 .github/workflows/updater.yml delete mode 100644 .gitignore delete mode 100644 doc/.DS_Store diff --git a/.github/workflows/updater.sh b/.github/workflows/updater.sh new file mode 100644 index 0000000..e621712 --- /dev/null +++ b/.github/workflows/updater.sh @@ -0,0 +1,132 @@ +#!/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' | sort -V | tail -1) +assets=($(curl --silent "https://api.github.com/repos/$repo/releases" | jq -r '[ .[] | select(.tag_name=="'$version'").assets[].browser_download_url ] | join(" ") | @sh' | tr -d "'")) + +# 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 + *"all_php8.0"*) + src="app" + ;; + *) + 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 + + # Get extension + if [[ $filename == *.tar.gz ]]; then + extension=tar.gz + else + extension=${filename##*.} + fi + + # Rewrite source file + cat < conf/$src.src +SOURCE_URL=$asset_url +SOURCE_SUM=$checksum +SOURCE_SUM_PRG=sha256sum +SOURCE_FORMAT=$extension +SOURCE_IN_SUBDIR=false +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/.gitignore b/.gitignore deleted file mode 100644 index f4c6dce..0000000 --- a/.gitignore +++ /dev/null @@ -1 +0,0 @@ -sources diff --git a/check_process b/check_process index 51ee97e..f66c795 100644 --- a/check_process +++ b/check_process @@ -2,8 +2,8 @@ ; Manifest domain="domain.tld" path="/ampache" - admin="john" is_public=1 + admin="john" ; Checks pkg_linter=1 setup_sub_dir=1 @@ -15,9 +15,10 @@ upgrade=1 from_commit=919c3359d9fe21c29bad1cabf0e7b9a8e368f20e backup_restore=1 multi_instance=1 + port_already_use=0 change_url=1 ;;; Options -Email=aymhce@gmail.com +Email= Notification=none ;;; Upgrade options ; commit=919c3359d9fe21c29bad1cabf0e7b9a8e368f20e diff --git a/conf/ampache.cfg.php b/conf/ampache.cfg.php index a10c81b..54258f1 100644 --- a/conf/ampache.cfg.php +++ b/conf/ampache.cfg.php @@ -391,6 +391,13 @@ catalog_prefix_pattern = "The|An|A|Die|Das|Ein|Eine|Les|Le|La" ; DEFAULT: Ampache - Zip Batch Download ;file_zip_comment = "Ampache - Zip Batch Download" +; Load the debug webplayer +; This will load the *.js player instead of the *.min.js player +; The unminified player has a lot of console.log() statements in the code. +; You can make changes and then check how the player is functioning. +; DEFAULT: "false" +;webplayer_debug = "true" + ; Waveform ; This settings tells Ampache to attempt to generate a waveform ; for each song. It requires transcode and encode_args_wav settings. @@ -837,7 +844,7 @@ debug_level = 5 ; the specified directory exists and your HTTP server has ; write access. ; DEFAULT: none -log_path = "/var/www/ampache/log" +log_path = "/var/log/__APP__" ; Log filename pattern ; This defines where the log file name pattern diff --git a/conf/nginx.conf b/conf/nginx.conf index fde30de..77a5133 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -1,52 +1,52 @@ #sub_path_only rewrite ^__PATH__$ __PATH__/ permanent; location __PATH__/ { - # Path to source - alias __FINALPATH__/public/; + # Path to source + alias __FINALPATH__/public/; - rewrite ^__PATH__/play/ssid/(.*)/type/(.*)/oid/([0-9]+)/uid/([0-9]+)/client/(.*)/noscrobble/([0-1])/player/(.*)/name/(.*)$ __PATH__/play/index.php?ssid=$1&type=$2&oid=$3&uid=$4&client=$5&noscrobble=$6&player=$7&name=$8 last; - rewrite ^__PATH__/play/ssid/(.*)/type/(.*)/oid/([0-9]+)/uid/([0-9]+)/client/(.*)/noscrobble/([0-1])/bitrate/([0-9]+)/player/(.*)/name/(.*)$ __PATH__/play/index.php?ssid=$1&type=$2&oid=$3&uid=$4&client=$5&noscrobble=$6&bitrate=$7player=$8&name=$9 last; - rewrite ^__PATH__/play/ssid/(.*)/type/(.*)/oid/([0-9]+)/uid/([0-9]+)/client/(.*)/noscrobble/([0-1])/transcode_to/(w+)/bitrate/([0-9]+)/player/(.*)/name/(.*)$ __PATH__/play/index.php?ssid=$1&type=$2&oid=$3&uid=$4&client=$5&noscrobble=$6&transcode_to=$7&bitrate=$8&player=$9&name=$10 last; + rewrite ^__PATH__/play/ssid/(.*)/type/(.*)/oid/([0-9]+)/uid/([0-9]+)/client/(.*)/noscrobble/([0-1])/player/(.*)/name/(.*)$ __PATH__/play/index.php?ssid=$1&type=$2&oid=$3&uid=$4&client=$5&noscrobble=$6&player=$7&name=$8 last; + rewrite ^__PATH__/play/ssid/(.*)/type/(.*)/oid/([0-9]+)/uid/([0-9]+)/client/(.*)/noscrobble/([0-1])/bitrate/([0-9]+)/player/(.*)/name/(.*)$ __PATH__/play/index.php?ssid=$1&type=$2&oid=$3&uid=$4&client=$5&noscrobble=$6&bitrate=$7player=$8&name=$9 last; + rewrite ^__PATH__/play/ssid/(.*)/type/(.*)/oid/([0-9]+)/uid/([0-9]+)/client/(.*)/noscrobble/([0-1])/transcode_to/(w+)/bitrate/([0-9]+)/player/(.*)/name/(.*)$ __PATH__/play/index.php?ssid=$1&type=$2&oid=$3&uid=$4&client=$5&noscrobble=$6&transcode_to=$7&bitrate=$8&player=$9&name=$10 last; - index index.php; - try_files $uri $uri/ index.php; - location ~ [^/]\.php(/|$) { - fastcgi_split_path_info ^(.+?\.php)(/.*)$; - fastcgi_pass unix:/var/run/php/php__PHPVERSION__-fpm-__NAME__.sock; + index index.php; + try_files $uri $uri/ index.php; + location ~ [^/]\.php(/|$) { + fastcgi_split_path_info ^(.+?\.php)(/.*)$; + fastcgi_pass unix:/var/run/php/php__PHPVERSION__-fpm-__NAME__.sock; - fastcgi_index index.php; - include fastcgi_params; - fastcgi_param REMOTE_USER $remote_user; - fastcgi_param PATH_INFO $fastcgi_path_info; - fastcgi_param SCRIPT_FILENAME $request_filename; - } - - location ^~ __PATH__/bin/ { - deny all; - return 403; - } + fastcgi_index index.php; + include fastcgi_params; + fastcgi_param REMOTE_USER $remote_user; + fastcgi_param PATH_INFO $fastcgi_path_info; + fastcgi_param SCRIPT_FILENAME $request_filename; + } + + location ^~ __PATH__/bin/ { + deny all; + return 403; + } - location ^~ __PATH__/config/ { - deny all; - return 403; - } + location ^~ __PATH__/config/ { + deny all; + return 403; + } - rewrite ^__PATH__/play/ssid/(\w+)/type/(\w+)/oid/([0-9]+)/uid/([0-9]+)/name/(.*)$ __PATH__/play/index.php?ssid=$1&type=$2&oid=$3&uid=$4&name=$5 last; - rewrite ^__PATH__/play/ssid/(\w+)/type/(\w+)/oid/([0-9]+)/uid/([0-9]+)/client/(.*)/noscrobble/([0-1])/name/(.*)$ __PATH__/play/index.php?ssid=$1&type=$2&oid=$3&uid=$4&client=$5&noscrobble=$6&name=$7 last; + rewrite ^__PATH__/play/ssid/(\w+)/type/(\w+)/oid/([0-9]+)/uid/([0-9]+)/name/(.*)$ __PATH__/play/index.php?ssid=$1&type=$2&oid=$3&uid=$4&name=$5 last; + rewrite ^__PATH__/play/ssid/(\w+)/type/(\w+)/oid/([0-9]+)/uid/([0-9]+)/client/(.*)/noscrobble/([0-1])/name/(.*)$ __PATH__/play/index.php?ssid=$1&type=$2&oid=$3&uid=$4&client=$5&noscrobble=$6&name=$7 last; - location __PATH__/rest { + location __PATH__/rest { - #enable subsonic api - if ( !-d $request_filename ) { - rewrite ^__PATH__/rest/(.*)\.view$ __PATH__/rest/index.php?action=$1 last; - rewrite ^__PATH__/rest/fake/(.+)$ __PATH__/play/$1 last; - } + #enable subsonic api + if ( !-d $request_filename ) { + rewrite ^__PATH__/rest/(.*)\.view$ __PATH__/rest/index.php?action=$1 last; + rewrite ^__PATH__/rest/fake/(.+)$ __PATH__/play/$1 last; + } - limit_except GET POST { - deny all; - } - } - - # Include SSOWAT user panel. - include conf.d/yunohost_panel.conf.inc; + limit_except GET POST { + deny all; + } + } + + # Include SSOWAT user panel. + include conf.d/yunohost_panel.conf.inc; } diff --git a/doc/.DS_Store b/doc/.DS_Store deleted file mode 100644 index c90376b56b73b627c519d1a34c5d8c9abb7004dc..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHKyG{c^3>-s>NNG}1?l15Mt0;UyegFv&DbPhqfch%Fi%(bFB<-Yt6!=#P*lfL7ulP#UTPH8)y|&RG>0a|qcjG!J4AG8> j(T=(Cc6=8_S=W5c^IkY62A%n!6ZJFTy2zx!wH5dQ#>Eyj diff --git a/manifest.json b/manifest.json index 6ad593e..7ec89d8 100644 --- a/manifest.json +++ b/manifest.json @@ -6,7 +6,7 @@ "en": "Web based audio/video streaming application", "fr": "Application de streaming audio et vidéo" }, - "version": "5.5.1~ynh1", + "version": "5.5.1~ynh2", "url": "http://ampache.org", "upstream": { "license": "AGPL-3.0", @@ -24,13 +24,13 @@ "yunohost": ">= 11.0.9" }, "multi_instance": true, - "services" : [ + "services": [ "nginx", "php8.0-fpm", "mysql" ], "arguments": { - "install" : [ + "install": [ { "name": "domain", "type": "domain" @@ -41,14 +41,14 @@ "example": "/ampache", "default": "/ampache" }, - { - "name": "admin", - "type": "user" - }, { "name": "is_public", "type": "boolean", "default": true + }, + { + "name": "admin", + "type": "user" } ] } diff --git a/scripts/_common.sh b/scripts/_common.sh index 340027d..d13e89e 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -4,18 +4,24 @@ # COMMON VARIABLES #================================================= -YNH_PHP_VERSION="8.0" +YNH_PHP_VERSION=8.0 # Composer version YNH_COMPOSER_VERSION="2.3.5" -pkg_dependencies="libav-tools|ffmpeg php${YNH_PHP_VERSION}-mysql php${YNH_PHP_VERSION}-curl php${YNH_PHP_VERSION}-simplexml php${YNH_PHP_VERSION}-gd php${YNH_PHP_VERSION}-ldap php${YNH_PHP_VERSION}-intl" +php_dependencies="php${YNH_PHP_VERSION}-mysql php${YNH_PHP_VERSION}-curl php${YNH_PHP_VERSION}-simplexml php${YNH_PHP_VERSION}-gd php${YNH_PHP_VERSION}-ldap php${YNH_PHP_VERSION}-intl" + +# dependencies used by the app (must be on a single line) +pkg_dependencies="libav-tools|ffmpeg $php_dependencies" + +#================================================= +# PERSONAL HELPERS +#================================================= #================================================= # EXPERIMENTAL HELPERS #================================================= - #================================================= # FUTURE OFFICIAL HELPERS #================================================= diff --git a/scripts/backup b/scripts/backup index 742dee5..4cf0ae1 100644 --- a/scripts/backup +++ b/scripts/backup @@ -6,7 +6,7 @@ # IMPORT GENERIC HELPERS #================================================= -#Keep this path for calling _common.sh inside the execution's context of backup and restore scripts +# Keep this path for calling _common.sh inside the execution's context of backup and restore scripts source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers @@ -14,6 +14,9 @@ source /usr/share/yunohost/helpers # MANAGE SCRIPT FAILURE #================================================= +ynh_clean_setup () { + true +} # Exit if an error occurs during the execution of the script ynh_abort_if_errors @@ -52,6 +55,14 @@ ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" ynh_backup --src_path="/etc/php/$phpversion/fpm/pool.d/$app.conf" +#================================================= +# SPECIFIC BACKUP +#================================================= +# BACKUP LOGROTATE +#================================================= + +ynh_backup --src_path="/etc/logrotate.d/$app" + #================================================= # BACKUP THE MYSQL DATABASE #================================================= diff --git a/scripts/install b/scripts/install index 059a7ef..665968c 100644 --- a/scripts/install +++ b/scripts/install @@ -13,6 +13,9 @@ source /usr/share/yunohost/helpers # MANAGE SCRIPT FAILURE #================================================= +ynh_clean_setup () { + true +} # Exit if an error occurs during the execution of the script ynh_abort_if_errors @@ -22,16 +25,17 @@ 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 -secret_key=$(ynh_string_random --length=24) +admin=$YNH_APP_ARG_ADMIN app=$YNH_APP_INSTANCE_NAME +secret_key=$(ynh_string_random --length=24) + #================================================= # 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" @@ -58,6 +62,14 @@ ynh_script_progression --message="Installing dependencies..." --weight=25 ynh_install_app_dependencies $pkg_dependencies +#================================================= +# CREATE DEDICATED USER +#================================================= +ynh_script_progression --message="Configuring system user..." --weight=1 + +# Create a system user +ynh_system_user_create --username=$app --home_dir="$final_path" + #================================================= # CREATE A MYSQL DATABASE #================================================= @@ -68,14 +80,6 @@ db_user=$db_name ynh_app_setting_set --app=$app --key=db_name --value=$db_name ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name -#================================================= -# CREATE DEDICATED USER -#================================================= -ynh_script_progression --message="Configuring system user..." --weight=1 - -# Create a system user -ynh_system_user_create --username=$app --home_dir="$final_path" - #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= @@ -89,6 +93,15 @@ chmod 750 "$final_path" chmod -R o-rwx "$final_path" chown -R $app:www-data "$final_path" +#================================================= +# PHP-FPM CONFIGURATION +#================================================= +ynh_script_progression --message="Configuring PHP-FPM..." --weight=2 + +# Create a dedicated PHP-FPM config +ynh_add_fpm_config --usage=low --footprint=low +phpversion=$(ynh_app_setting_get --app=$app --key=phpversion) + #================================================= # NGINX CONFIGURATION #================================================= @@ -97,27 +110,8 @@ ynh_script_progression --message="Configuring NGINX web server..." --weight=1 # Create a dedicated NGINX config ynh_add_nginx_config -#================================================= -# PHP-FPM CONFIGURATION -#================================================= -ynh_script_progression --message="Configuring PHP-FPM..." --weight=2 - -# Create a dedicated php-fpm config -ynh_add_fpm_config --usage=low --footprint=low -phpversion=$(ynh_app_setting_get --app=$app --key=phpversion) - #================================================= # SPECIFIC SETUP -#================================================= -# CONFIGURE AMPACHE -#================================================= -ynh_script_progression --message="Preconfiguring $app..." --weight=2 - -ynh_add_config --template="../conf/ampache.cfg.php" --destination="$final_path/config/ampache.cfg.php" - -chmod 600 "$final_path/config/ampache.cfg.php" -chown $app: "$final_path/config/ampache.cfg.php" - #================================================= # LOAD DEFAULT DATABASE #================================================= @@ -126,14 +120,6 @@ ynh_script_progression --message="Loading default database..." --weight=2 # Load default ampache database ynh_mysql_connect_as --user=$db_user --password="$db_pwd" --database=$db_name < "$final_path/resources/sql/ampache.sql" -#================================================= -# INSTALL AMPACHE WITH COMPOSER -#================================================= -ynh_script_progression --message="Installing $app with Composer..." --weight=45 - -# Install composer -ynh_install_composer - #================================================= # INSTALL MULTIMEDIA DIRECTORIES #================================================= @@ -142,18 +128,42 @@ ynh_script_progression --message="Installing multimedia directories..." --weight ynh_multimedia_build_main_dir #================================================= -# PRE CONFIGURE AMPACHE +# ADD A CONFIGURATION #================================================= -ynh_script_progression --message="Configuring $app..." --weight=5 +ynh_script_progression --message="Adding a configuration file..." --weight=2 + +ynh_add_config --template="../conf/ampache.cfg.php" --destination="$final_path/config/ampache.cfg.php" + +chmod 600 "$final_path/config/ampache.cfg.php" +chown $app: "$final_path/config/ampache.cfg.php" + +#================================================= +# INSTALL WITH COMPOSER +#================================================= +ynh_script_progression --message="Installing with Composer..." --weight=45 + +# Install composer +ynh_install_composer --workdir=$final_path + +#================================================= +# SETUP APPLICATION WITH CURL +#================================================= +ynh_script_progression --message="Setuping application with CURL..." --weight=5 # Set the app as temporarily public for curl call +ynh_script_progression --message="Configuring SSOwat..." --weight=1 +# Making the app public for curl ynh_permission_update --permission="main" --add="visitors" # Reload NGINX ynh_systemd_action --service_name=nginx --action=reload +# Installation with curl +ynh_script_progression --message="Finalizing installation..." --weight=1 ynh_local_curl /update.php?action=update -sleep 1 + +# Remove the public access +ynh_permission_update --permission="main" --remove="visitors" #================================================= # LOAD ADMIN DATABASE @@ -167,14 +177,29 @@ ynh_mysql_connect_as --user=$db_user --password="$db_pwd" --database=$db_name < ynh_secure_remove --file=/tmp/admin.sql +#================================================= +# GENERIC FINALIZATION +#================================================= +# SETUP LOGROTATE +#================================================= +ynh_script_progression --message="Configuring log rotation..." --weight=1 + +mkdir -p "/var/log/$app" +chown $app: "/var/log/$app" +# Use logrotate to manage application logfile(s) +ynh_use_logrotate + #================================================= # SETUP SSOWAT #================================================= ynh_script_progression --message="Configuring permissions..." --weight=1 -if [ $is_public -eq 0 ] +# Make app public if necessary +if [ $is_public -eq 1 ] then - ynh_permission_update --permission="main" --remove="visitors" + # 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/remove b/scripts/remove index 71e304f..330be1a 100644 --- a/scripts/remove +++ b/scripts/remove @@ -23,6 +23,14 @@ final_path=$(ynh_app_setting_get --app=$app --key=final_path) #================================================= # STANDARD REMOVE +#================================================= +# REMOVE LOGROTATE CONFIGURATION +#================================================= +ynh_script_progression --message="Removing logrotate configuration..." --weight=1 + +# Remove the app-specific logrotate config +ynh_remove_logrotate + #================================================= # REMOVE THE MYSQL DATABASE #================================================= @@ -31,14 +39,6 @@ ynh_script_progression --message="Removing the MySQL database..." --weight=3 # Remove a database if it exists, along with the associated user ynh_mysql_remove_db --db_user=$db_user --db_name=$db_name -#================================================= -# REMOVE DEPENDENCIES -#================================================= -ynh_script_progression --message="Removing dependencies..." --weight=4 - -# Remove metapackage and its dependencies -ynh_remove_app_dependencies - #================================================= # REMOVE APP MAIN DIR #================================================= @@ -50,7 +50,7 @@ ynh_secure_remove --file="$final_path" #================================================= # 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 @@ -58,11 +58,29 @@ ynh_remove_nginx_config #================================================= # REMOVE PHP-FPM CONFIGURATION #================================================= -ynh_script_progression --message="Removing PHP-FPM configuration..." +ynh_script_progression --message="Removing PHP-FPM configuration..." --weight=1 # Remove the dedicated PHP-FPM config ynh_remove_fpm_config +#================================================= +# REMOVE DEPENDENCIES +#================================================= +ynh_script_progression --message="Removing dependencies..." --weight=4 + +# Remove metapackage and its dependencies +ynh_remove_app_dependencies + +#================================================= +# SPECIFIC REMOVE +#================================================= +# REMOVE VARIOUS FILES +#================================================= +ynh_script_progression --message="Removing various files..." --weight=1 + +# Remove the log files +ynh_secure_remove --file="/var/log/$app" + #================================================= # GENERIC FINALIZATION #================================================= diff --git a/scripts/restore b/scripts/restore index b7993de..c2a5f64 100644 --- a/scripts/restore +++ b/scripts/restore @@ -6,7 +6,7 @@ # IMPORT GENERIC HELPERS #================================================= -#Keep this path for calling _common.sh inside the execution's context of backup and restore scripts +# Keep this path for calling _common.sh inside the execution's context of backup and restore scripts source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers @@ -14,12 +14,16 @@ source /usr/share/yunohost/helpers # MANAGE SCRIPT FAILURE #================================================= +ynh_clean_setup () { + true +} +# Exit if an error occurs during the execution of the script ynh_abort_if_errors #================================================= # LOAD SETTINGS #================================================= -ynh_script_progression --message="Loading settings..." --weight=2 +ynh_script_progression --message="Loading installation settings..." --weight=2 app=$YNH_APP_INSTANCE_NAME @@ -33,19 +37,13 @@ phpversion=$(ynh_app_setting_get --app=$app --key=phpversion) #================================================= # 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 " +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 configuration..." - -ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" - #================================================= # RECREATE THE DEDICATED USER #================================================= @@ -76,10 +74,17 @@ ynh_install_app_dependencies $pkg_dependencies #================================================= # RESTORE THE PHP-FPM CONFIGURATION #================================================= -ynh_script_progression --message="Restoring PHP-FPM configuration..." --weight=1 +ynh_script_progression --message="Restoring the PHP-FPM configuration..." --weight=1 ynh_restore_file --origin_path="/etc/php/$phpversion/fpm/pool.d/$app.conf" +#================================================= +# 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 MYSQL DATABASE #================================================= @@ -89,12 +94,21 @@ db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd) ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd ynh_mysql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < ./db.sql +#================================================= +# RESTORE THE LOGROTATE CONFIGURATION +#================================================= +ynh_script_progression --message="Restoring the logrotate configuration..." --weight=1 + +mkdir -p "/var/log/$app" +chown $app: "/var/log/$app" +ynh_restore_file --origin_path="/etc/logrotate.d/$app" + #================================================= # GENERIC FINALIZATION #================================================= # RELOAD NGINX AND PHP-FPM #================================================= -ynh_script_progression --message="Reloading NGINX web server and PHP-FPM..." +ynh_script_progression --message="Reloading NGINX web server and PHP-FPM..." --weight=1 ynh_systemd_action --service_name=php$phpversion-fpm --action=reload ynh_systemd_action --service_name=nginx --action=reload diff --git a/scripts/upgrade b/scripts/upgrade index fd0f219..40cb036 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -30,6 +30,7 @@ phpversion=$(ynh_app_setting_get --app=$app --key=phpversion) #================================================= # CHECK VERSION #================================================= +ynh_script_progression --message="Checking version..." --weight=1 upgrade_type=$(ynh_check_app_version_changed) @@ -41,16 +42,18 @@ ynh_script_progression --message="Backing up the app before upgrading (may take # Backup the current version of the app ynh_backup_before_upgrade ynh_clean_setup () { - # restore it if the upgrade fails - ynh_restore_upgradebackup + # Restore it if the upgrade fails + ynh_restore_upgradebackup } # Exit if an error occurs during the execution of the script ynh_abort_if_errors +#================================================= +# STANDARD UPGRADE STEPS #================================================= # ENSURE DOWNWARD COMPATIBILITY #================================================= -ynh_script_progression --message="Ensuring downward compatibility..." +ynh_script_progression --message="Ensuring downward compatibility..." --weight=1 # If db_name doesn't exist, create it if [ -z "$db_name" ]; then @@ -74,14 +77,15 @@ fi # Cleaning legacy permissions if ynh_legacy_permissions_exists; then ynh_legacy_permissions_delete_all - ynh_app_setting_delete --app=$app --key=is_public fi +ynh_secure_remove --file="$final_path/log" + #================================================= # 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" @@ -102,14 +106,6 @@ chmod 750 "$final_path" chmod -R o-rwx "$final_path" chown -R $app:www-data "$final_path" -#================================================= -# NGINX CONFIGURATION -#================================================= -ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=3 - -# Create a dedicated nginx config -ynh_add_nginx_config - #================================================= # UPGRADE DEPENDENCIES #================================================= @@ -122,33 +118,42 @@ ynh_install_app_dependencies $pkg_dependencies #================================================= ynh_script_progression --message="Upgrading PHP-FPM configuration..." --weight=2 -# Create a dedicated php-fpm config +# Create a dedicated PHP-FPM config ynh_add_fpm_config --usage=low --footprint=low +#================================================= +# NGINX CONFIGURATION +#================================================= +ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=3 + +# Create a dedicated NGINX config +ynh_add_nginx_config + #================================================= # SPECIFIC UPGRADE #================================================= -# RECONFIGURE AMPACHE +# UPDATE AMPACHE WITH COMPOSER #================================================= if [ "$upgrade_type" == "UPGRADE_APP" ] then - #ynh_script_progression --message="Upgrading Ampache configuration..." - - #ynh_add_config --template="../conf/ampache.cfg.php" --destination="$final_path/config/ampache.cfg.php" - #chmod 600 "$final_path/config/ampache.cfg.php" - #chown $app:$app "$final_path/config/ampache.cfg.php" - - #================================================= - # UPDATE AMPACHE WITH COMPOSER - #================================================= ynh_script_progression --message="Upgrading ampache with Composer..." --weight=30 # Install composer - ynh_install_composer + ynh_install_composer --workdir=$final_path ynh_composer_exec --phpversion="${YNH_PHP_VERSION}" --workdir="$final_path" --commands="config discard-changes true" fi +#================================================= +# UPDATE A CONFIG FILE +#================================================= +ynh_script_progression --message="Updating a configuration file..." --weight=1 + +ynh_add_config --template="../conf/ampache.cfg.php" --destination="$final_path/config/ampache.cfg.php" + +chmod 600 "$final_path/config/ampache.cfg.php" +chown $app: "$final_path/config/ampache.cfg.php" + #================================================= # UPDATE MULTIMEDIA DIRECTORIES #================================================= @@ -178,19 +183,21 @@ then fi #================================================= -# SETUP SSOWAT +# GENERIC FINALIZATION #================================================= -# ynh_script_progression --message="Configuring permissions..." +# SETUP LOGROTATE +#================================================= +ynh_script_progression --message="Upgrading logrotate configuration..." --weight=1 -# if [ $is_public -eq 0 ] -# then -# ynh_permission_update --permission="main" --remove="visitors" -# fi +mkdir -p "/var/log/$app" +chown $app: "/var/log/$app" +# Use logrotate to manage app-specific logfile(s) +ynh_use_logrotate --non-append #================================================= # 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