Skip to content

Commit

Permalink
Merge pull request #206 from thomasmerz/issue_188_fix_SC2034_and_SC2154
Browse files Browse the repository at this point in the history
Fix Issue 188 by enabling and fixing SC2034 and SC2154 shellcheck warnings
  • Loading branch information
yubiuser committed Mar 25, 2022
2 parents df43fb0 + 0cc4928 commit a2d1b7e
Showing 1 changed file with 10 additions and 22 deletions.
32 changes: 10 additions & 22 deletions padd.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
#!/usr/bin/env bash
# shellcheck disable=SC2034
# shellcheck disable=SC1091
# shellcheck disable=SC2154

# PADD
#
# A more advanced version of the chronometer provided with Pihole

# SETS LOCALE
Expand Down Expand Up @@ -38,14 +35,12 @@ core_count=$(cat /sys/devices/system/cpu/kernel_max 2> /dev/null)+1

# COLORS
CSI="$(printf '\033')["
black_text="${CSI}90m" # Black
red_text="${CSI}91m" # Red
green_text="${CSI}92m" # Green
yellow_text="${CSI}93m" # Yellow
blue_text="${CSI}94m" # Blue
magenta_text="${CSI}95m" # Magenta
cyan_text="${CSI}96m" # Cyan
white_text="${CSI}97m" # White
reset_text="${CSI}0m" # Reset to default

# STYLES
Expand Down Expand Up @@ -98,16 +93,13 @@ mega_status_unknown="${check_box_question} Unable to determine Pi-hole status."
# TINY STATUS
tiny_status_ok="${check_box_good} System is healthy."
tiny_status_update="${check_box_info} Updates are available."
tiny_status_hot="${check_box_bad} System is hot!"
tiny_status_off="${check_box_bad} Pi-hole is offline"
tiny_status_ftl_down="${check_box_info} FTL is down!"
tiny_status_dns_down="${check_box_bad} DNS is off!"
tiny_status_unknown="${check_box_question} Status unknown!"

# Text only "logos"
padd_text="${green_text}${bold_text}PADD${reset_text}"
padd_text_retro="${bold_text}${red_text}P${yellow_text}A${green_text}D${blue_text}D${reset_text}${reset_text}"
mini_text_retro="${dim_text}${cyan_text}m${magenta_text}i${red_text}n${yellow_text}i${reset_text}"

# PADD logos - regular and retro
padd_logo_1="${bold_text}${green_text} __ __ __ ${reset_text}"
Expand All @@ -117,13 +109,6 @@ padd_logo_retro_1="${bold_text} ${yellow_text}_${green_text}_ ${blue_text}_
padd_logo_retro_2="${bold_text}${yellow_text}|${green_text}_${blue_text}_${cyan_text}) ${red_text}/${yellow_text}\\ ${blue_text}| ${red_text}\\${yellow_text}| ${cyan_text}\\ ${reset_text}"
padd_logo_retro_3="${bold_text}${green_text}| ${red_text}/${yellow_text}-${green_text}-${blue_text}\\${cyan_text}|${magenta_text}_${red_text}_${yellow_text}/${green_text}|${blue_text}_${cyan_text}_${magenta_text}/ ${reset_text}"

# old script Pi-hole logos - regular and retro
pihole_logo_script_1="${bold_text}${green_text}.-.. . . ${reset_text}"
pihole_logo_script_2="${bold_text}${green_text}|-'. - |-. .-.| .-, ${reset_text}"
pihole_logo_script_3="${bold_text}${green_text}' ' ' '-\`-''-\`'- ${reset_text}"
pihole_logo_script_retro_1="${red_text}.${yellow_text}-${green_text}.${blue_text}. ${green_text}. ${magenta_text}. ${reset_text}"
pihole_logo_script_retro_2="${yellow_text}|${green_text}-${blue_text}'${magenta_text}. ${yellow_text}- ${blue_text}|${magenta_text}-${red_text}. ${green_text}.${blue_text}-${magenta_text}.${red_text}| ${green_text}.${blue_text}-${magenta_text}, ${reset_text}"
pihole_logo_script_retro_3="${green_text}' ${red_text}' ${magenta_text}' ${yellow_text}'${green_text}-${blue_text}\`${magenta_text}-${red_text}'${yellow_text}'${green_text}-${blue_text}\`${magenta_text}'${red_text}- ${reset_text}"

############################################# GETTERS ##############################################

Expand Down Expand Up @@ -158,7 +143,7 @@ GetFTLData() {

GetSummaryInformation() {
local summary
local cache_summary
local cache_info
summary=$(GetFTLData "stats")
cache_info=$(GetFTLData "cacheinfo")

Expand Down Expand Up @@ -330,7 +315,7 @@ GetNetworkInformation() {

full_hostname=${pi_hostname}
# does the Pi-hole have a domain set?
if ! [ -z ${PIHOLE_DOMAIN+x} ]; then
if [ -n "${PIHOLE_DOMAIN+x}" ]; then
# is Pi-hole acting as DHCP server?
if [[ "${DHCP_ACTIVE}" == "true" ]]; then
count=${pi_hostname}"."${PIHOLE_DOMAIN}
Expand Down Expand Up @@ -376,6 +361,8 @@ GetNetworkInformation() {
dhcp_check_box=${check_box_good}

# Is DHCP handling IPv6?
# DHCP_IPv6 is set in setupVars.conf
# shellcheck disable=SC2154
if [[ "${DHCP_IPv6}" == "true" ]]; then
dhcp_ipv6_status="Enabled"
dhcp_ipv6_heatmap=${green_text}
Expand Down Expand Up @@ -409,22 +396,18 @@ GetNetworkInformation() {
if [[ "${DNSSEC}" == "true" ]]; then
dnssec_status="Enabled"
dnssec_heatmap=${green_text}
dnssec_check_box=${check_box_good}
else
dnssec_status="Disabled"
dnssec_heatmap=${red_text}
dnssec_check_box=${check_box_bad}
fi

# Conditional forwarding
if [[ "${CONDITIONAL_FORWARDING}" == "true" ]] || [[ "${REV_SERVER}" == "true" ]]; then
conditional_forwarding_status="Enabled"
conditional_forwarding_heatmap=${green_text}
conditional_forwarding_check_box=${check_box_good}
else
conditional_forwarding_status="Disabled"
conditional_forwarding_heatmap=${red_text}
conditional_forwarding_check_box=${check_box_bad}
fi
}

Expand Down Expand Up @@ -497,6 +480,8 @@ GetVersionInformation() {
today=$(date +%Y%m%d)

# was the last check today?
# last_check is read from ./piHoleVersion
# shellcheck disable=SC2154
if [ "${today}" != "${last_check}" ]; then # no, it wasn't today
# Remove the Pi-hole version file...
rm -f piHoleVersion
Expand Down Expand Up @@ -659,6 +644,8 @@ CleanEcho() {
# wrapper - printf
CleanPrintf() {
# tput el
# disabling shellcheck here because we pass formatting instructions within `"${@}"`
# shellcheck disable=SC2059
printf "$@"
}

Expand Down Expand Up @@ -1054,7 +1041,8 @@ json_extract() {
local pair_regex="\"${key}\"[[:space:]]*:[[:space:]]*(${value_regex})"

if [[ ${json} =~ ${pair_regex} ]]; then
echo $(sed 's/^"\|"$//g' <<< "${BASH_REMATCH[1]}")
# remove leading and trailing quotes
sed -e 's/^"//' -e 's/"$//' <<<"${BASH_REMATCH[1]}"
else
return 1
fi
Expand Down

0 comments on commit a2d1b7e

Please sign in to comment.