From 1b60657f88465792bd65188463f388b60cab1d67 Mon Sep 17 00:00:00 2001 From: ericgaspar Date: Sun, 20 Jun 2021 23:23:08 +0200 Subject: [PATCH] Fix --- check_process | 11 ++++---- scripts/install | 30 +++++++++------------ scripts/restore | 26 ++++++++---------- scripts/upgrade | 72 +++++++++++++++++++++++-------------------------- 4 files changed, 61 insertions(+), 78 deletions(-) diff --git a/check_process b/check_process index 2306c4b..e3ce2e8 100644 --- a/check_process +++ b/check_process @@ -1,11 +1,11 @@ ;; Nom du test auto_remove=1 ; Manifest - domain="domain.tld" (DOMAIN) - path="/path" (PATH) - is_public=1 (PUBLIC|public=1|private=0) - theme="milligram" (THEME) - password="verysecretpassword" (PASSWORD) + domain="domain.tld" + path="/path" + is_public=1 + theme="milligram" + password="verysecretpassword" ; Checks pkg_linter=1 setup_sub_dir=1 @@ -17,7 +17,6 @@ upgrade=1 from_commit=2d33783907d6de4486ac9e954ebc4b4028e11de8 backup_restore=1 multi_instance=1 - port_already_use=1 (8095) change_url=1 ;;; Upgrade options ; commit=2d33783907d6de4486ac9e954ebc4b4028e11de8 diff --git a/scripts/install b/scripts/install index 42a2d36..cdad896 100644 --- a/scripts/install +++ b/scripts/install @@ -86,6 +86,14 @@ db_user=$db_name ynh_app_setting_set --app=$app --key=db_name --value=$db_name ynh_psql_setup_db --db_user=$db_user --db_name=$db_name +#================================================= +# CREATE DEDICATED USER +#================================================= +ynh_script_progression --message="Configuring system user..." + +# Create a system user +ynh_system_user_create --username=$app --home_dir="$final_path" + #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= @@ -95,6 +103,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 #================================================= @@ -103,14 +115,6 @@ ynh_script_progression --message="Configuring NGINX web server..." # Create a dedicated nginx config ynh_add_nginx_config -#================================================= -# CREATE DEDICATED USER -#================================================= -ynh_script_progression --message="Configuring system user..." - -# Create a system user -ynh_system_user_create --username=$app - #================================================= # SPECIFIC SETUP #================================================= @@ -156,16 +160,6 @@ ynh_script_progression --message="Configuring a systemd service..." # Create a dedicated systemd config ynh_add_systemd_config -#================================================= -# GENERIC FINALIZATION -#================================================= -# SECURE FILES AND DIRECTORIES -#================================================= -ynh_script_progression --message="Securing files and directories..." - -# Set permissions to app files -chown -R $app: $final_path - #================================================= # SETUP LOGROTATE #================================================= diff --git a/scripts/restore b/scripts/restore index 4696e08..209456f 100644 --- a/scripts/restore +++ b/scripts/restore @@ -53,6 +53,14 @@ 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 +#================================================= +ynh_script_progression --message="Recreating the dedicated system user..." + +# Create the dedicated user (if not existing) +ynh_system_user_create --username=$app --home_dir="$final_path" + #================================================= # RESTORE THE APP MAIN DIR #================================================= @@ -60,21 +68,9 @@ ynh_script_progression --message="Restoring the app main directory..." ynh_restore_file --origin_path="$final_path" -#================================================= -# RECREATE THE DEDICATED USER -#================================================= -ynh_script_progression --message="Recreating the dedicated system user..." - -# Create the dedicated user (if not existing) -ynh_system_user_create --username=$app - -#================================================= -# RESTORE USER RIGHTS -#================================================= -ynh_script_progression --message="Restoring user rights..." - -# Restore permissions on app files -chown -R $app: $final_path +chmod 750 "$datadir" +chmod -R o-rwx "$datadir" +chown -R $app:www-data "$datadir" #================================================= # SPECIFIC RESTORATION diff --git a/scripts/upgrade b/scripts/upgrade index 8068ad6..ef57d02 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -119,6 +119,14 @@ ynh_script_progression --message="Stopping a systemd service..." ynh_systemd_action --service_name=$app --action="stop" --log_path="systemd" +#================================================= +# CREATE DEDICATED USER +#================================================= +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" + #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= @@ -128,9 +136,13 @@ then ynh_script_progression --message="Upgrading source files..." # Download, check integrity, uncompress and patch the source from app.src - ynh_setup_source --dest_dir="$final_path" + ynh_setup_source --dest_dir="$final_path" --keep="$final_path/lstu.conf" fi +chmod 750 "$final_path" +chmod -R o-rwx "$final_path" +chown -R $app:www-data "$final_path" + #================================================= # NGINX CONFIGURATION #================================================= @@ -146,42 +158,34 @@ ynh_script_progression --message="Upgrading dependencies..." ynh_install_app_dependencies $pkg_dependencies -#================================================= -# CREATE DEDICATED USER -#================================================= -ynh_script_progression --message="Making sure dedicated system user exists..." - -# Create a dedicated user (if not existing) -ynh_system_user_create --username=$app - #================================================= # SPECIFIC UPGRADE #================================================= # UPGRADE LSTU CONFIGURATION #================================================= -ynh_script_progression --message="Upgrading lstu configuration..." +# ynh_script_progression --message="Upgrading lstu configuration..." -config="${final_path}/lstu.conf" -ynh_backup_if_checksum_is_different --file="$config" -cp ../conf/lstu.conf.template "$config" -ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="$config" -ynh_replace_string --match_string="__PATH__" --replace_string="$path_url" --target_file="$config" -ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="$config" -ynh_replace_string --match_string="__DB_NAME__" --replace_string="$db_name" --target_file="$config" -ynh_replace_string --match_string="__DB_USER__" --replace_string="$db_user" --target_file="$config" -ynh_replace_string --match_string="__DB_PWD__" --replace_string="$db_pwd" --target_file="$config" -ynh_replace_string --match_string="__SELECTED_THEME__" --replace_string="$theme" --target_file="$config" -ynh_replace_string --match_string="__PASSWORD_HASHED__" --replace_string="$hashed_password" --target_file="$config" -ynh_replace_string --match_string="__SECRET__" --replace_string="$secret" --target_file="$config" +# config="${final_path}/lstu.conf" +# ynh_backup_if_checksum_is_different --file="$config" +# cp ../conf/lstu.conf.template "$config" +# ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="$config" +# ynh_replace_string --match_string="__PATH__" --replace_string="$path_url" --target_file="$config" +# ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="$config" +# ynh_replace_string --match_string="__DB_NAME__" --replace_string="$db_name" --target_file="$config" +# ynh_replace_string --match_string="__DB_USER__" --replace_string="$db_user" --target_file="$config" +# ynh_replace_string --match_string="__DB_PWD__" --replace_string="$db_pwd" --target_file="$config" +# ynh_replace_string --match_string="__SELECTED_THEME__" --replace_string="$theme" --target_file="$config" +# ynh_replace_string --match_string="__PASSWORD_HASHED__" --replace_string="$hashed_password" --target_file="$config" +# ynh_replace_string --match_string="__SECRET__" --replace_string="$secret" --target_file="$config" -if [ $is_public -eq 0 ]; -then - ynh_replace_string --match_string="__IS_PUBLIC__" --replace_string="" --target_file="$config" -else - ynh_replace_string --match_string="__IS_PUBLIC__" --replace_string="#" --target_file="$config" -fi +# if [ $is_public -eq 0 ]; +# then +# ynh_replace_string --match_string="__IS_PUBLIC__" --replace_string="" --target_file="$config" +# else +# ynh_replace_string --match_string="__IS_PUBLIC__" --replace_string="#" --target_file="$config" +# fi -ynh_store_file_checksum --file="$config" +# ynh_store_file_checksum --file="$config" #================================================= # BUILD LSU @@ -208,16 +212,6 @@ ynh_script_progression --message="Upgrading systemd configuration..." # Create a dedicated systemd config ynh_add_systemd_config -#================================================= -# GENERIC FINALIZATION -#================================================= -# SECURING FILES AND DIRECTORIES -#================================================= -ynh_script_progression --message="Securing files and directories..." - -# Set permissions on app files -chown -R $app: $final_path - #================================================= # INTEGRATE SERVICE IN YUNOHOST #=================================================