Sfoglia il codice sorgente

Merge pull request #28 from YunoHost-Apps/testing

Testing
Maniack Crudelis 7 anni fa
parent
commit
67faa90abe
8 ha cambiato i file con 318 aggiunte e 26 eliminazioni
  1. 22 0
      actions.json
  2. 3 3
      check_process
  3. 41 0
      config_panel.json
  4. 18 0
      scripts/_common.sh
  5. 68 0
      scripts/actions/reset_default_config
  6. 91 0
      scripts/config
  7. 4 0
      scripts/install
  8. 71 23
      scripts/upgrade

+ 22 - 0
actions.json

@@ -0,0 +1,22 @@
+[{
+		"id": "reset_default_setupvars",
+		"name": "Reset the config file and restore a default one.",
+		"command": "/bin/bash scripts/actions/reset_default_config \"setupVars.conf\"",
+		"user": "root",
+		"accepted_return_codes": [0],
+		"description": {
+			"en": "Reset the config file setupVars.conf.",
+			"fr": "Réinitialise le fichier de configuration setupVars.conf."
+		}
+},
+{
+		"id": "reset_default_ftl",
+		"name": "Reset the config file and restore a default one.",
+		"command": "/bin/bash scripts/actions/reset_default_config \"pihole-FTL.conf\"",
+		"user": "root",
+		"accepted_return_codes": [0],
+		"description": {
+			"en": "Reset the config file pihole-FTL.conf.",
+			"fr": "Réinitialise le fichier de configuration pihole-FTL.conf."
+		}
+}]

+ 3 - 3
check_process

@@ -13,7 +13,7 @@
 		setup_private=1
 		setup_public=0
 		upgrade=1
-		upgrade=1	from_commit=32af3e208d36dd9601dd7a33efab656425822782
+		upgrade=1	from_commit=d79ec131b3038ff4695c3317b5d3ee4eda9c8932
 		backup_restore=1
 		multi_instance=0
 		incorrect_path=1
@@ -35,6 +35,6 @@
 Email=
 Notification=down
 ;;; Upgrade options
-	; commit=32af3e208d36dd9601dd7a33efab656425822782
-		name= Première version du package
+	; commit=d79ec131b3038ff4695c3317b5d3ee4eda9c8932
+		name= Stretch fix
 		manifest_arg=domain=DOMAIN&path=PATH&admin=USER&query_logging=1&

+ 41 - 0
config_panel.json

@@ -0,0 +1,41 @@
+{
+	"name": "PiHole configuration panel",
+	"version": "0.1",
+	"panel": [{
+		"name": "PiHole configuration",
+		"id": "main",
+		"sections": [{
+			"name": "Overwriting config files",
+			"id": "overwrite_files",
+			"options": [{
+				"name": "Overwrite the config file setupVars.conf ?",
+				"help": "If the file is overwritten, a backup will be created.",
+				"id": "overwrite_setupvars",
+				"type": "bool",
+				"default": true
+			},
+			{
+				"name": "Overwrite the config file pihole-FTL.conf ?",
+				"help": "If the file is overwritten, a backup will be created.",
+				"id": "overwrite_ftl",
+				"type": "bool",
+				"default": true
+			},
+			{
+				"name": "Overwrite the nginx config file ?",
+				"help": "If the file is overwritten, a backup will be created.",
+				"id": "overwrite_nginx",
+				"type": "bool",
+				"default": true
+			},
+			{
+				"name": "Overwrite the php-fpm config file ?",
+				"help": "If the file is overwritten, a backup will be created.",
+				"id": "overwrite_phpfpm",
+				"type": "bool",
+				"default": true
+			}]
+		}]
+	}
+]
+}

+ 18 - 0
scripts/_common.sh

@@ -30,6 +30,24 @@ IS_PACKAGE_CHECK () {
 	return $(env | grep -c container=lxc)
 }
 
+#=================================================
+# BOOLEAN CONVERTER
+#=================================================
+
+bool_to_01 () {
+	local var="$1"
+	[ "$var" = "true" ] && var=1
+	[ "$var" = "false" ] && var=0
+	echo "$var"
+}
+
+bool_to_true_false () {
+	local var="$1"
+	[ "$var" = "1" ] && var=true
+	[ "$var" = "0" ] && var=false
+	echo "$var"
+}
+
 #=================================================
 # EXPERIMENTAL HELPERS
 #=================================================

+ 68 - 0
scripts/actions/reset_default_config

