Run so-preflight during setup

This commit is contained in:
William Wernert
2021-11-02 11:18:23 -04:00
parent 9a9d1480de
commit e6adb46364
4 changed files with 66 additions and 10 deletions

View File

@@ -1124,9 +1124,10 @@ detect_os() {
installer_progress_loop() {
local i=0
local msg="${1:-Performing background actions...}"
while true; do
[[ $i -lt 98 ]] && ((i++))
set_progress_str "$i" 'Checking that all required packages are installed and enabled...' nolog
set_progress_str "$i" "$msg" nolog
[[ $i -gt 0 ]] && sleep 5s
done
}

View File

@@ -18,7 +18,13 @@
source ../salt/common/tools/sbin/so-common
source ./so-functions
preflight_log='/root/preflight.log'
script_run="$1"
if [[ $script_run == true ]]; then
preflight_log="${2:-'/root/preflight.log'}"
else
preflight_log='/root/preflight.log'
fi
check_default_repos() {
local ret_code=0
@@ -72,7 +78,8 @@ check_new_repos() {
check_misc_urls() {
printf ' Checking various other URLs used by setup.' | tee -a "$preflight_log"
local so_version=$(cat ../VERSION)
local so_version
so_version=$(cat ../VERSION)
local url_arr=(
"https://raw.githubusercontent.com/Security-Onion-Solutions/securityonion/master/KEYS"
"https://github.com/Neo23x0/signature-base"
@@ -112,10 +119,18 @@ __check_url_arr() {
}
main() {
local intro_str="Beginning pre-flight checks."
local success_str="Pre-flight checks completed successfully!"
local fail_str="Pre-flight checks could not complete."
detect_os "$preflight_log"
[[ -f $preflight_log ]] || touch "$preflight_log"
echo "Beginning pre-flight checks." | tee "$preflight_log"
if [[ $script_run == true ]]; then
echo "$intro_str"
else
echo "$intro_str" | tee "$preflight_log"
fi
check_default_repos &&\
check_new_repos &&\
check_misc_urls
@@ -124,12 +139,23 @@ main() {
echo ""
if [[ $success == 0 ]]; then
echo -e "Pre-flight checks completed successfully!\n" | tee -a "$preflight_log"
if [[ $script_run == true ]]; then
echo "$success_str"
else
echo "$success_str" | tee -a "$preflight_log"
echo ""
fi
else
echo -e "Pre-flight checks could not complete." | tee -a "$preflight_log"
echo -e " Check $preflight_log for details.\n"
exit 1
if [[ $script_run == true ]]; then
echo "$fail_str"
else
echo "$fail_str" | tee -a "$preflight_log"
echo "Check $preflight_log for details."
echo ""
fi
fi
exit $success
}
main

View File

@@ -345,9 +345,24 @@ else
rm -rf $install_opt_file >> "$setup_log" 2>&1
fi
if [[ -z $is_airgap ]]; then
percentage=0
{
installer_progress_loop 'Running preflight checks...' &
progress_bg_proc=$!
./so-preflight true "$setup_log" >> $setup_log 2>&1
preflight_ret=$?
kill -9 "$progress_bg_proc"
wait "$progress_bg_proc" &> /dev/null
if [[ $preflight_ret -gt 0 ]] && ! ( whiptail_preflight_err ); then
whiptail_cancel
fi
} | progress '...'
fi
percentage=0
{
installer_progress_loop & # Run progress bar to 98 in ~8 minutes while waiting for package installs
installer_progress_loop 'Checking that all required packages are installed and enabled...' & # Run progress bar to 98 in ~8 minutes while waiting for package installs
progress_bg_proc=$!
installer_prereq_packages
install_success=$?

View File

@@ -95,7 +95,7 @@ whiptail_cancel() {
title "User cancelled setup."
exit
exit 1
}
whiptail_check_exitstatus() {
@@ -1489,6 +1489,20 @@ whiptail_patch_schedule_select_hours() {
}
whiptail_preflight_err() {
[ -n "$TESTING" ] && return
read -r -d '' message <<- EOM
The so-preflight script failed checking one or more URLs required by setup. Check $setup_log for more details.
Would you like to exit setup?
EOM
whiptail --title "$whiptail_title" \
--yesno "$message" 11 75 \
--yes-button "Continue" --no-button "Exit" --defaultno
}
whiptail_proxy_ask() {
[ -n "$TESTING" ] && return