Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added more checks to scripts and output more system information #1456

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Update system information and check IPv6 address.
  • Loading branch information
tdulcet committed Jul 27, 2019
commit b53a10d085d5d6fd28ee2484824484dd6ef810c2
74 changes: 52 additions & 22 deletions setup/network-checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,38 +6,68 @@ 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

# Stop if the IPv4 address is listed in the ZEN Spamhouse Block List.
# 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.
Expand Down
3 changes: 2 additions & 1 deletion setup/preflight.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
15 changes: 9 additions & 6 deletions setup/questions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ address, so we're suggesting $DEFAULT_PRIMARY_HOSTNAME.
RE='^.+\.localdomain$'
tdulcet marked this conversation as resolved.
Show resolved Hide resolved
# 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
Expand Down Expand Up @@ -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[*]}"
Expand All @@ -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"
Expand Down