@@ -0,0 +1,68 @@
+#!/bin/bash
+
+#=================================================
+# GENERIC STARTING
+#=================================================
+# IMPORT GENERIC HELPERS
+#=================================================
+
+source scripts/_common.sh
+source /usr/share/yunohost/helpers
+
+#=================================================
+# RETRIEVE ARGUMENTS
+#=================================================
+
+app=${YNH_APP_INSTANCE_NAME:-$YNH_APP_ID}
+query_logging=$(ynh_app_setting_get $app query_logging)
+
+#=================================================
+# SORT OUT THE CONFIG FILE TO HANDLE
+#=================================================
+
+file="$1"
+
+if [ "$file" = "setupVars.conf" ]; then
+	config_file="/etc/pihole/setupVars.conf"
+elif [ "$file" = "pihole-FTL.conf" ]; then
+	config_file="/etc/pihole/pihole-FTL.conf"
+fi
+
+#=================================================
+# SPECIFIC ACTION
+#=================================================
+# RESET THE CONFIG FILE
+#=================================================
+
+# Verify the checksum and backup the file if it's different
+ynh_backup_if_checksum_is_different "$config_file"
+
+if [ "$file" = "setupVars.conf" ]
+then
+	# Recreate the default config
+	# Trouve l'interface réseau par défaut
+	main_iface=$(ip route | grep default | awk '{print $5;}')
+	echo "PIHOLE_INTERFACE=$main_iface" > "$config_file"
+	echo "IPV4_ADDRESS=127.0.0.1" >> "$config_file"
+	echo "IPV6_ADDRESS=" >> "$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
+	cp /etc/yunohost/apps/$app/conf/pihole-FTL.conf "$config_file"
+
+	# Restart pihole-FTL
+	ynh_system_reload --service_name=pihole-FTL --action=restart
+fi
+
+# Calculate and store the config file checksum into the app settings
+ynh_store_file_checksum "$config_file"

+ 91 - 0
scripts/config

@@ -0,0 +1,91 @@
+#!/bin/bash
+
+#=================================================
+# GENERIC STARTING
+#=================================================
+# IMPORT GENERIC HELPERS
+#=================================================
+
+source _common.sh
+source /usr/share/yunohost/helpers
+
+#=================================================
+# RETRIEVE ARGUMENTS
+#=================================================
+
+app=${YNH_APP_INSTANCE_NAME:-$YNH_APP_ID}
+
+#=================================================
+# SPECIFIC CODE
+#=================================================
+# LOAD VALUES
+#=================================================
+
+# Load the real value from the app config or elsewhere.
+# Then get the value from the form.
+# If the form has a value for a variable, take the value from the form,
+# Otherwise, keep the value from the app config.
+
+# Overwrite setupVars.conf file
+old_overwrite_setupvars="$(ynh_app_setting_get $app overwrite_setupvars)"
+old_overwrite_setupvars=$(bool_to_true_false $old_overwrite_setupvars)
+overwrite_setupvars="${YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_SETUPVARS:-$old_overwrite_setupvars}"
+
+# Overwrite pihole-FTL.conf file
+old_overwrite_ftl="$(ynh_app_setting_get $app overwrite_ftl)"
+old_overwrite_ftl=$(bool_to_true_false $old_overwrite_ftl)
+overwrite_ftl="${YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_FTL:-$old_overwrite_ftl}"
+
+# Overwrite nginx configuration
+old_overwrite_nginx="$(ynh_app_setting_get $app overwrite_nginx)"
+old_overwrite_nginx=$(bool_to_true_false $old_overwrite_nginx)
+overwrite_nginx="${YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_NGINX:-$old_overwrite_nginx}"
+
+# Overwrite php-fpm configuration
+old_overwrite_phpfpm="$(ynh_app_setting_get $app overwrite_phpfpm)"
+old_overwrite_phpfpm=$(bool_to_true_false $old_overwrite_phpfpm)
+overwrite_phpfpm="${YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_PHPFPM:-$old_overwrite_phpfpm}"
+
+#=================================================
+# SHOW_CONFIG FUNCTION FOR 'SHOW' COMMAND
+#=================================================
+
+show_config() {
+	# here you are supposed to read some config file/database/other then print the values
+	# echo "YNH_CONFIG_${PANEL_ID}_${SECTION_ID}_${OPTION_ID}=value"
+
+	echo "YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_SETUPVARS=$overwrite_setupvars"
+	echo "YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_FTL=$overwrite_ftl"
+	echo "YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_NGINX=$overwrite_nginx"
+	echo "YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_PHPFPM=$overwrite_phpfpm"
+}
+
+#=================================================
+# MODIFY THE CONFIGURATION
+#=================================================
+
+apply_config() {
+	# Set overwrite_setupvars
+	overwrite_setupvars=$(bool_to_01 $overwrite_setupvars)
+	ynh_app_setting_set $app overwrite_setupvars "$overwrite_setupvars"
+	# Set overwrite_ftl
+	overwrite_ftl=$(bool_to_01 $overwrite_ftl)
+	ynh_app_setting_set $app overwrite_ftl "$overwrite_ftl"
+	# Set overwrite_nginx
+	overwrite_nginx=$(bool_to_01 $overwrite_nginx)
+	ynh_app_setting_set $app overwrite_nginx "$overwrite_nginx"
+	# Set overwrite_phpfpm
+	overwrite_phpfpm=$(bool_to_01 $overwrite_phpfpm)
+	ynh_app_setting_set $app overwrite_phpfpm "$overwrite_phpfpm"
+}
+
+#=================================================
+# GENERIC FINALIZATION
+#=================================================
+# SELECT THE ACTION FOLLOWING THE GIVEN ARGUMENT
+#=================================================
+
+case $1 in
+  show) show_config;;
+  apply) apply_config;;
+esac

