From 46aa7ebdf31d7cc02e4318e010901fe49d17628d Mon Sep 17 00:00:00 2001 From: Jason Ertel Date: Fri, 20 Jan 2023 06:48:33 -0500 Subject: [PATCH 1/6] correct find/exec syntax --- setup/so-functions | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup/so-functions b/setup/so-functions index d9c9bc2b2..416656bc2 100755 --- a/setup/so-functions +++ b/setup/so-functions @@ -1943,7 +1943,7 @@ securityonion_repo() { # if the package is updated when the update_packages function is called logCmd "yum -v -y update centos-release" info "Backing up the .repo files that were added by the centos-release package." - logCmd "find /etc/yum.repos.d/ -type f -not -name 'securityonion*repo' -exec mv -bvf {} /root/oldrepos/ \;" + logCmd "find /etc/yum.repos.d/ -type f -not -name 'securityonion*repo' -exec mv -bvf {} /root/oldrepos/ \\;" logCmd "yum repolist all" fi } From ece63b72e2b957dae515c58e6185887e77542301 Mon Sep 17 00:00:00 2001 From: Jason Ertel Date: Fri, 20 Jan 2023 07:38:58 -0500 Subject: [PATCH 2/6] Ensure so-verify output is logged --- setup/so-setup | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/setup/so-setup b/setup/so-setup index fb19a9120..8eae60299 100755 --- a/setup/so-setup +++ b/setup/so-setup @@ -585,7 +585,7 @@ if ! [[ -f $install_opt_file ]]; then fi checkin_at_boot set_initial_firewall_access - ./so-verify $setup_type + logCmd ./so-verify $setup_type else touch /root/accept_changes mkdir -p /opt/so @@ -608,7 +608,7 @@ if ! [[ -f $install_opt_file ]]; then configure_minion "$minion_type" drop_install_options checkin_at_boot - ./so-verify $setup_type + logCmd ./so-verify $setup_type fi # Need to make sure the latest install is located on the web server of the manager to check the versions and donwload the code if required From 1e4f9c9f269c0023447fe9f7be1678c639b578cb Mon Sep 17 00:00:00 2001 From: Jason Ertel Date: Fri, 20 Jan 2023 11:01:02 -0500 Subject: [PATCH 3/6] use newer find syntax to allow the exec to work inside a quoted string --- setup/so-functions | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup/so-functions b/setup/so-functions index 416656bc2..d804bef15 100755 --- a/setup/so-functions +++ b/setup/so-functions @@ -1943,7 +1943,7 @@ securityonion_repo() { # if the package is updated when the update_packages function is called logCmd "yum -v -y update centos-release" info "Backing up the .repo files that were added by the centos-release package." - logCmd "find /etc/yum.repos.d/ -type f -not -name 'securityonion*repo' -exec mv -bvf {} /root/oldrepos/ \\;" + logCmd "find /etc/yum.repos.d/ -type f -not -name 'securityonion*repo' -exec mv -bvf {} /root/oldrepos/ +" logCmd "yum repolist all" fi } From c3384d838199e3758af07b4620538de7b6a51641 Mon Sep 17 00:00:00 2001 From: Jason Ertel Date: Fri, 20 Jan 2023 11:23:13 -0500 Subject: [PATCH 4/6] further improvements --- setup/so-functions | 8 ++++++++ setup/so-setup | 6 ++---- setup/so-verify | 17 +---------------- 3 files changed, 11 insertions(+), 20 deletions(-) diff --git a/setup/so-functions b/setup/so-functions index d804bef15..57f112982 100755 --- a/setup/so-functions +++ b/setup/so-functions @@ -2380,3 +2380,11 @@ wait_for_file() { wait_for_salt_minion() { retry 60 5 "journalctl -u salt-minion.service | grep 'Minion is ready to receive requests'" >> "$setup_log" 2>&1 || exit 1 } + +verify_setup() { + if logCmd ./so-verify "$setup_type"; then + whiptail_setup_complete + else + whiptail_setup_failed + fi +} \ No newline at end of file diff --git a/setup/so-setup b/setup/so-setup index 8eae60299..2b0abedc8 100755 --- a/setup/so-setup +++ b/setup/so-setup @@ -585,7 +585,7 @@ if ! [[ -f $install_opt_file ]]; then fi checkin_at_boot set_initial_firewall_access - logCmd ./so-verify $setup_type + verify_setup else touch /root/accept_changes mkdir -p /opt/so @@ -608,10 +608,8 @@ if ! [[ -f $install_opt_file ]]; then configure_minion "$minion_type" drop_install_options checkin_at_boot - logCmd ./so-verify $setup_type + verify_setup fi # Need to make sure the latest install is located on the web server of the manager to check the versions and donwload the code if required - - fi diff --git a/setup/so-verify b/setup/so-verify index 234ef2dec..685e50d81 100755 --- a/setup/so-verify +++ b/setup/so-verify @@ -9,15 +9,10 @@ cd "$(dirname "$0")" || exit 255 source ../salt/common/tools/sbin/so-common source ./so-functions -source ./so-whiptail source ./so-variables setup_type=$1 -setup_in_progress() { - ps -ef | grep so-setup | grep -v grep &> /dev/null -} - using_iso() { if [ "$setup_type" == "iso" ]; then return 0 @@ -25,14 +20,6 @@ using_iso() { return 0 } -whipit() { - if [[ $exit_code -eq 0 ]]; then - whiptail_setup_complete - else - whiptail_setup_failed - fi -} - # Check entire setup log for errors or unexpected salt states log_has_errors() { # Ignore salt mast cached public key and minion failed to auth because this is a test @@ -44,7 +31,7 @@ log_has_errors() { # Ignore Failed: 0 since that is the salt state output, and we detect state failures # via Result: False already. - + grep -E "FAILED|Failed|failed|ERROR|Error|Result: False" "$setup_log" | \ grep -vE "The Salt Master has cached the public key for this node" | \ grep -vE "Minion failed to authenticate with the master" | \ @@ -105,8 +92,6 @@ main() { echo "Successfully completed setup!" fi - setup_in_progress && whipit $exit_code - exit $exit_code } From 56478da0b29b788c8a19bc4a1e56ddd14cf7abf3 Mon Sep 17 00:00:00 2001 From: Jason Ertel Date: Fri, 20 Jan 2023 11:58:29 -0500 Subject: [PATCH 5/6] eliminate find/exec issue altogether to keep it simple --- setup/so-functions | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup/so-functions b/setup/so-functions index 57f112982..03221d0e9 100755 --- a/setup/so-functions +++ b/setup/so-functions @@ -1943,7 +1943,7 @@ securityonion_repo() { # if the package is updated when the update_packages function is called logCmd "yum -v -y update centos-release" info "Backing up the .repo files that were added by the centos-release package." - logCmd "find /etc/yum.repos.d/ -type f -not -name 'securityonion*repo' -exec mv -bvf {} /root/oldrepos/ +" + logCmd "mv -bvf /etc/yum.repos.d/CentOS* /root/oldrepos/" logCmd "yum repolist all" fi } From 95412140734c6254777fc81d137157b649947129 Mon Sep 17 00:00:00 2001 From: Jason Ertel Date: Fri, 20 Jan 2023 12:26:52 -0500 Subject: [PATCH 6/6] logCmd with tee is eating the exit code --- setup/so-functions | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/setup/so-functions b/setup/so-functions index 03221d0e9..a046b49ca 100755 --- a/setup/so-functions +++ b/setup/so-functions @@ -2382,7 +2382,11 @@ wait_for_salt_minion() { } verify_setup() { - if logCmd ./so-verify "$setup_type"; then + info "Verifying setup" + output=$(./so-verify "$setup_type" 2>&1) + result=$? + echo "$output" >> "$setup_log" + if [[ $result -eq 0 ]]; then whiptail_setup_complete else whiptail_setup_failed