From 39369b32040c3cf7edc42d975f078cc5590d96ed Mon Sep 17 00:00:00 2001 From: yalh76 Date: Thu, 22 Sep 2022 03:39:33 +0200 Subject: [PATCH 1/2] Apply last example_ynh --- .github/workflows/updater.sh | 84 ++++++++++++++++++------------------ check_process | 1 + conf/app.src | 1 + manifest.json | 2 +- scripts/_common.sh | 19 ++++++-- scripts/backup | 6 ++- scripts/change_url | 10 ++--- scripts/install | 18 +++++--- scripts/remove | 52 +++++++++++----------- scripts/restore | 31 +++++++------ scripts/upgrade | 19 ++++---- 11 files changed, 134 insertions(+), 109 deletions(-) diff --git a/.github/workflows/updater.sh b/.github/workflows/updater.sh index 50c6881..fd14205 100755 --- a/.github/workflows/updater.sh +++ b/.github/workflows/updater.sh @@ -9,9 +9,6 @@ # Since each app is different, maintainers can adapt its contents so as to perform # automatic actions when a new upstream release is detected. -# Remove this exit command when you are ready to run this Action -#exit 1 - #================================================= # FETCHING LATEST RELEASE AND ITS ASSETS #================================================= @@ -25,9 +22,9 @@ assets=($(curl --silent "https://api.github.com/repos/$repo/releases" | jq -r '[ # 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. +# 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} + version=${version:1} fi # Setting up the environment variables @@ -40,12 +37,12 @@ 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 + 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 + 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.) @@ -61,55 +58,56 @@ echo "${#assets[@]} available asset(s)" # Let's loop over the array of assets URLs for asset_url in ${assets[@]}; do -echo "Handling asset at $asset_url" + 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 - *"baikal-"*".zip") - src="app" - ;; - *) - src="" - ;; -esac + # 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 + *"baikal-"*".zip") + src="app" + ;; + *) + src="" + ;; + esac -# If $src is not empty, let's process the asset -if [ ! -z "$src" ]; then + # If $src is not empty, let's process the asset + if [ ! -z "$src" ]; then -# Create the temporary directory -tempdir="$(mktemp -d)" + # 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) + # 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 + # Delete temporary directory + rm -rf $tempdir -# Get extension -if [[ $filename == *.tar.gz ]]; then - extension=tar.gz -else - extension=${filename##*.} -fi + # Get extension + if [[ $filename == *.tar.gz ]]; then + extension=tar.gz + else + extension=${filename##*.} + fi -# Rewrite source file -cat < conf/$src.src + # Rewrite source file + cat < conf/$src.src SOURCE_URL=$asset_url SOURCE_SUM=$checksum SOURCE_SUM_PRG=sha256sum SOURCE_FORMAT=$extension SOURCE_IN_SUBDIR=true SOURCE_FILENAME= +SOURCE_EXTRACT=true EOT -echo "... conf/$src.src updated" + echo "... conf/$src.src updated" -else -echo "... asset ignored" -fi + else + echo "... asset ignored" + fi done diff --git a/check_process b/check_process index 3f57549..9b1daae 100644 --- a/check_process +++ b/check_process @@ -15,6 +15,7 @@ upgrade=1 from_commit=7c074c7b18322cde08c4eb57ffbc5ae174b7ae65 backup_restore=1 multi_instance=0 + port_already_use=0 change_url=1 ;;; Options Email= diff --git a/conf/app.src b/conf/app.src index ee5cd22..c419b03 100644 --- a/conf/app.src +++ b/conf/app.src @@ -4,3 +4,4 @@ SOURCE_SUM_PRG=sha256sum SOURCE_FORMAT=zip SOURCE_IN_SUBDIR=true SOURCE_FILENAME= +SOURCE_EXTRACT=true diff --git a/manifest.json b/manifest.json index 5954e63..c1c0231 100644 --- a/manifest.json +++ b/manifest.json @@ -31,7 +31,7 @@ "mysql" ], "arguments": { - "install" : [ + "install": [ { "name": "domain", "type": "domain" diff --git a/scripts/_common.sh b/scripts/_common.sh index e77b284..76bfd01 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -3,14 +3,19 @@ #================================================= # COMMON VARIABLES #================================================= +# PHP APP SPECIFIC +#================================================= # dependencies used by the app -YNH_PHP_VERSION="8.0" +YNH_PHP_VERSION=8.0 -pkg_dependencies="php${YNH_PHP_VERSION}-xml php${YNH_PHP_VERSION}-mbstring php${YNH_PHP_VERSION}-mysql php${YNH_PHP_VERSION}-ldap" +php_dependencies="php${YNH_PHP_VERSION}-xml php${YNH_PHP_VERSION}-mbstring php${YNH_PHP_VERSION}-mysql php${YNH_PHP_VERSION}-ldap" + +# dependencies used by the app (must be on a single line) +pkg_dependencies="$php_dependencies" #================================================= -# EXPERIMENTAL HELPERS +# PERSONAL HELPERS #================================================= # Check if an URL is already handled @@ -44,3 +49,11 @@ is_url_handled() { return 1 fi } + +#================================================= +# EXPERIMENTAL HELPERS +#================================================= + +#================================================= +# FUTURE OFFICIAL HELPERS +#================================================= diff --git a/scripts/backup b/scripts/backup index e20a222..86cad22 100644 --- a/scripts/backup +++ b/scripts/backup @@ -6,13 +6,17 @@ # IMPORT GENERIC HELPERS #================================================= -# source ../settings/scripts/_common.sh +# 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 #================================================= # MANAGE SCRIPT FAILURE #================================================= +ynh_clean_setup () { + 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 54431ae..bb5917c 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -67,19 +67,19 @@ ynh_script_progression --message="Updating NGINX web server configuration..." -- nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf -# Change the path in the nginx config file +# Change the path in the NGINX config file if [ $change_path -eq 1 ] then - # Make a backup of the original nginx config file if modified + # Make a backup of the original NGINX config file if modified ynh_backup_if_checksum_is_different --file="$nginx_conf_path" - # Set global variables for nginx helper + # Set global variables for NGINX helper domain="$old_domain" path_url="$new_path" - # Create a dedicated nginx config + # Create a dedicated NGINX config ynh_add_nginx_config fi -# Change the domain for nginx +# Change the domain for NGINX if [ $change_domain -eq 1 ] then # Delete file checksum for the old conf file location diff --git a/scripts/install b/scripts/install index 3a0cd5f..39b34c0 100644 --- a/scripts/install +++ b/scripts/install @@ -6,13 +6,17 @@ # IMPORT GENERIC HELPERS #================================================= -source ./_common.sh +source _common.sh 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,19 +26,20 @@ ynh_abort_if_errors domain=$YNH_APP_ARG_DOMAIN path_url=$YNH_APP_ARG_PATH password=$YNH_APP_ARG_PASSWORD + +app=$YNH_APP_INSTANCE_NAME + timezone=$(cat /etc/timezone) encrypt_key=$(ynh_string_random 24) password_hash=$(echo -n admin:BaikalDAV:$password | sha256sum | cut -d ' ' -f 1) -app=$YNH_APP_INSTANCE_NAME - #================================================= # CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS #================================================= ynh_script_progression --message="Validating installation parameters..." --weight=1 final_path=/var/www/$app -test ! -e "$final_path" || ynh_die "This path already contains a folder" +test ! -e "$final_path" || ynh_die --message="This path already contains a folder" # Register (book) web path ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url @@ -77,7 +82,7 @@ ynh_system_user_create --username=$app --home_dir="$final_path" #================================================= ynh_script_progression --message="Creating a MySQL database..." --weight=2 -db_name=$(ynh_sanitize_dbid $app) +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_mysql_setup_db --db_user=$db_user --db_name=$db_name @@ -119,8 +124,7 @@ ynh_add_nginx_config #================================================= ynh_script_progression --message="Configuring $app..." --weight=3 -ynh_mysql_connect_as --user=$db_user --password="$db_pwd" --database=$db_name \ - < "$final_path/Core/Resources/Db/MySQL/db.sql" +ynh_mysql_connect_as --user=$db_user --password="$db_pwd" --database=$db_name < "$final_path/Core/Resources/Db/MySQL/db.sql" #================================================= # CONFIGURE BAIKAL diff --git a/scripts/remove b/scripts/remove index 7da7426..cefdd0b 100644 --- a/scripts/remove +++ b/scripts/remove @@ -26,11 +26,35 @@ final_path=$(ynh_app_setting_get --app=$app --key=final_path) #================================================= # REMOVE THE MYSQL DATABASE #================================================= -ynh_script_progression --message="Removing the MySQL database" --weight=1 +ynh_script_progression --message="Removing the MySQL database..." --weight=1 # Remove a database if it exists, along with the associated user ynh_mysql_remove_db --db_user=$db_user --db_name=$db_name +#================================================= +# REMOVE APP MAIN DIR +#================================================= +ynh_script_progression --message="Removing app main directory..." --weight=3 + +# Remove the app directory securely +ynh_secure_remove --file="$final_path" + +#================================================= +# REMOVE NGINX CONFIGURATION +#================================================= +ynh_script_progression --message="Removing NGINX web server configuration..." --weight=1 + +# Remove the dedicated NGINX config +ynh_remove_nginx_config + +#================================================= +# REMOVE 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 #================================================= @@ -39,36 +63,12 @@ ynh_script_progression --message="Removing dependencies..." --weight=3 # Remove metapackage and its dependencies ynh_remove_app_dependencies -#================================================= -# REMOVE APP MAIN DIR -#================================================= -ynh_script_progression --message="Removing app main directory" --weight=3 - -# Remove the app directory securely -ynh_secure_remove --file="$final_path" - -#================================================= -# REMOVE NGINX CONFIGURATION -#================================================= -ynh_script_progression --message="Removing NGINX web server configuration" --weight=1 - -# Remove the dedicated NGINX config -ynh_remove_nginx_config - -#================================================= -# REMOVE PHP-FPM CONFIGURATION -#================================================= -ynh_script_progression --message="Removing PHP-FPM configuration" --weight=1 - -# Remove the dedicated PHP-FPM config -ynh_remove_fpm_config - #================================================= # GENERIC FINALIZATION #================================================= # REMOVE DEDICATED USER #================================================= -ynh_script_progression --message="Removing the dedicated system user" --weight=1 +ynh_script_progression --message="Removing the dedicated system user..." --weight=1 # Delete a system user ynh_system_user_delete --username=$app diff --git a/scripts/restore b/scripts/restore index 6c05c96..17e7a91 100644 --- a/scripts/restore +++ b/scripts/restore @@ -6,6 +6,7 @@ # IMPORT GENERIC HELPERS #================================================= +# 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 @@ -13,13 +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=1 +ynh_script_progression --message="Loading installation settings..." --weight=1 app=$YNH_APP_INSTANCE_NAME @@ -65,28 +69,18 @@ chmod 750 "$final_path" chmod -R o-rwx "$final_path" chown -R $app:www-data "$final_path" -#================================================= -# RESTORE THE MYSQL DATABASE -#================================================= -ynh_script_progression --message="Restoring the MySQL database..." --weight=2 - -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 USER RIGHTS -#================================================= - # Set permissions chown $app: "$final_path/config/baikal.yaml" chmod 640 "$final_path/config/baikal.yaml" +#================================================= +# SPECIFIC RESTORATION #================================================= # REINSTALL DEPENDENCIES #================================================= ynh_script_progression --message="Reinstalling dependencies..." --weight=5 +# Define and install dependencies ynh_install_app_dependencies $pkg_dependencies #================================================= @@ -103,6 +97,15 @@ 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 MYSQL DATABASE +#================================================= +ynh_script_progression --message="Restoring the MySQL database..." --weight=2 + +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 + #================================================= # GENERIC FINALIZATION #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index 6464025..fe9e335 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -22,13 +22,14 @@ 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=mysqlpwd) -phpversion=$YNH_PHP_VERSION +phpversion=$(ynh_app_setting_get --app=$app --key=phpversion) password_hash=$(ynh_app_setting_get --app=$app --key=password_hash) encrypt_key=$(ynh_app_setting_get --app=$app --key=encrypt_key) #================================================= # CHECK VERSION #================================================= +ynh_script_progression --message="Checking version..." --weight=1 upgrade_type=$(ynh_check_app_version_changed) @@ -40,12 +41,14 @@ 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 + # 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 #================================================= @@ -91,8 +94,6 @@ 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" -#================================================= -# STANDARD UPGRADE STEPS #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= @@ -101,7 +102,8 @@ if [ "$upgrade_type" == "UPGRADE_APP" ] then ynh_script_progression --message="Upgrading source files..." --weight=3 - ynh_setup_source --dest_dir="$final_path" --keep="Specific config" + # Download, check integrity, uncompress and patch the source from app.src + ynh_setup_source --dest_dir="$final_path" --keep="config/baikal.yaml" fi chmod 750 "$final_path" @@ -134,16 +136,13 @@ ynh_add_nginx_config #================================================= # SPECIFIC UPGRADE #================================================= -# UPGRADE BAIKAL +# UPGRADE BAIKAL CONFIGURATION #================================================= # We keep this to allow upgrade the config file in case it needs to be changed. if [ "$upgrade_type" == "UPGRADE_APP" ] then - #================================================= - # UPGRADE BAIKAL CONFIGURATION - #================================================= ynh_script_progression --message="Upgrading the configuration file..." --weight=2 timezone=$(cat /etc/timezone) @@ -153,6 +152,8 @@ then chmod 640 "$final_path/config/baikal.yaml" fi +#================================================= +# GENERIC FINALIZATION #================================================= # RELOAD NGINX #================================================= From c608f7572bafc076688ea0bb8db8100fad65e129 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Thu, 22 Sep 2022 22:57:12 +0200 Subject: [PATCH 2/2] Update manifest.json --- manifest.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/manifest.json b/manifest.json index c1c0231..e44cbab 100644 --- a/manifest.json +++ b/manifest.json @@ -18,8 +18,8 @@ }, "license": "GPL-3.0", "maintainer": { - "name": "julien", - "email": "julien.malik@paraiso.me" + "name": "", + "email": "" }, "requirements": { "yunohost": ">= 11.0.9"