+ 4 - 0
scripts/install

@@ -53,6 +53,10 @@ ynh_app_setting_set $app path $path_url
 ynh_app_setting_set $app admin $admin
 ynh_app_setting_set $app query_logging $query_logging
 ynh_app_setting_set $app enable_dhcp $enable_dhcp
+ynh_app_setting_set $app overwrite_setupvars "1"
+ynh_app_setting_set $app overwrite_ftl "1"
+ynh_app_setting_set $app overwrite_nginx "1"
+ynh_app_setting_set $app overwrite_phpfpm "1"
 
 #=================================================
 # STANDARD MODIFICATIONS

+ 71 - 23
scripts/upgrade

@@ -23,6 +23,10 @@ admin=$(ynh_app_setting_get $app admin)
 query_logging=$(ynh_app_setting_get $app query_logging)
 final_path=$(ynh_app_setting_get $app final_path)
 port=$(ynh_app_setting_get $app port)
+overwrite_setupvars=$(ynh_app_setting_get $app overwrite_setupvars)
+overwrite_ftl=$(ynh_app_setting_get $app overwrite_ftl)
+overwrite_nginx=$(ynh_app_setting_get $app overwrite_nginx)
+overwrite_phpfpm=$(ynh_app_setting_get $app overwrite_phpfpm)
 
 #=================================================
 # CHECK VERSION
@@ -30,6 +34,34 @@ port=$(ynh_app_setting_get $app port)
 
 upgrade_type=$(ynh_check_app_version_changed)
 
+#=================================================
+# ENSURE DOWNWARD COMPATIBILITY
+#=================================================
+
+# If overwrite_setupvars doesn't exist, create it
+if [ -z "$overwrite_setupvars" ]; then
+	overwrite_setupvars=1
+	ynh_app_setting_set $app overwrite_setupvars $overwrite_setupvars
+fi
+
+# If overwrite_ftl doesn't exist, create it
+if [ -z "$overwrite_ftl" ]; then
+	overwrite_ftl=1
+	ynh_app_setting_set $app overwrite_ftl $overwrite_ftl
+fi
+
+# If overwrite_nginx doesn't exist, create it
+if [ -z "$overwrite_nginx" ]; then
+	overwrite_nginx=1
+	ynh_app_setting_set $app overwrite_nginx $overwrite_nginx
+fi
+
+# If overwrite_phpfpm doesn't exist, create it
+if [ -z "$overwrite_phpfpm" ]; then
+	overwrite_phpfpm=1
+	ynh_app_setting_set $app overwrite_phpfpm $overwrite_phpfpm
+fi
+
 #=================================================
 # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
 #=================================================
@@ -67,10 +99,10 @@ ynh_install_app_dependencies $app_depencencies
 # DOWNLOAD, CHECK AND UNPACK SOURCE
 #=================================================
 
+pihole_local_repo="/etc/.pihole"
 if [ "$upgrade_type" == "UPGRADE_APP" ]
 then
 	# Update la copie du repo de pihole (nécessaire pour Gravity)
