From c422dde26d2a60af94596e1c6cc22356a57cb1ab Mon Sep 17 00:00:00 2001 From: Bruno21 Date: Thu, 11 Apr 2024 08:28:18 +0200 Subject: [PATCH] Cosmetics corrections --- sync_pihole_lan.sh | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/sync_pihole_lan.sh b/sync_pihole_lan.sh index a2c9b36..fe39385 100755 --- a/sync_pihole_lan.sh +++ b/sync_pihole_lan.sh @@ -11,6 +11,7 @@ box="\033[1;41m" redbold="\033[1;31m" redbox="\033[1;41m" green="\033[0;32m" +greenbold="\033[1;32m" reset="\033[0m" @@ -23,6 +24,8 @@ not_used=("ds916" "musiiic" "tunes" "notif" "pastefy") pihole1=192.168.2.116 pihole2=192.168.2.216 +echo -e "${greenbold}Sync_pihole_lan.sh synchronise the /etc/pihole/lan.list file with your Zones DNS ...${reset}\n" + cat < /dev/null > /dev/tcp/1.1.1.1/53 if [[ $? -ne 0 ]]; then echo -e "\n${red}No Internet connection !${reset}" @@ -35,7 +38,7 @@ fi echo -e "${bold}Backup ${italic}lan.list...${reset}" ping -q -c1 "$pihole1" &>/dev/null && ssh -p51322 root@"$pihole1" "cat /etc/pihole/lan.list" > lan.list.1 || echo -e "\n${red}Pihole1 is unreachable !'${reset}" -ping -q -c1 "$pihole2" &>/dev/null && ssh -p51522 root@"$pihole2" "cat /etc/pihole/lan.list" > lan.list.2 || echo -e "\n${red}Pihole2 is unreachable !'${reset}" +ping -q -c1 "$pihole2" &>/dev/null && ssh -p51522 root@"$pihole2" "cat /etc/pihole/lan.list" > lan.list.2 || echo -e "${red}Pihole2 is unreachable !'${reset}" if [ -f lan.list.bak ]; then @@ -55,7 +58,7 @@ else fi nb_dynhost=$(awk 'END { print NR }' lan.list) -echo "$nb_dynhost dynhost found in lan.list !" +echo -e "\n$nb_dynhost dynhost found in lan.list !" # Suppression des 'not_required' et 'not_used' dans le lan.list @@ -89,7 +92,8 @@ if [ ${#delete[@]} -ge 1 ]; then nb_dynhost=$(awk 'END { print NR }' lan.list) echo "$nb_dynhost dynhost found in lan.list !" fi - echo "" +else + echo "None" fi @@ -112,15 +116,15 @@ while IFS= read -r line; do done <<< "$dynhost_list" -echo -echo -e "${bold}Update ${italic}lan.list...${reset}" -echo -e "${green}Not required: ${not_required[@]}${reset}" -echo -e "${italic}Not used: ${not_used[@]}${reset}" -echo -e "${red}Missing: ${absent[@]}${reset}" if [ ${#absent[@]} -ge 1 ]; then + echo -e "${bold}Update ${italic}lan.list...${reset}" + echo -e "${green}Not required: ${not_required[@]}${reset}" + echo -e "${italic}Not used: ${not_used[@]}${reset}" + echo -e "${red}Missing: ${absent[@]}${reset}" + [ -f /tmp/temp_file.list ] && rm /tmp/temp_file.list for val in ${absent[@]} @@ -129,12 +133,13 @@ if [ ${#absent[@]} -ge 1 ]; then done cat /tmp/temp_file.list >> lan.list + cat lan.list | sort -k2 > lan.list.sorted + mv lan.list.sorted lan.list + else - echo -e "\n${green}No new dynhost !${reset}" + echo -e "${green}No new dynhost !${reset}" fi -cat lan.list | sort -k2 > lan.list.sorted -mv lan.list.sorted lan.list echo echo -e "${bold}Display ${italic}lan.list...${reset}" @@ -144,7 +149,7 @@ nb_dynhost=$(awk 'END { print NR }' lan.list) echo -e "$nb_dynhost dynhost !\n" -a=$(echo -e "Do you want to export ${italic}lan.list${reset} to ${bold}pihole1${reset} and ${bold}pihole2${reset} ? (y/n)") +a=$(echo -e "Do you want to export ${italic}lan.list${reset} to ${bold}pihole1${reset} ($pihole1) and ${bold}pihole2${reset} ($pihole2) ? (y/n)") read -p "$a" choice if [ "$choice" == "y" ] || [ "$choice" == "Y" ]; then @@ -156,6 +161,8 @@ if [ "$choice" == "y" ] || [ "$choice" == "Y" ]; then echo "Restarting dns on pihole1..." ssh -p51322 root@"$pihole1" 'pihole restartdns' [ $? != 0 ] && echo -e "${red}Error during restarting dns on pihole1 ($pihole1)${reset}" || echo -e "${green}Ok${reset}" + else + echo -e "\n${red}Pihole1 is unreachable !'${reset}" fi @@ -167,6 +174,8 @@ if [ "$choice" == "y" ] || [ "$choice" == "Y" ]; then echo "Restarting dns on pihole2..." ssh -p51522 root@"$pihole2" 'pihole restartdns' [ $? != 0 ] && echo -e "${red}Error during restarting dns on pihole2 ($pihole2)${reset}" || echo -e "${green}Ok${reset}" + else + echo -e "n${red}Pihole2 is unreachable !'${reset}" fi else echo -e "OK, let's continue..."