From 1bd68044394dd8b6390d04232e2d00a44e6aab1d Mon Sep 17 00:00:00 2001 From: yalh76 Date: Tue, 30 Aug 2022 00:36:35 +0200 Subject: [PATCH] Apply last example_ynh --- check_process | 52 +++++++++++++++++++------------------- manifest.json | 2 +- scripts/_common.sh | 7 ++++-- scripts/install | 61 ++++++++++++++++++++++----------------------- scripts/restore | 4 +-- scripts/upgrade | 62 +++++++++++++++++++++++++--------------------- 6 files changed, 97 insertions(+), 91 deletions(-) diff --git a/check_process b/check_process index eeee805..562e35f 100644 --- a/check_process +++ b/check_process @@ -1,31 +1,31 @@ ;; Test complet - ; Manifest - domain="domain.tld" (DOMAIN) - path="/path" (PATH) - admin="john" (USER) - is_public=1 (PUBLIC|public=1|private=0) - ; Checks - pkg_linter=1 - setup_sub_dir=1 - setup_root=1 - setup_nourl=0 - setup_private=1 - setup_public=1 - upgrade=1 - # 1.8.2~ynh1 - upgrade=1 from_commit=83500d6e866539d56a0aed6f288a8a8ce02a674b - # 1.8.2~ynh3 - upgrade=1 from_commit=50c74393ad4376bc18676b4be86fce74629ad60a - backup_restore=1 - multi_instance=1 - port_already_use=0 - change_url=0 + ; Manifest + domain="domain.tld" + path="/path" + is_public=1 + admin="john" + ; Checks + pkg_linter=1 + setup_sub_dir=1 + setup_root=1 + setup_nourl=0 + setup_private=1 + setup_public=1 + upgrade=1 + # 1.8.2~ynh1 + upgrade=1 from_commit=83500d6e866539d56a0aed6f288a8a8ce02a674b + # 1.8.2~ynh3 + upgrade=1 from_commit=50c74393ad4376bc18676b4be86fce74629ad60a + # 1.8.2~ynh4 + upgrade=1 from_commit=7da020da5079b580cc2a418e2f6fb48f637a989a + backup_restore=1 + multi_instance=1 + port_already_use=0 + change_url=0 ;;; Options Email= Notification=none ;;; Upgrade options - ; commit=83500d6e866539d56a0aed6f288a8a8ce02a674b - name=Name and date of the commit. - manifest_arg=domain=DOMAIN&path=PATH&admin=USER&is_public=1& - - + ; commit=83500d6e866539d56a0aed6f288a8a8ce02a674b + name=Name and date of the commit. + manifest_arg=domain=DOMAIN&path=PATH&admin=USER&is_public=1& diff --git a/manifest.json b/manifest.json index bf3590f..29e984d 100644 --- a/manifest.json +++ b/manifest.json @@ -26,7 +26,7 @@ "multi_instance": true, "services": [ "nginx", - "php7.3-fpm", + "php7.4-fpm", "mysql" ], "arguments": { diff --git a/scripts/_common.sh b/scripts/_common.sh index 8b8c9e3..688e090 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -4,9 +4,12 @@ # COMMON VARIABLES #================================================= -YNH_PHP_VERSION="7.4" +YNH_PHP_VERSION=7.4 -pkg_dependencies="php${YNH_PHP_VERSION}-imagick php${YNH_PHP_VERSION}-curl php${YNH_PHP_VERSION}-bz2 php${YNH_PHP_VERSION}-gd php${YNH_PHP_VERSION}-intl php${YNH_PHP_VERSION}-mysql php${YNH_PHP_VERSION}-zip php${YNH_PHP_VERSION}-apcu-bc php${YNH_PHP_VERSION}-apcu php${YNH_PHP_VERSION}-xml php${YNH_PHP_VERSION}-ldap" +php_dependencies="php${YNH_PHP_VERSION}-imagick php${YNH_PHP_VERSION}-curl php${YNH_PHP_VERSION}-bz2 php${YNH_PHP_VERSION}-gd php${YNH_PHP_VERSION}-intl php${YNH_PHP_VERSION}-mysql php${YNH_PHP_VERSION}-zip php${YNH_PHP_VERSION}-apcu-bc php${YNH_PHP_VERSION}-apcu php${YNH_PHP_VERSION}-xml php${YNH_PHP_VERSION}-ldap" + +# dependencies used by the app (must be on a single line) +pkg_dependencies="$php_dependencies" HUMHUB_AUTH_BASIC_VERSION=0.1.0 HUMHUB_AUTH_BASIC_PATH="/protected/modules/auth-basic" diff --git a/scripts/install b/scripts/install index 3af00f4..36c112d 100644 --- a/scripts/install +++ b/scripts/install @@ -55,7 +55,7 @@ ynh_app_setting_set --app=$app --key=admin --value=$admin #================================================= # INSTALL DEPENDENCIES #================================================= -ynh_script_progression --message="Installing dependencies..." +ynh_script_progression --message="Installing dependencies..." --weight=1 ynh_install_app_dependencies $pkg_dependencies @@ -149,25 +149,25 @@ ynh_script_progression --message="Finalizing installation..." --weight=2 install_sso pushd $final_path/protected - php${YNH_PHP_VERSION} yii migrate/up --includeModuleMigrations=1 --interactive=0 + php$phpversion yii migrate/up --includeModuleMigrations=1 --interactive=0 - php${YNH_PHP_VERSION} yii settings/set ldap enabled '1' - php${YNH_PHP_VERSION} yii settings/set ldap hostname 'localhost' - php${YNH_PHP_VERSION} yii settings/set ldap port 389 - php${YNH_PHP_VERSION} yii settings/set ldap encryption '' - php${YNH_PHP_VERSION} yii settings/set ldap username '' - php${YNH_PHP_VERSION} yii settings/set ldap password '' - php${YNH_PHP_VERSION} yii settings/set ldap baseDn 'ou=users,dc=yunohost,dc=org' - php${YNH_PHP_VERSION} yii settings/set ldap loginFilter '(uid=%s)' - php${YNH_PHP_VERSION} yii settings/set ldap userFilter 'objectClass=mailAccount' - php${YNH_PHP_VERSION} yii settings/set ldap emailAttribute 'mail' - php${YNH_PHP_VERSION} yii settings/set ldap usernameAttribute 'uid' - php${YNH_PHP_VERSION} yii settings/set ldap idAttribute 'uid' - php${YNH_PHP_VERSION} yii settings/set ldap refreshUsers '1' - php${YNH_PHP_VERSION} yii settings/set ldap refreshUsers '1' + php$phpversion yii settings/set ldap enabled '1' + php$phpversion yii settings/set ldap hostname 'localhost' + php$phpversion yii settings/set ldap port 389 + php$phpversion yii settings/set ldap encryption '' + php$phpversion yii settings/set ldap username '' + php$phpversion yii settings/set ldap password '' + php$phpversion yii settings/set ldap baseDn 'ou=users,dc=yunohost,dc=org' + php$phpversion yii settings/set ldap loginFilter '(uid=%s)' + php$phpversion yii settings/set ldap userFilter 'objectClass=mailAccount' + php$phpversion yii settings/set ldap emailAttribute 'mail' + php$phpversion yii settings/set ldap usernameAttribute 'uid' + php$phpversion yii settings/set ldap idAttribute 'uid' + php$phpversion yii settings/set ldap refreshUsers '1' + php$phpversion yii settings/set ldap refreshUsers '1' - php${YNH_PHP_VERSION} yii ldap/sync - php${YNH_PHP_VERSION} yii user/make-admin ${admin} + php$phpversion yii ldap/sync + php$phpversion yii user/make-admin ${admin} ynh_local_curl "/index.php?r=installer/index/go" @@ -181,11 +181,11 @@ pushd $final_path/protected local_curl_csrf "/index.php?r=installer/config/sample-data" \ "SampleDataForm[sampleData]=0" - php${YNH_PHP_VERSION} yii settings/set user auth.anonymousRegistration '0' - php${YNH_PHP_VERSION} yii settings/set user auth.allowGuestAccess '0' - php${YNH_PHP_VERSION} yii settings/set user auth.internalUsersCanInvite '0' + php$phpversion yii settings/set user auth.anonymousRegistration '0' + php$phpversion yii settings/set user auth.allowGuestAccess '0' + php$phpversion yii settings/set user auth.internalUsersCanInvite '0' - php${YNH_PHP_VERSION} yii module/enable auth-basic + php$phpversion yii module/enable auth-basic popd @@ -194,20 +194,17 @@ ynh_permission_update --permission="main" --remove="visitors" ynh_store_file_checksum --file="$final_path/protected/config/common.php" -#================================================= -# SETUP CRON CONFIGURATION -#================================================= - -ynh_add_config --template="../conf/cron" --destination="/etc/cron.d/${app}" - -#================================================= -# SECURE FILES AND DIRECTORIES -#================================================= - chmod 750 "$final_path" chmod -R o-rwx "$final_path" chown -R $app:www-data "$final_path" +#================================================= +# SETUP CRON CONFIGURATION +#================================================= +ynh_script_progression --message="Setuping crontab..." --weight=1 + +ynh_add_config --template="../conf/cron" --destination="/etc/cron.d/${app}" + #================================================= # GENERIC FINALIZATION #================================================= diff --git a/scripts/restore b/scripts/restore index 60f6fd4..98a4b85 100644 --- a/scripts/restore +++ b/scripts/restore @@ -68,7 +68,7 @@ chown -R $app:www-data "$final_path" #================================================= # 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 @@ -99,7 +99,7 @@ ynh_mysql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < ./ #================================================= # RESTORE VARIOUS FILES #================================================= -ynh_script_progression --message="Restoring various files..." +ynh_script_progression --message="Restoring various files..." --weight=1 ynh_restore_file --origin_path="/etc/cron.d/$app" diff --git a/scripts/upgrade b/scripts/upgrade index be9537b..d3448cb 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -94,26 +94,12 @@ then # Delete old source ynh_secure_remove --file="$final_path.old" - - if [[ ! -d $final_path/$HUMHUB_AUTH_BASIC_PATH ]]; then - install_sso - - pushd $final_path/protected - php${YNH_PHP_VERSION} yii module/enable auth-basic - popd - else - current_version=$(cat $final_path/$HUMHUB_AUTH_BASIC_PATH/module.json | jq -j '.version') - if [ "$current_version" != "$HUMHUB_AUTH_BASIC_VERSION" ]; then - ynh_secure_remove $final_path/$HUMHUB_AUTH_BASIC_PATH - install_sso - fi - fi fi #================================================= # UPGRADE DEPENDENCIES #================================================= -ynh_script_progression --message="Upgrading dependencies..." +ynh_script_progression --message="Upgrading dependencies..." --weight=1 ynh_install_app_dependencies $pkg_dependencies @@ -124,6 +110,7 @@ ynh_script_progression --message="Upgrading PHP-FPM configuration..." --weight=1 # Create a dedicated PHP-FPM config ynh_add_fpm_config +phpversion=$(ynh_app_setting_get --app=$app --key=phpversion) #================================================= # NGINX CONFIGURATION @@ -146,6 +133,29 @@ ynh_replace_string --match_string="defined('YII_ENV') or define('YII_ENV', 'dev' --replace_string="// defined('YII_ENV') or define('YII_ENV', 'dev');"\ --target_file="$final_path/index.php" +#================================================= +# SETUP APPLICATION +#================================================= + +if [ "$upgrade_type" == "UPGRADE_APP" ] +then + ynh_script_progression --message="Setuping application..." --weight=1 + + if [[ ! -d $final_path/$HUMHUB_AUTH_BASIC_PATH ]]; then + install_sso + + pushd $final_path/protected + php$phpversion yii module/enable auth-basic + popd + else + current_version=$(cat $final_path/$HUMHUB_AUTH_BASIC_PATH/module.json | jq -j '.version') + if [ "$current_version" != "$HUMHUB_AUTH_BASIC_VERSION" ]; then + ynh_secure_remove $final_path/$HUMHUB_AUTH_BASIC_PATH + install_sso + fi + fi +fi + #================================================= # MIGRATE DATABASE #================================================= @@ -153,30 +163,26 @@ ynh_script_progression --message="Migrating database..." --weight=1 chown -R $app $final_path/ -sudo -u $app /usr/bin/php$YNH_PHP_VERSION $final_path/protected/yii migrate/up --includeModuleMigrations=1 +sudo -u $app /usr/bin/php$phpversion $final_path/protected/yii migrate/up --includeModuleMigrations=1 #================================================= # UPDATE MODULES #================================================= ynh_script_progression --message="Updating modules..." --weight=1 -sudo -u $app /usr/bin/php$YNH_PHP_VERSION $final_path/protected/yii module/update-all - -#================================================= -# REINSTALL CRONTAB -#================================================= -ynh_script_progression --message="Upgrading crontab..." --weight=1 - -ynh_add_config --template="../conf/cron" --destination="/etc/cron.d/${app}" - -#================================================= -# SECURE FILES AND DIRECTORIES -#================================================= +sudo -u $app /usr/bin/php$phpversion $final_path/protected/yii module/update-all chmod 750 "$final_path" chmod -R o-rwx "$final_path" chown -R $app:www-data "$final_path" +#================================================= +# UPGRADE CRONTAB +#================================================= +ynh_script_progression --message="Upgrading crontab..." --weight=1 + +ynh_add_config --template="../conf/cron" --destination="/etc/cron.d/${app}" + #================================================= # GENERIC FINALIZATION #=================================================