[fix] Fix dependency install progress bar

This commit is contained in:
William Wernert
2021-03-11 16:30:14 -05:00
parent 8e8bb1489b
commit b35e65190e
2 changed files with 29 additions and 26 deletions

View File

@@ -1001,12 +1001,14 @@ installer_progress_loop() {
local i=0
while true; do
((i++))
set_progress_str "$i" 'Checking that all required packages are installed and enabled...'
set_progress_str "$i" 'Checking that all required packages are installed and enabled...' nolog
[[ $i -gt 0 ]] && sleep 5s
done
}
installer_prereq_packages() {
installer_progress_loop & # Run progress bar to 100 in ~8 minutes
progress_bg_proc=$!
if [ "$OS" == centos ]; then
# Print message to stdout so the user knows setup is doing something
@@ -1042,6 +1044,13 @@ installer_prereq_packages() {
fi
retry 50 10 "apt-get -y install curl" >> "$setup_log" 2>&1 || exit 1
fi
install_success=$?
kill -9 "$progress_bg_proc" >> "$setup_log" 2>&1
if [[ $install_success -gt 0 ]]; then
echo "Could not install packages required for setup, exiting now." >> "$setup_log" 2>&1
kill -SIGUSR1 "$setup_proc" >> "$setup_log" 2>&1; exit 1
fi
}
disable_auto_start() {
@@ -2369,6 +2378,7 @@ set_progress_str() {
local percentage_input=$1
progress_bar_text=$2
export progress_bar_text
local nolog=$2
if (( "$percentage_input" >= "$percentage" )); then
percentage="$percentage_input"
@@ -2378,12 +2388,14 @@ set_progress_str() {
echo -e "$percentage_str"
if [[ -z $nolog ]]; then
info "Progressing ($percentage%): $progress_bar_text"
printf '%s\n' \
'----'\
"$percentage% - ${progress_bar_text^^}"\
"----" >> "$setup_log" 2>&1
# printf '%s\n' \
# '----'\
# "$percentage% - ${progress_bar_text^^}"\
# "----" >> "$setup_log" 2>&1
fi
}
set_ssh_cmds() {

View File

@@ -95,6 +95,16 @@ if ! [ -f $install_opt_file ]; then
analyze_system
fi
# Set up handler for setup to exit early (use `kill -SIGUSR1 "$setup_proc"; exit 1` in child scripts)
trap 'catch $LINENO' SIGUSR1
setup_proc="$$"
catch() {
info "Fatal error occurred at $1 in so-setup, failing setup."
grep --color=never "ERROR" "$setup_log" > "$error_log"
whiptail_setup_failed
exit 1
}
automated=no
progress() {
local title='Security Onion Setup'
@@ -107,16 +117,6 @@ progress() {
fi
}
# Set up handler for setup to exit early (use `kill -SIGUSR1 "$setup_proc"; exit 1` in child scripts)
trap 'catch $LINENO' SIGUSR1
setup_proc="$$"
catch() {
info "Fatal error occurred at $1 in so-setup, failing setup."
grep --color=never "ERROR" "$setup_log" > "$error_log"
whiptail_setup_failed
exit 1
}
detect_os
if [[ -f automation/$automation && $(basename $automation) == $automation ]]; then
@@ -167,7 +167,6 @@ set_ssh_cmds $automated
local_sbin="$(pwd)/../salt/common/tools/sbin"
export PATH=$PATH:$local_sbin
installer_prereq_packages && detect_cloud
set_network_dev_status_list
if [ "$OS" == ubuntu ]; then
@@ -282,16 +281,8 @@ fi
percentage=0
{
installer_progress_loop & # Run progress bar to 100 in ~8 minutes
progress_bg_proc=$!
installer_prereq_packages
install_success=$?
kill -9 $progress_bg_proc &> /dev/null
if [[ $install_success -gt 0 ]]; then
error "Could not install packages required for setup, exiting now."
kill -SIGUSR1 "$setup_proc" &> /dev/null; exit 1
fi
set_progress_str 99 "Detecting whether setup is running in the cloud."
set_progress_str 99 "Detecting whether setup is running in the cloud." nolog
detect_cloud
} | progress '...'