From b53a10d085d5d6fd28ee2484824484dd6ef810c2 Mon Sep 17 00:00:00 2001 From: Teal Dulcet Date: Sat, 27 Jul 2019 01:03:15 -0700 Subject: [PATCH] Update system information and check IPv6 address. --- setup/network-checks.sh | 74 +++++++++++++++++++++++++++++------------ setup/preflight.sh | 3 +- setup/questions.sh | 15 +++++---- 3 files changed, 63 insertions(+), 29 deletions(-) diff --git a/setup/network-checks.sh b/setup/network-checks.sh index 428fa4ca..a91a6641 100644 --- a/setup/network-checks.sh +++ b/setup/network-checks.sh @@ -6,15 +6,15 @@ apt_get_quiet install bind9-host sed netcat-openbsd # The user might have chosen a name that was previously in use by a spammer # and will not be able to reliably send mail. Do this after any automatic # choices made above. -if host $PRIMARY_HOSTNAME.dbl.spamhaus.org > /dev/null; then - echo - echo "The hostname you chose '$PRIMARY_HOSTNAME' is listed in the" - echo "Spamhaus Domain Block List. See http://www.spamhaus.org/dbl/" - echo "and http://www.spamhaus.org/query/domain/$PRIMARY_HOSTNAME." - echo - echo "You will not be able to send mail using this domain name, so" - echo "setup cannot continue." - echo +if host "$PRIMARY_HOSTNAME.dbl.spamhaus.org" > /dev/null; then + echo >&2 + echo "The hostname you chose '$PRIMARY_HOSTNAME' is listed in the" >&2 + echo "Spamhaus Domain Block List. See http://www.spamhaus.org/dbl/" >&2 + echo "and http://www.spamhaus.org/query/domain/$PRIMARY_HOSTNAME." >&2 + echo >&2 + echo "You will not be able to send mail using this domain name, so" >&2 + echo "setup cannot continue." >&2 + echo >&2 exit 1 fi @@ -22,22 +22,52 @@ fi # The user might have ended up on an IP address that was previously in use # by a spammer, or the user may be deploying on a residential network. We # will not be able to reliably send mail in these cases. -REVERSED_IPV4=$(echo $PUBLIC_IP | sed "s/\([0-9]*\).\([0-9]*\).\([0-9]*\).\([0-9]*\)/\4.\3.\2.\1/") -if host $REVERSED_IPV4.zen.spamhaus.org > /dev/null; then - echo - echo "The IP address $PUBLIC_IP is listed in the Spamhaus Block List." - echo "See http://www.spamhaus.org/query/ip/$PUBLIC_IP." - echo - echo "You will not be able to send mail using this machine, so setup" - echo "cannot continue." - echo - echo "Associate a different IP address with this machine if possible." - echo "Many residential network IP addresses are listed, so Mail-in-a-Box" - echo "typically cannot be used on a residential Internet connection." - echo +# Adapted from: https://github.com/tdulcet/Remote-Servers-Status/blob/master/status.sh +REVERSED_IPV4=$(echo "$PUBLIC_IP" | awk -F'.' '{for(i=NF;i>0;i--) printf "%s%s",$i,(i==1?"\n":".")}') +if host "$REVERSED_IPV4.zen.spamhaus.org" > /dev/null; then + output=$(dig +short txt "$REVERSED_IPV4.zen.spamhaus.org" 2>&1) && [[ -n "$output" ]] && mapfile -t reasons < <(echo "$output" | grep -v '^;') + echo >&2 + echo "The IP address $PUBLIC_IP is listed in the Spamhaus Block List." >&2 + if [[ -n "$reasons" ]]; then + echo "Reason: ${reasons[*]}" >&2 + fi + echo "See http://www.spamhaus.org/query/ip/$PUBLIC_IP." >&2 + echo >&2 + echo "You will not be able to send mail using this machine, so setup" >&2 + echo "cannot continue." >&2 + echo >&2 + echo "Associate a different IP address with this machine if possible." >&2 + echo "Many residential network IP addresses are listed, so Mail-in-a-Box" >&2 + echo "typically cannot be used on a residential Internet connection." >&2 + echo >&2 exit 1 fi +# Stop if the IPv6 address is listed in the ZEN Spamhouse Block List. +# Adapted from: https://github.com/tdulcet/Remote-Servers-Status/blob/master/status.sh +if [ -n "$PUBLIC_IPV6" ]; then + # Expand and reverse IPv6 address, adapted from: https://gist.github.com/lsowen/4447d916fd19cbb7fce4 + REVERSED_IPV6=$(echo "$PUBLIC_IPV6" | awk -F: 'BEGIN{OFS="";}{addCount = 9 - NF; for(i=1;i<=NF;i++) {if(length($i) == 0) {for(j=1;j<=addCount;j++) {$i = ($i "0000");}} else{$i = substr(("0000" $i), length($i)+5-4);}}; print}' | awk -F '' 'BEGIN{OFS=".";}{for(i=NF;i>0;i--) printf "%s%s",$i,(i==1?"\n":".")}') + if host "$REVERSED_IPV6.zen.spamhaus.org" > /dev/null; then + output=$(dig +short txt "$REVERSED_IPV6.zen.spamhaus.org" 2>&1) && [[ -n "$output" ]] && mapfile -t reasons < <(echo "$output" | grep -v '^;') + echo >&2 + echo "The IP address $PUBLIC_IPV6 is listed in the Spamhaus Block List." >&2 + if [[ -n "$reasons" ]]; then + echo "Reason: ${reasons[*]}" >&2 + fi + echo "See http://www.spamhaus.org/query/ip/$PUBLIC_IPV6." >&2 + echo >&2 + echo "You will not be able to send mail using this machine, so setup" >&2 + echo "cannot continue." >&2 + echo >&2 + echo "Associate a different IP address with this machine if possible." >&2 + echo "Many residential network IP addresses are listed, so Mail-in-a-Box" >&2 + echo "typically cannot be used on a residential Internet connection." >&2 + echo >&2 + exit 1 + fi +fi + # Stop if we cannot make an outbound connection on port 25. Many residential # networks block outbound port 25 to prevent their network from sending spam. # See if we can reach one of Google's MTAs with a 5-second timeout. diff --git a/setup/preflight.sh b/setup/preflight.sh index 8339da4f..9c6bfa0f 100644 --- a/setup/preflight.sh +++ b/setup/preflight.sh @@ -25,7 +25,8 @@ if ! echo "$ID" | grep -iq "ubuntu" || ! echo "$VERSION_ID" | grep -iq "18.04"; fi # Check for the Windows Subsystem for Linux (WSL) -if uname -r | grep -iq "microsoft"; then +KERNEL=$(uname -r) +if echo "$KERNEL" | grep -iq "microsoft"; then echo "Warning: The Windows Subsystem for Linux (WSL) is not yet fully supported by this script." fi diff --git a/setup/questions.sh b/setup/questions.sh index 598c5bf4..ea613279 100644 --- a/setup/questions.sh +++ b/setup/questions.sh @@ -81,7 +81,7 @@ address, so we're suggesting $DEFAULT_PRIMARY_HOSTNAME. RE='^.+\.localdomain$' # Regular expressions to check if the hostname is a valid FQDN RE1='^.{4,253}$' - RE2='^([[:alnum:]][[:alnum:]\-]{0,61}[[:alnum:]]\.)+[a-zA-Z]{2,63}$' + RE2='^((xn--)?[[:alnum:]][[:alnum:]\-]{0,61}[[:alnum:]]\.)+(xn--)?[a-zA-Z]{2,63}$' if [ -z "$PRIMARY_HOSTNAME" ]; then # user hit ESC/cancel exit 1 @@ -203,18 +203,21 @@ if [ -z "${STORAGE_ROOT:-}" ]; then fi # Show the configuration, since the user may have not entered it manually. +# Adapted from: https://github.com/tdulcet/Linux-System-Information/blob/master/info.sh echo -e "\nLinux Distribution:\t\t${PRETTY_NAME:-$ID-$VERSION_ID}" -CPU=( $(sed -n 's/^model name[[:space:]]*: *//p' /proc/cpuinfo | uniq) ) +echo -e "Linux Kernel:\t\t\t$KERNEL" +mapfile -t CPU < <(sed -n 's/^model name[[:space:]]*: *//p' /proc/cpuinfo | uniq) if [ -n "$CPU" ]; then echo -e "Processor (CPU):\t\t${CPU[*]}" fi -CPU_CORES=$(nproc --all) -echo -e "CPU Cores:\t\t\t$CPU_CORES" +CPU_THREADS=$(nproc --all) +CPU_CORES=$(( CPU_THREADS / $(lscpu | grep -i '^thread(s) per core' | sed -n 's/^.\+:[[:blank:]]*//p') )) +echo -e "CPU Cores/Threads:\t\t$CPU_CORES/$CPU_THREADS" echo -e "Architecture:\t\t\t$HOSTTYPE (${ARCHITECTURE}-bit)" echo -e "Total memory (RAM):\t\t$(printf "%'d" $((TOTAL_PHYSICAL_MEM / 1024))) MiB ($(printf "%'d" $((((TOTAL_PHYSICAL_MEM * 1024) / 1000) / 1000))) MB)" echo -e "Total swap space:\t\t$(printf "%'d" $((TOTAL_SWAP / 1024))) MiB ($(printf "%'d" $((((TOTAL_SWAP * 1024) / 1000) / 1000))) MB)" if command -v lspci >/dev/null; then - GPU=( $(lspci 2>/dev/null | grep -i 'vga\|3d\|2d' | sed -n 's/^.*: //p') ) + mapfile -t GPU < <(lspci 2>/dev/null | grep -i 'vga\|3d\|2d' | sed -n 's/^.*: //p') fi if [ -n "$GPU" ]; then echo -e "Graphics Processor (GPU):\t${GPU[*]}" @@ -239,7 +242,7 @@ else echo -e "Private IP Address:\t\t$PRIVATE_IP" fi fi -TIME_ZONE=$(timedatectl 2>/dev/null | grep -i 'time zone\|timezone' | sed -n 's/^.*: //p') +TIME_ZONE=$(timedatectl 2>/dev/null | grep -i 'time zone:\|timezone:' | sed -n 's/^.*: //p') echo -e "Time zone:\t\t\t$TIME_ZONE\n" if command -v systemd-detect-virt >/dev/null && CONTAINER=$(systemd-detect-virt -c); then echo -e "Virtualization container:\t$CONTAINER\n"