From 2e680284a414c1b110705f0d73e3354626d87193 Mon Sep 17 00:00:00 2001 From: Miraty Date: Sun, 6 Mar 2022 02:54:51 +0100 Subject: [PATCH] Change permissions with a dedicated function --- scripts/_common.sh | 14 ++++++++++++++ scripts/install | 6 ++---- scripts/restore | 10 ++++------ scripts/upgrade | 7 ++----- 4 files changed, 22 insertions(+), 15 deletions(-) create mode 100644 scripts/_common.sh diff --git a/scripts/_common.sh b/scripts/_common.sh new file mode 100644 index 0000000..f56b2c6 --- /dev/null +++ b/scripts/_common.sh @@ -0,0 +1,14 @@ +libreqr_apply_filesystem_permissions() { + find "$final_path" -type f -exec chmod 400 "{}" + + find "$final_path" -type f -exec chown www-data:www-data "{}" + + find "$final_path" -type d -exec chmod 110 "{}" + + find "$final_path" -type d -exec chown $app:www-data "{}" + + find "$final_path" -type f -name "*.php" -exec chmod 400 "{}" + + find "$final_path" -type f -name "*.php" -exec chown $app:$app "{}" + + find "$final_path" -type f -name "*.css" -exec chmod 440 "{}" + + find "$final_path" -type f -name "*.css" -exec chown $app:www-data "{}" + + find "$final_path" -type f -name "*.less" -exec chmod 440 "{}" + + find "$final_path" -type f -name "*.less" -exec chown $app:www-data "{}" + + chmod 350 "$final_path"/css + chown $app:www-data "$final_path"/css +} diff --git a/scripts/install b/scripts/install index ebcdae1..e56f14e 100755 --- a/scripts/install +++ b/scripts/install @@ -1,4 +1,5 @@ #!/bin/bash +source _common.sh source /usr/share/yunohost/helpers ynh_abort_if_errors @@ -23,10 +24,7 @@ ynh_system_user_create --username=$app --home_dir="$final_path" ynh_script_progression --message="Setting up source files..." ynh_setup_source --dest_dir="$final_path" -chmod -R 440 "$final_path" -find "$final_path" -type d | xargs chmod 110 -chmod 750 "$final_path"/css -chown -R $app:www-data "$final_path" +libreqr_apply_filesystem_permissions ynh_script_progression --message="Configuring NGINX web server..." ynh_add_nginx_config diff --git a/scripts/restore b/scripts/restore index e7faba4..2f94f48 100755 --- a/scripts/restore +++ b/scripts/restore @@ -1,9 +1,10 @@ #!/bin/bash +source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers ynh_abort_if_errors -ynh_script_progression --message="Loading installation settings..." --weight=1 +ynh_script_progression --message="Loading installation settings..." app=$YNH_APP_INSTANCE_NAME domain=$(ynh_app_setting_get --app=$app --key=domain) path_url=$(ynh_app_setting_get --app=$app --key=path) @@ -15,16 +16,13 @@ ynh_system_user_create --username=$app --home_dir="$final_path" ynh_script_progression --message="Restoring the app main directory..." ynh_restore_file --origin_path="$final_path" -chmod -R 440 "$final_path" -find "$final_path" -type d | xargs chmod 110 -chmod 750 "$final_path"/css -chown -R $app:www-data "$final_path" +libreqr_apply_filesystem_permissions ynh_script_progression --message="Restoring the PHP-FPM configuration..." ynh_restore_file --origin_path="/etc/php/$phpversion/fpm/pool.d/$app.conf" ynh_systemd_action --service_name=php$phpversion-fpm --action=reload -ynh_script_progression --message="Restoring the NGINX configuration..." --weight=1 +ynh_script_progression --message="Restoring the NGINX configuration..." ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" ynh_systemd_action --service_name=nginx --action=reload diff --git a/scripts/upgrade b/scripts/upgrade index 65a03f9..2306faa 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -1,4 +1,5 @@ #!/bin/bash +source _common.sh source /usr/share/yunohost/helpers ynh_script_progression --message="Loading installation settings..." @@ -31,11 +32,7 @@ then ynh_secure_remove --file="$final_path" ynh_setup_source --dest_dir="$final_path" fi - -chmod -R 440 "$final_path" -find "$final_path" -type d | xargs chmod 110 -chmod 750 "$final_path"/css -chown -R $app:www-data "$final_path" +libreqr_apply_filesystem_permissions ynh_script_progression --message="Upgrading NGINX web server configuration..." ynh_add_nginx_config