From 703208bef26f4a3ceeef1058ba7d107a9f264872 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Sun, 3 Sep 2023 14:42:57 +0200 Subject: [PATCH] More cleanup / trying to fix php during restore --- manifest.json | 2 +- scripts/_common.sh | 0 scripts/actions/reset_default_app | 224 --------------------------- scripts/actions/reset_default_config | 87 ----------- scripts/actions/reset_default_system | 64 -------- scripts/backup | 1 - scripts/install | 4 +- scripts/remove | 0 scripts/restore | 11 +- scripts/upgrade | 48 +----- 10 files changed, 9 insertions(+), 432 deletions(-) mode change 100755 => 100644 scripts/_common.sh delete mode 100755 scripts/actions/reset_default_app delete mode 100755 scripts/actions/reset_default_config delete mode 100755 scripts/actions/reset_default_system mode change 100755 => 100644 scripts/remove diff --git a/manifest.json b/manifest.json index 132b10d..3822c07 100644 --- a/manifest.json +++ b/manifest.json @@ -26,7 +26,7 @@ } ], "requirements": { - "yunohost": ">= 11.2" + "yunohost": ">= 11.2.4" }, "multi_instance": false, "services": [ diff --git a/scripts/_common.sh b/scripts/_common.sh old mode 100755 new mode 100644 diff --git a/scripts/actions/reset_default_app b/scripts/actions/reset_default_app deleted file mode 100755 index 4bcce48..0000000 --- a/scripts/actions/reset_default_app +++ /dev/null @@ -1,224 +0,0 @@ -#!/bin/bash - -#================================================= -# GENERIC STARTING -#================================================= -# IMPORT GENERIC HELPERS -#================================================= - -# Load common variables for all scripts. -source scripts/_common.sh -source /usr/share/yunohost/helpers - -#================================================= -# MANAGE SCRIPT FAILURE -#================================================= - -ynh_clean_setup () { -# Clean installation remaining that are not handle by the remove script. - ynh_clean_check_starting -} -# Exit if an error occurs during the execution of the script -ynh_abort_if_errors - -#================================================= -# RETRIEVE ARGUMENTS -#================================================= - -app=$YNH_APP_INSTANCE_NAME - -path_url=$(ynh_app_setting_get --app=$app --key=path) -domain=$(ynh_app_setting_get --app=$app --key=domain) -final_path=$(ynh_app_setting_get --app=$app --key=final_path) - -#================================================= -# SPECIFIC ACTION -#================================================= -# ACTIVATE MAINTENANCE MODE -#================================================= -ynh_script_progression --message="Activating maintenance mode..." --weight=1 - -ynh_maintenance_mode_ON - -#================================================= -# CREATE DEDICATED USER -#================================================= -ynh_script_progression --message="Making sure dedicated system user exists..." --weight=1 - -# Create a dedicated user (if not existing) -ynh_system_user_create --username=$app - -#================================================= -# DOWNLOAD, CHECK AND UNPACK SOURCE -#================================================= -ynh_script_progression --message="Resetting source files..." --weight=1 - -# Download, check integrity, uncompress and patch the source from app.src -( - cd scripts - # Overwrite the last version available - YNH_CWD=$PWD ynh_setup_source --dest_dir="$PI_HOLE_LOCAL_REPO" --source_id="pi-hole_Core" - # Overwrite admin dashboard - YNH_CWD=$PWD ynh_setup_source --dest_dir="$final_path" --source_id=pi-hole_AdminLTE - - chown $app:www-data "$final_path" - -) - -#================================================= -# NGINX CONFIGURATION -#================================================= -ynh_script_progression --message="Resetting NGINX web server configuration..." --weight=1 - -# Create a dedicated nginx config -yunohost app action run $app reset_default_nginx - -#================================================= -# PHP-FPM CONFIGURATION -#================================================= -ynh_script_progression --message="Resetting PHP-FPM configuration..." --weight=1 - -# Create a dedicated php-fpm config -yunohost app action run $app reset_default_phpfpm - -#================================================= -# RECREATE DIRECTORIES -#================================================= -ynh_script_progression --message="Recreating and populating directories..." --weight=1 - -mkdir -p "$PI_HOLE_CONFIG_DIR" -chown $app: -R "$PI_HOLE_CONFIG_DIR" - -mkdir -p "$PI_HOLE_INSTALL_DIR" - -# Make a copy of Pi-Hole scripts -cp -a "$PI_HOLE_LOCAL_REPO/gravity.sh" "$PI_HOLE_INSTALL_DIR/" -cp -a $PI_HOLE_LOCAL_REPO/advanced/Scripts/*.sh "$PI_HOLE_INSTALL_DIR/" - -# And copy this fucking COL_TABLE file... -cp -a "$PI_HOLE_LOCAL_REPO/advanced/Scripts/COL_TABLE" "$PI_HOLE_INSTALL_DIR/" - -#================================================= -# COPY PI-HOLE MAIN SCRIPT -#================================================= -ynh_script_progression --message="Copying Pi-Hole main script..." - -cp -a "$PI_HOLE_LOCAL_REPO/pihole" $PI_HOLE_BIN_DIR/ -cp -a "$PI_HOLE_LOCAL_REPO/advanced/bash-completion/pihole" /etc/bash_completion.d/pihole - -#================================================= -# RECREATE LOG FILES -#================================================= - -touch /var/log/{pihole,pihole-FTL}.log -chmod 644 /var/log/{pihole,pihole-FTL}.log -dnsmasq_user=$(grep DNSMASQ_USER= /etc/init.d/dnsmasq | cut -d'"' -f2) -chown $dnsmasq_user:root /var/log/{pihole,pihole-FTL}.log - -#================================================= -# RECREATE SUDOER FILE -#================================================= - -# This sudoers config allow pihole to execute $PI_HOLE_BIN_DIR/pihole as root without password. Nothing more. -cp "$PI_HOLE_LOCAL_REPO/advanced/Templates/pihole.sudo" /etc/sudoers.d/pihole -echo "$app ALL=NOPASSWD: $PI_HOLE_BIN_DIR/pihole" >> /etc/sudoers.d/pihole -# echo "Defaults secure_path = /sbin:/bin:/usr/sbin:/usr/bin:$PI_HOLE_BIN_DIR" >> /etc/sudoers.d/pihole -chmod 0440 /etc/sudoers.d/pihole - -#================================================= -# REINSTALL LOGROTATE SCRIPT FOR PI-HOLE -#================================================= - -cp "$PI_HOLE_LOCAL_REPO/advanced/Templates/logrotate" "$PI_HOLE_CONFIG_DIR/logrotate" -sed -i "/# su #/d;" "$PI_HOLE_CONFIG_DIR/logrotate" - -#================================================= -# REINSTALLATION OF PIHOLE-FTL -#================================================= -ynh_script_progression --message="Reinstalling PiHole-FTL..." --weight=30 - -# Get the source of Pi-Hole-FTL -FTL_temp_path=$(mktemp -d) -# Install the last version available -ynh_setup_source --dest_dir="$FTL_temp_path" --source_id="pi-hole_FTL" - -# Instead of downloading a binary file, we're going to compile it -( - cd "$FTL_temp_path" - ynh_exec_warn_less make - ynh_exec_warn_less make install -) -ynh_secure_remove --file="$FTL_temp_path" - -cp "../conf/dns-servers.conf" "$PI_HOLE_CONFIG_DIR" - -# Restore the default pihole-FTL.conf -yunohost app action run $app reset_default_ftl - -cp -a $PI_HOLE_LOCAL_REPO/advanced/Templates/pihole-FTL.service /etc/init.d/pihole-FTL -chmod +x /etc/init.d/pihole-FTL -ynh_exec_warn_less systemctl enable pihole-FTL - -# Reload systemd config -systemctl daemon-reload - -#================================================= -# RESET THE VARIABLES FILE -#================================================= - -# Restore the default setupVars.conf -yunohost app action run $app reset_default_setupvars - -#================================================= -# RESET DNSMASQ CONFIG -#================================================= - -# Restore the default setupVars.conf -yunohost app action run $app reset_default_dnsmasq - -#================================================= -# REINSTALL CRON JOB -#================================================= - -cp $PI_HOLE_LOCAL_REPO/advanced/Templates/pihole.cron /etc/cron.d/pihole - -# Remove git usage for version. Which fails because we use here a release instead of master. -ynh_replace_string --match_string=".*updatechecker.*" --replace_string="#&" --target_file=/etc/cron.d/pihole - -#================================================= -# REINSTALL CONF_REGEN HOOK -#================================================= - -( - cd scripts - cp ../conf/dnsmasq_regenconf_hook /usr/share/yunohost/hooks/conf_regen/50-dnsmasq_$app - ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file="/usr/share/yunohost/hooks/conf_regen/50-dnsmasq_$app" -) - -#================================================= -# RESTART PIHOLE-FTL -#================================================= - -ynh_script_progression --message="Restarting PiHole-FTL..." --weight=2 - -ynh_systemd_action --service_name=pihole-FTL --action=restart --log_path="/var/log/pihole-FTL.log" - -#================================================= -# RELOAD NGINX -#================================================= -ynh_script_progression --message="Reloading NGINX web server..." --weight=1 - -ynh_systemd_action --service_name=nginx --action=reload - -#================================================= -# DEACTIVE MAINTENANCE MODE -#================================================= -ynh_script_progression --message="Disabling maintenance mode..." --weight=1 - -ynh_maintenance_mode_OFF - -#================================================= -# END OF SCRIPT -#================================================= - -ynh_script_progression --message="Execution completed" --last diff --git a/scripts/actions/reset_default_config b/scripts/actions/reset_default_config deleted file mode 100755 index 2360ee3..0000000 --- a/scripts/actions/reset_default_config +++ /dev/null @@ -1,87 +0,0 @@ -#!/bin/bash - -#================================================= -# GENERIC STARTING -#================================================= -# IMPORT GENERIC HELPERS -#================================================= - -source scripts/_common.sh -source /usr/share/yunohost/helpers - -#================================================= -# MANAGE SCRIPT FAILURE -#================================================= - -# Exit if an error occurs during the execution of the script -ynh_abort_if_errors - -#================================================= -# RETRIEVE ARGUMENTS -#================================================= - -app=$YNH_APP_INSTANCE_NAME - -query_logging=$(ynh_app_setting_get --app=$app --key=query_logging) - -#================================================= -# SORT OUT THE CONFIG FILE TO HANDLE -#================================================= - -file="$1" - -if [ "$file" = "setupVars.conf" ]; then - config_file="$PI_HOLE_CONFIG_DIR/setupVars.conf" -elif [ "$file" = "pihole-FTL.conf" ]; then - config_file="$PI_HOLE_CONFIG_DIR/pihole-FTL.conf" -fi - -#================================================= -# SPECIFIC ACTION -#================================================= -# RESET THE CONFIG FILE -#================================================= -ynh_script_progression --message="Resetting the config file $config_file..." --weight=9 - -# Verify the checksum and backup the file if it's different -ynh_backup_if_checksum_is_different --file="$config_file" - -main_iface=$(ip route | grep --max-count=1 default | awk '{print $5;}') - -if [ "$file" = "setupVars.conf" ] -then - # Recreate the default config - # Trouve l'interface réseau par défaut - echo "PIHOLE_INTERFACE=$main_iface" > "$config_file" - echo "IPV4_ADDRESS=127.0.0.1" >> "$config_file" - echo "IPV6_ADDRESS=::1" >> "$config_file" - echo "PIHOLE_DNS_1=" >> "$config_file" - echo "PIHOLE_DNS_2=" >> "$config_file" - if [ $query_logging -eq 1 ]; then - query_logging=true - else - query_logging=false - fi - echo "QUERY_LOGGING=$query_logging" >> "$config_file" - echo "INSTALL_WEB=true" >> "$config_file" - -elif [ "$file" = "pihole-FTL.conf" ] -then - # Get the default file and overwrite the current config - port=$(ynh_app_setting_get --app=$app --key=port) - ynh_add_config --template="/etc/yunohost/apps/$app/conf/pihole-FTL.conf" --destination="$config_file" - - ynh_script_progression --message="Restarting Pi-Hole..." --weight=2 - - # Restart pihole-FTL - ynh_systemd_action --service_name=pihole-FTL --action=restart --log_path="/var/log/pihole-FTL.log" -fi - -# Calculate and store the config file checksum into the app settings -ynh_store_file_checksum --file="$config_file" - -#================================================= -# END OF SCRIPT -#================================================= - -ynh_script_progression --message="Execution completed" --last diff --git a/scripts/actions/reset_default_system b/scripts/actions/reset_default_system deleted file mode 100755 index 46de6a4..0000000 --- a/scripts/actions/reset_default_system +++ /dev/null @@ -1,64 +0,0 @@ -#!/bin/bash - -#================================================= -# GENERIC STARTING -#================================================= -# IMPORT GENERIC HELPERS -#================================================= - -source scripts/_common.sh -source /usr/share/yunohost/helpers - -#================================================= -# MANAGE SCRIPT FAILURE -#================================================= - -ynh_clean_setup () { -# Clean installation remaining that are not handle by the remove script. - ynh_clean_check_starting -} -# Exit if an error occurs during the execution of the script -ynh_abort_if_errors - -#================================================= -# RETRIEVE ARGUMENTS -#================================================= - -app=$YNH_APP_INSTANCE_NAME - -type=$1 - -domain=$(ynh_app_setting_get --app=$app --key=domain) -path_url=$(ynh_app_setting_get --app=$app --key=path) -final_path=$(ynh_app_setting_get --app=$app --key=final_path) - -#================================================= -# SPECIFIC ACTION -#================================================= -# RESET THE CONFIG FILE -#================================================= - -if [ $type == nginx ]; then - name=Nginx -elif [ $type == phpfpm ]; then - name=PHP-FPM -else - ynh_die --message="The type $type is not recognized" -fi - -ynh_script_progression --message="Resetting the specific configuration of $name for the app $app..." --weight=3 - -if [ $type == nginx ] -then - (cd scripts; ynh_add_nginx_config) - -elif [ $type == phpfpm ] -then - (cd scripts; ynh_add_fpm_config --usage=low --footprint=low --dedicated_service) -fi - -#================================================= -# END OF SCRIPT -#================================================= - -ynh_script_progression --message="Execution completed" --last diff --git a/scripts/backup b/scripts/backup index 00a4d71..286bc4d 100644 --- a/scripts/backup +++ b/scripts/backup @@ -53,7 +53,6 @@ ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" # BACKUP THE PHP-FPM CONFIGURATION #================================================= -ynh_backup --src_path="$fpm_config_dir/php-fpm-$app.conf" ynh_backup --src_path="$fpm_config_dir/pool.d/$app.conf" #================================================= diff --git a/scripts/install b/scripts/install index f70634a..1769d83 100644 --- a/scripts/install +++ b/scripts/install @@ -55,8 +55,6 @@ ynh_app_setting_set --app=$app --key=enable_dhcp --value=$enable_dhcp ynh_app_setting_set --app=$app --key=overwrite_setupvars --value=1 ynh_app_setting_set --app=$app --key=overwrite_ftl --value=1 -ynh_app_setting_set --app=$app --key=overwrite_nginx --value=1 -ynh_app_setting_set --app=$app --key=overwrite_phpfpm --value=1 #================================================= # STANDARD MODIFICATIONS @@ -117,7 +115,7 @@ chown -R $app:www-data "$final_path" ynh_script_progression --message="Configuring PHP-FPM..." --weight=2 # Create a dedicated PHP-FPM config -ynh_add_fpm_config --usage=low --footprint=low --dedicated_service +ynh_add_fpm_config #================================================= # NGINX CONFIGURATION diff --git a/scripts/remove b/scripts/remove old mode 100755 new mode 100644 diff --git a/scripts/restore b/scripts/restore index 5bd6d36..68b75fb 100644 --- a/scripts/restore +++ b/scripts/restore @@ -33,11 +33,6 @@ final_path=$(ynh_app_setting_get --app=$app --key=final_path) enable_dhcp=$(ynh_app_setting_get --app=$app --key=enable_dhcp) admin=$(ynh_app_setting_get --app=$app --key=admin) -# Get variables from ynh_add_fpm_config -fpm_footprint=$(ynh_app_setting_get --app=$app --key=fpm_footprint) -fpm_usage=$(ynh_app_setting_get --app=$app --key=fpm_usage) -fpm_config_dir=$(ynh_app_setting_get --app=$app --key=fpm_config_dir) - #================================================= # CHECK IF THE APP CAN BE RESTORED #================================================= @@ -110,11 +105,7 @@ ynh_install_app_dependencies $pkg_dependencies ynh_script_progression --message="Restoring the PHP-FPM configuration..." --weight=7 # Restore the file first, so it can have a backup if different -ynh_restore_file --origin_path="$fpm_config_dir/php-fpm-$app.conf" -ynh_restore_file --origin_path="$fpm_config_dir/pool.d/$app.conf" - -# Recreate a dedicated php-fpm config -#ynh_add_fpm_config --usage=$fpm_usage --footprint=$fpm_footprint +ynh_add_fpm_config #================================================= # RESTORE THE NGINX CONFIGURATION diff --git a/scripts/upgrade b/scripts/upgrade index ec42e59..adf5ec9 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -27,10 +27,6 @@ pihole_version="$(ynh_app_setting_get --app=$app --key=pihole_version)" overwrite_setupvars=$(ynh_app_setting_get --app=$app --key=overwrite_setupvars) overwrite_ftl=$(ynh_app_setting_get --app=$app --key=overwrite_ftl) -overwrite_nginx=$(ynh_app_setting_get --app=$app --key=overwrite_nginx) -overwrite_phpfpm=$(ynh_app_setting_get --app=$app --key=overwrite_phpfpm) -fpm_footprint=$(ynh_app_setting_get --app=$app --key=fpm_footprint) -fpm_usage=$(ynh_app_setting_get --app=$app --key=fpm_usage) #================================================= # CHECK VERSION @@ -79,36 +75,12 @@ if [ -z "$overwrite_ftl" ]; then ynh_app_setting_set --app=$app --key=overwrite_ftl --value=$overwrite_ftl fi -# If overwrite_nginx doesn't exist, create it -if [ -z "$overwrite_nginx" ]; then - overwrite_nginx=1 - ynh_app_setting_set --app=$app --key=overwrite_nginx --value=$overwrite_nginx -fi - -# If overwrite_phpfpm doesn't exist, create it -if [ -z "$overwrite_phpfpm" ]; then - overwrite_phpfpm=1 - ynh_app_setting_set --app=$app --key=overwrite_phpfpm --value=$overwrite_phpfpm -fi - # If admin_mail_html doesn't exist, create it if [ -z "$admin_mail_html" ]; then admin_mail_html=1 ynh_app_setting_set --app=$app --key=admin_mail_html --value=$admin_mail_html fi -# If fpm_footprint doesn't exist, create it -if [ -z "$fpm_footprint" ]; then - fpm_footprint=low - ynh_app_setting_set --app=$app --key=fpm_footprint --value=$fpm_footprint -fi - -# If fpm_usage doesn't exist, create it -if [ -z "$fpm_usage" ]; then - fpm_usage=low - ynh_app_setting_set --app=$app --key=fpm_usage --value=$fpm_usage -fi - # If pihole_version doesn't exist, create it if [ -z "$pihole_version" ]; then pihole_version="Last 3.X" @@ -151,25 +123,17 @@ ynh_install_app_dependencies $pkg_dependencies # PHP-FPM CONFIGURATION #================================================= -# Overwrite the PHP-FPM configuration only if it's allowed -if [ $overwrite_phpfpm -eq 1 ] -then - ynh_script_progression --message="Upgrading PHP-FPM configuration..." --weight=3 - # Create a dedicated PHP-FPM config - ynh_add_fpm_config --usage=$fpm_usage --footprint=$fpm_footprint --dedicated_service -fi +ynh_script_progression --message="Upgrading PHP-FPM configuration..." --weight=3 +# Create a dedicated PHP-FPM config +ynh_add_fpm_config #================================================= # NGINX CONFIGURATION #================================================= -# Overwrite the NGINX configuration only if it's allowed -if [ $overwrite_nginx -eq 1 ] -then - ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=2 - # Create a dedicated NGINX config - ynh_add_nginx_config -fi +ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=2 +# Create a dedicated NGINX config +ynh_add_nginx_config #================================================= # SPECIFIC UPGRADE