From 173ac0bf4628f34e6b6546e7f1a0bc8fda318f6b Mon Sep 17 00:00:00 2001 From: ericgaspar Date: Wed, 2 Jun 2021 08:53:23 +0200 Subject: [PATCH] Add cconfig --- check_process | 11 ++----- manifest.json | 2 +- scripts/install | 37 ++++++++++-------------- scripts/restore | 25 +++++++--------- scripts/upgrade | 76 ++++++++++++++++--------------------------------- 5 files changed, 55 insertions(+), 96 deletions(-) diff --git a/check_process b/check_process index 432896c..81c87d5 100644 --- a/check_process +++ b/check_process @@ -1,13 +1,8 @@ -# See here for more informations -# https://github.com/YunoHost/package_check#syntax-check_process-file - -# Move this file from check_process.default to check_process when you have filled it. - ;; Test complet ; Manifest - domain="domain.tld" (DOMAIN) - path="/path" (PATH) - admin="john" (USER) + domain="domain.tld" + path="/path" + admin="john" ; Checks pkg_linter=1 setup_sub_dir=1 diff --git a/manifest.json b/manifest.json index 409a9aa..0550669 100644 --- a/manifest.json +++ b/manifest.json @@ -15,7 +15,7 @@ "url": "" }, "requirements": { - "yunohost": ">= 4.1.7" + "yunohost": ">= 4.2.4" }, "previous_maintainers": { "name": "courgette", diff --git a/scripts/install b/scripts/install index 5a3de2d..a3c81c5 100644 --- a/scripts/install +++ b/scripts/install @@ -59,6 +59,14 @@ 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 #================================================= @@ -68,6 +76,10 @@ ynh_app_setting_set --app=$app --key=final_path --value=$final_path # Download, check integrity, uncompress and patch the source from app.src ynh_setup_source --dest_dir="$final_path" +chmod 750 "$final_path" +chmod -R o-rwx "$final_path" +chown -R $app:www-data "$final_path" + #================================================= # NGINX CONFIGURATION #================================================= @@ -75,14 +87,6 @@ ynh_script_progression --message="Configuring NGINX web server..." --weight=2 ynh_add_nginx_config -#================================================= -# CREATE DEDICATED USER -#================================================= -ynh_script_progression --message="Configuring system user..." --weight=1 - -# Create a system user -ynh_system_user_create --username=$app - #================================================= # PHP-FPM CONFIGURATION #================================================= @@ -99,22 +103,11 @@ cp ../conf/index.php $final_path/ # MODIFY A CONFIG FILE #================================================= -cp ../conf/config.php $final_path/user/config.php +path=${path_url%/} +random=$(ynh_string_random 24) -ynh_replace_string --match_string="__DB_NAME__" --replace_string="$db_name" --target_file="$final_path/user/config.php" -ynh_replace_string --match_string="__DB_PWD__" --replace_string="$db_pwd" --target_file="$final_path/user/config.php" -ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="$final_path/user/config.php" -ynh_replace_string --match_string="__PATH__" --replace_string="${path_url%/}" --target_file="$final_path/user/config.php" -ynh_replace_string --match_string="__RANDOM__" --replace_string="$(ynh_string_random 24)" --target_file="$final_path/user/config.php" +ynh_add_config --template="../conf/config.php" --destination="$final_path/user/config.php" -# Calculate and store the config file checksum into the app settings -ynh_store_file_checksum "$final_path/user/config.php" - -#================================================= -# SECURE FILES AND DIRECTORIES -#================================================= - -chown -R $app: $final_path chmod 600 $final_path/user/config.php #================================================= diff --git a/scripts/restore b/scripts/restore index 0b3848f..d1959ce 100644 --- a/scripts/restore +++ b/scripts/restore @@ -51,6 +51,14 @@ test ! -d $final_path \ 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..." --weight=1 + +# Create the dedicated user (if not existing) +ynh_system_user_create --username=$app --home_dir="$final_path" + #================================================= # RESTORE THE APP MAIN DIR #================================================= @@ -58,20 +66,9 @@ ynh_script_progression --message="Restoring YOURLS main directory..." --weight=3 ynh_restore_file --origin_path="$final_path" -#================================================= -# RECREATE THE DEDICATED 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 - -#================================================= -# RESTORE USER RIGHTS -#================================================= - -# Restore permissions on app files -chown -R $app: $final_path +chmod 750 "$final_path" +chmod -R o-rwx "$final_path" +chown -R $app:www-data "$final_path" chmod 600 $final_path/user/config.php #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index 3c98e9b..c5bf391 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -66,34 +66,31 @@ ynh_clean_setup () { # Exit if an error occurs during the execution of the script ynh_abort_if_errors +#================================================= +# CREATE DEDICATED USER +#================================================= +ynh_script_progression --message="Making sure dedicated system user exists..." --weight=3 + +# 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 #================================================= -# Download, check integrity, uncompress and patch the source from app.src -# Create a temporary directory along with /user/plugin sub directory in it -tmpdir="$(mktemp -d)" -mkdir -p "$tmpdir/user/" -# Backup the app files in the temp dir -cp -a "$final_path/index.php" "$tmpdir" -cp -a "$final_path/.htaccess" "$tmpdir" -cp -a "$final_path/user/config.php" "$tmpdir/user" +if [ "$upgrade_type" == "UPGRADE_APP" ] +then + ynh_script_progression --message="Upgrading source files..." --weight=1 -# Remove the app directory securely -ynh_secure_remove --file="$final_path" + # Download, check integrity, uncompress and patch the source from app.src + ynh_setup_source --dest_dir="$final_path" --keep="$final_path/index.php $final_path/.htaccess $final_path/user/config.php" +fi -# Download, check integrity, uncompress and patch the source from app.src -ynh_setup_source --dest_dir="$final_path" - -# Copy the app files from tmp to final_path -cp -a "$tmpdir/index.php" "$final_path" -cp -a "$tmpdir/.htaccess" "$final_path" -cp -a "$tmpdir/user/config.php" "$final_path/user" - -#remove tmp dir -ynh_secure_remove "$tmpdir" +chmod 750 "$final_path" +chmod -R o-rwx "$final_path" +chown -R $app:www-data "$final_path" #================================================= # NGINX CONFIGURATION @@ -102,14 +99,6 @@ ynh_script_progression --message="Upgrading NGINX web server configuration..." - ynh_add_nginx_config -#================================================= -# CREATE DEDICATED USER -#================================================= -ynh_script_progression --message="Making sure dedicated system user exists..." --weight=3 - -# Create a dedicated user (if not existing) -ynh_system_user_create --username=$app - #================================================= # PHP-FPM CONFIGURATION #================================================= @@ -118,32 +107,17 @@ ynh_script_progression --message="Upgrading PHP-FPM configuration..." --weight=4 # Create a dedicated PHP-FPM config ynh_add_fpm_config --package="$extra_php_dependencies" -#================================================= -# MODIFY A CONFIG FILE -#================================================= -ynh_script_progression --message="Modifying a config file..." --weight=2 +# #================================================= +# # MODIFY A CONFIG FILE +# #================================================= +# ynh_script_progression --message="Modifying a config file..." --weight=2 -# Verify the checksum and backup the file if it's different -ynh_backup_if_checksum_is_different --file="$final_path/user/config.php" +# path=${path_url%/} +# random=$(ynh_string_random 24) -cp ../conf/config.php $final_path/user/config.php +# ynh_add_config --template="../conf/config.php" --destination="$final_path/user/config.php" -ynh_replace_string --match_string="__DB_NAME__" --replace_string="$db_name" --target_file="$final_path/user/config.php" -ynh_replace_string --match_string="__DB_PWD__" --replace_string="$db_pwd" --target_file="$final_path/user/config.php" -ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="$final_path/user/config.php" -ynh_replace_string --match_string="__PATH__" --replace_string="${path_url%/}" --target_file="$final_path/user/config.php" -ynh_replace_string --match_string="__RANDOM__" --replace_string="$(ynh_string_random 24)" --target_file="$final_path/user/config.php" - -# Recalculate and store the config file checksum into the app settings -ynh_store_file_checksum --file="$final_path/user/config.php" - -#================================================= -# SECURE FILES AND DIRECTORIES -#================================================= - -# Restore permissions on app files -chown -R $app: $final_path -chmod 600 $final_path/user/config.php +# chmod 600 $final_path/user/config.php #================================================= # RELOAD NGINX