From fdbc6595278bfaf437c8814f41fac3f32a8ad4b6 Mon Sep 17 00:00:00 2001 From: Cisien Date: Sat, 3 Nov 2018 16:30:46 -0700 Subject: [PATCH 1/4] switch to using hping3 for connectivity testing/ip resolution --- pi-gen-sources/00-packages | 3 ++- run/archiveloop | 2 +- run/cifs_archive/verify-archive-configuration.sh | 2 +- run/lookup-ip-address.sh | 2 +- setup/pi/make-root-fs-readonly.sh | 8 -------- setup/pi/setup-teslausb | 13 +++++++++++++ 6 files changed, 18 insertions(+), 12 deletions(-) diff --git a/pi-gen-sources/00-packages b/pi-gen-sources/00-packages index 700b896..8beff5f 100644 --- a/pi-gen-sources/00-packages +++ b/pi-gen-sources/00-packages @@ -1 +1,2 @@ -dos2unix \ No newline at end of file +dos2unix +hping3 \ No newline at end of file diff --git a/run/archiveloop b/run/archiveloop index 81b313a..22da133 100644 --- a/run/archiveloop +++ b/run/archiveloop @@ -26,7 +26,7 @@ function fix_errors_in_mounted_files () { function archive_is_reachable () { local reachable=true - ping -q -w 1 -c 1 "$ARCHIVE_HOST_NAME" > /dev/null 2>&1 || reachable=false + hping3 -c 1 -S -p 445 "$ARCHIVE_HOST_NAME" > /dev/null 2>&1 || reachable=false if [ "$reachable" = false ] then false diff --git a/run/cifs_archive/verify-archive-configuration.sh b/run/cifs_archive/verify-archive-configuration.sh index bf8b9f2..d08e09e 100644 --- a/run/cifs_archive/verify-archive-configuration.sh +++ b/run/cifs_archive/verify-archive-configuration.sh @@ -3,7 +3,7 @@ function check_archive_server_reachable () { echo "Verifying that the archive server $archiveserver is reachable..." local serverunreachable=false - ping -c 1 -w 1 "$archiveserver" 1>/dev/null 2>&1 || serverunreachable=true + hping3 -c 1 -S -p 445 "$archiveserver" 1>/dev/null 2>&1 || serverunreachable=true if [ "$serverunreachable" = true ] then diff --git a/run/lookup-ip-address.sh b/run/lookup-ip-address.sh index 41b8f5a..a09e374 100644 --- a/run/lookup-ip-address.sh +++ b/run/lookup-ip-address.sh @@ -1,3 +1,3 @@ #!/bin/bash -eu -echo "$(ping -c 1 -w 1 $1 2>/dev/null | head -n 1 | grep -o -e "(\([[:digit:]]\{1,3\}\.\)\{3\}[[:digit:]]\{1,3\})" | tr -d '()')" \ No newline at end of file +echo "$(hping3 -c 1 -S -p 445 -n $1 2>/dev/null | head -n 1 | grep -o -e "\W\([[:digit:]]\{1,3\}\.\)\{3\}[[:digit:]]\{1,3\})" | tr -d ' )')" \ No newline at end of file diff --git a/setup/pi/make-root-fs-readonly.sh b/setup/pi/make-root-fs-readonly.sh index 4ac638b..160e038 100644 --- a/setup/pi/make-root-fs-readonly.sh +++ b/setup/pi/make-root-fs-readonly.sh @@ -7,14 +7,6 @@ function append_cmdline_txt_param() { sed -i "s/\'/ ${toAppend}/g" /boot/cmdline.txt >/dev/null } -echo "Updating package index files..." -apt-get update -echo "Removing unwanted packages..." -apt-get remove -y --force-yes --purge triggerhappy logrotate dphys-swapfile -apt-get -y --force-yes autoremove --purge -# Replace log management with busybox (use logread if needed) -echo "Installing ntp and busybox-syslogd..." -apt-get -y --force-yes install ntp busybox-syslogd; dpkg --purge rsyslog echo "Configuring system..." # Add fastboot, noswap and/or ro to end of /boot/cmdline.txt diff --git a/setup/pi/setup-teslausb b/setup/pi/setup-teslausb index c478e5b..edee593 100644 --- a/setup/pi/setup-teslausb +++ b/setup/pi/setup-teslausb @@ -191,9 +191,22 @@ function make_root_fs_readonly () { /tmp/make-root-fs-readonly.sh } +function install_required_packages () { + echo "Updating package index files..." + apt-get update + echo "Removing unwanted packages..." + apt-get remove -y --force-yes --purge triggerhappy logrotate dphys-swapfile + apt-get -y --force-yes autoremove --purge + # Replace log management with busybox (use logread if needed) + echo "Installing ntp, and busybox-syslogd..." + apt-get -y --force-yes install ntp busybox-syslogd hping3; dpkg --purge rsyslog +} + export -f setup_progress export HEADLESS_SETUP +install_required_packages + headless_setup_populate_variables # If USE_LED_FOR_SETUP_PROGRESS = true. From 2eec8864c822dc98214a362c55982be80499ec9d Mon Sep 17 00:00:00 2001 From: cimryan Date: Sat, 3 Nov 2018 17:31:28 -0700 Subject: [PATCH 2/4] Testing for archive reachability is different for each archive system, but necessary for all systems. --- run/archiveloop | 4 +++- run/cifs_archive/archive-is-reachable.sh | 5 +++++ run/rclone_archive/archive-is-reachable.sh | 3 +++ run/rsync_archive/archive-is-reachable.sh | 5 +++++ setup/pi/configure.sh | 1 + 5 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 run/cifs_archive/archive-is-reachable.sh create mode 100644 run/rclone_archive/archive-is-reachable.sh create mode 100644 run/rsync_archive/archive-is-reachable.sh diff --git a/run/archiveloop b/run/archiveloop index 22da133..24dab5b 100644 --- a/run/archiveloop +++ b/run/archiveloop @@ -26,7 +26,9 @@ function fix_errors_in_mounted_files () { function archive_is_reachable () { local reachable=true - hping3 -c 1 -S -p 445 "$ARCHIVE_HOST_NAME" > /dev/null 2>&1 || reachable=false + + /root/bin/archive-is-reachable.sh || reachable=false + if [ "$reachable" = false ] then false diff --git a/run/cifs_archive/archive-is-reachable.sh b/run/cifs_archive/archive-is-reachable.sh new file mode 100644 index 0000000..dd3b102 --- /dev/null +++ b/run/cifs_archive/archive-is-reachable.sh @@ -0,0 +1,5 @@ +#!/bin/bash -eu + +ARCHIVE_HOST_NAME="$1" + +hping3 -c 1 -S -p 445 "$ARCHIVE_HOST_NAME" > /dev/null 2>&1 diff --git a/run/rclone_archive/archive-is-reachable.sh b/run/rclone_archive/archive-is-reachable.sh new file mode 100644 index 0000000..4fc034a --- /dev/null +++ b/run/rclone_archive/archive-is-reachable.sh @@ -0,0 +1,3 @@ +#!/bin/bash -eu + +ping -q -w 1 -c 1 8.8.8.8 > /dev/null 2>&1 diff --git a/run/rsync_archive/archive-is-reachable.sh b/run/rsync_archive/archive-is-reachable.sh new file mode 100644 index 0000000..0ba86dd --- /dev/null +++ b/run/rsync_archive/archive-is-reachable.sh @@ -0,0 +1,5 @@ +#!/bin/bash -eu + +ARCHIVE_HOST_NAME="$1" + +ping -q -w 1 -c 1 "$ARCHIVE_HOST_NAME" > /dev/null 2>&1 diff --git a/setup/pi/configure.sh b/setup/pi/configure.sh index cc6874c..fc22fde 100644 --- a/setup/pi/configure.sh +++ b/setup/pi/configure.sh @@ -122,6 +122,7 @@ function install_archive_scripts () { get_script $install_path connect-archive.sh $archive_module get_script $install_path disconnect-archive.sh $archive_module get_script $install_path write-archive-configs-to.sh $archive_module + get_script $install_path archive-is-reachable.sh $archive_module } From 2a463ba40b3ab62cda5f069e6b756191d29b1929 Mon Sep 17 00:00:00 2001 From: cimryan Date: Sat, 3 Nov 2018 17:43:35 -0700 Subject: [PATCH 3/4] Move installation of the CIFS package to run/cifs_archive/configure-archive.sh Don't need hping3 for other systems. Keep the reconfiguration of the packages that is done specifically for making the root file system read-only in make-root-fs-readonly.sh. --- run/cifs_archive/configure-archive.sh | 6 ++++++ setup/pi/make-root-fs-readonly.sh | 9 +++++++++ setup/pi/setup-teslausb | 13 ------------- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/run/cifs_archive/configure-archive.sh b/run/cifs_archive/configure-archive.sh index a9b7fb5..9831c6a 100644 --- a/run/cifs_archive/configure-archive.sh +++ b/run/cifs_archive/configure-archive.sh @@ -22,6 +22,12 @@ function configure_archive () { echo "Configured the archive." } +function install_required_packages () { + apt-get -y --force-yes install hping3 +} + +install_required_packages + ARCHIVE_SERVER_IP_ADDRESS="$( $INSTALL_DIR/lookup-ip-address.sh "$archiveserver" )" configure_archive "$ARCHIVE_SERVER_IP_ADDRESS" \ No newline at end of file diff --git a/setup/pi/make-root-fs-readonly.sh b/setup/pi/make-root-fs-readonly.sh index 160e038..7cfb27e 100644 --- a/setup/pi/make-root-fs-readonly.sh +++ b/setup/pi/make-root-fs-readonly.sh @@ -7,6 +7,15 @@ function append_cmdline_txt_param() { sed -i "s/\'/ ${toAppend}/g" /boot/cmdline.txt >/dev/null } +echo "Updating package index files..." +apt-get update +echo "Removing unwanted packages..." +apt-get remove -y --force-yes --purge triggerhappy logrotate dphys-swapfile +apt-get -y --force-yes autoremove --purge +# Replace log management with busybox (use logread if needed) +echo "Installing ntp and busybox-syslogd..." +apt-get -y --force-yes install ntp busybox-syslogd; dpkg --purge rsyslog + echo "Configuring system..." # Add fastboot, noswap and/or ro to end of /boot/cmdline.txt diff --git a/setup/pi/setup-teslausb b/setup/pi/setup-teslausb index edee593..c478e5b 100644 --- a/setup/pi/setup-teslausb +++ b/setup/pi/setup-teslausb @@ -191,22 +191,9 @@ function make_root_fs_readonly () { /tmp/make-root-fs-readonly.sh } -function install_required_packages () { - echo "Updating package index files..." - apt-get update - echo "Removing unwanted packages..." - apt-get remove -y --force-yes --purge triggerhappy logrotate dphys-swapfile - apt-get -y --force-yes autoremove --purge - # Replace log management with busybox (use logread if needed) - echo "Installing ntp, and busybox-syslogd..." - apt-get -y --force-yes install ntp busybox-syslogd hping3; dpkg --purge rsyslog -} - export -f setup_progress export HEADLESS_SETUP -install_required_packages - headless_setup_populate_variables # If USE_LED_FOR_SETUP_PROGRESS = true. From 357a70d75f3ff1e173ad59f2857ab73d684bcd3a Mon Sep 17 00:00:00 2001 From: cimryan Date: Sat, 3 Nov 2018 18:05:53 -0700 Subject: [PATCH 4/4] Move installation of the hping3 package to run/cifs_archive/verify-archive-configuration.sh --- run/cifs_archive/configure-archive.sh | 6 ------ run/cifs_archive/verify-archive-configuration.sh | 7 +++++++ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/run/cifs_archive/configure-archive.sh b/run/cifs_archive/configure-archive.sh index 9831c6a..a9b7fb5 100644 --- a/run/cifs_archive/configure-archive.sh +++ b/run/cifs_archive/configure-archive.sh @@ -22,12 +22,6 @@ function configure_archive () { echo "Configured the archive." } -function install_required_packages () { - apt-get -y --force-yes install hping3 -} - -install_required_packages - ARCHIVE_SERVER_IP_ADDRESS="$( $INSTALL_DIR/lookup-ip-address.sh "$archiveserver" )" configure_archive "$ARCHIVE_SERVER_IP_ADDRESS" \ No newline at end of file diff --git a/run/cifs_archive/verify-archive-configuration.sh b/run/cifs_archive/verify-archive-configuration.sh index d08e09e..52ea1f7 100644 --- a/run/cifs_archive/verify-archive-configuration.sh +++ b/run/cifs_archive/verify-archive-configuration.sh @@ -43,6 +43,13 @@ function check_archive_mountable () { umount "$test_mount_location" } +function install_required_packages () { + apt-get -y --force-yes install hping3 +} + +install_required_packages + + ARCHIVE_SERVER_IP_ADDRESS="$( $INSTALL_DIR/lookup-ip-address.sh "$archiveserver" )" check_archive_server_reachable