-	pihole_local_repo="/etc/.pihole"
 	ynh_setup_source "$pihole_local_repo"
 	# Update le dashboard admin
 	ynh_setup_source "$final_path" admin_dashboard
@@ -80,7 +112,11 @@ fi
 # NGINX CONFIGURATION
 #=================================================
 
-ynh_add_nginx_config
+# Overwrite the nginx configuration only if it's allowed
+if [ $overwrite_nginx -eq 1 ]
+then
+	ynh_add_nginx_config
+fi
 
 #=================================================
 # CREATE DEDICATED USER
@@ -92,7 +128,11 @@ ynh_system_user_create $app	# Create the dedicated user, if not exist
 # PHP-FPM CONFIGURATION
 #=================================================
 
-ynh_add_fpm_config	# Créer le fichier de configuration du pool php-fpm et le configure.
+# Overwrite the php-fpm configuration only if it's allowed
+if [ $overwrite_phpfpm -eq 1 ]
+then
+	ynh_add_fpm_config	# Créer le fichier de configuration du pool php-fpm et le configure.
+fi
 
 #=================================================
 # SPECIFIC UPGRADE
@@ -152,9 +192,13 @@ then
 	ynh_secure_remove "$FTL_temp_path"
 fi
 
-ynh_backup_if_checksum_is_different "$pihole_storage/pihole-FTL.conf"	# Créé un backup du fichier de config si il a été modifié.
-cp "../conf/pihole-FTL.conf" "$pihole_storage"
-ynh_store_file_checksum "$pihole_storage/pihole-FTL.conf"	# Enregistre la somme de contrôle du fichier de config
+# Overwrite the pihole-FTL config file only if it's allowed
+if [ $overwrite_ftl -eq 1 ]
+then
+	ynh_backup_if_checksum_is_different "$pihole_storage/pihole-FTL.conf"	# Créé un backup du fichier de config si il a été modifié.
+	cp "../conf/pihole-FTL.conf" "$pihole_storage"
+	ynh_store_file_checksum "$pihole_storage/pihole-FTL.conf"	# Enregistre la somme de contrôle du fichier de config
+fi
 
 cp -a $pihole_local_repo/advanced/pihole-FTL.service /etc/init.d/pihole-FTL
 chmod +x /etc/init.d/pihole-FTL
@@ -166,24 +210,28 @@ ynh_exec_warn_less systemctl enable pihole-FTL
 
 setupVars="$pihole_storage/setupVars.conf"
 
-ynh_backup_if_checksum_is_different "$setupVars"	# Créé un backup du fichier de config si il a été modifié.
-
-# Trouve l'interface réseau par défaut
-main_iface=$(ip route | grep default | awk '{print $5;}')
-echo "PIHOLE_INTERFACE=$main_iface" > $setupVars
-echo "IPV4_ADDRESS=127.0.0.1" >> $setupVars
-echo "IPV6_ADDRESS=" >> $setupVars
-echo "PIHOLE_DNS_1=" >> $setupVars
-echo "PIHOLE_DNS_2=" >> $setupVars
-if [ $query_logging -eq 1 ]; then
-	query_logging=true
-else
-	query_logging=false
+# Overwrite the setupVars config file only if it's allowed
+if [ $overwrite_setupvars -eq 1 ]
+then
+	ynh_backup_if_checksum_is_different "$setupVars"	# Créé un backup du fichier de config si il a été modifié.
+
+	# Trouve l'interface réseau par défaut
+	main_iface=$(ip route | grep default | awk '{print $5;}')
+	echo "PIHOLE_INTERFACE=$main_iface" > $setupVars
+	echo "IPV4_ADDRESS=127.0.0.1" >> $setupVars
+	echo "IPV6_ADDRESS=" >> $setupVars
+	echo "PIHOLE_DNS_1=" >> $setupVars
+	echo "PIHOLE_DNS_2=" >> $setupVars
+	if [ $query_logging -eq 1 ]; then
+		query_logging=true
+	else
+		query_logging=false
+	fi
+	echo "QUERY_LOGGING=$query_logging" >> $setupVars
+	echo "INSTALL_WEB=true" >> $setupVars
+
+	ynh_store_file_checksum "$setupVars"	# Enregistre la somme de contrôle du fichier de config
 fi
-echo "QUERY_LOGGING=$query_logging" >> $setupVars
-echo "INSTALL_WEB=true" >> $setupVars
-
-ynh_store_file_checksum "$setupVars"	# Enregistre la somme de contrôle du fichier de config
 
 #=================================================
 # UPDATE THE CRON JOB