From 8c8e1a3fef65caa525dcd114fa73c63bb6699098 Mon Sep 17 00:00:00 2001 From: Jordan Carlin Date: Mon, 22 Jul 2024 23:10:45 -0700 Subject: [PATCH] Update section header function usage --- bin/wally-distro-check.sh | 19 ++++++++++++++----- bin/wally-package-install.sh | 14 ++------------ bin/wally-tool-chain-install.sh | 9 --------- 3 files changed, 16 insertions(+), 26 deletions(-) diff --git a/bin/wally-distro-check.sh b/bin/wally-distro-check.sh index cec2ac509..73eb58fba 100755 --- a/bin/wally-distro-check.sh +++ b/bin/wally-distro-check.sh @@ -38,11 +38,20 @@ WARNING_COLOR='\033[93m' FAIL_COLOR='\033[91m' ENDC='\033[0m' # Reset to default color -printf "${SECTION_COLOR}%$(tput cols)s" | tr ' ' '#' -printf "%$(tput cols)s" | tr ' ' '#' -echo -e "Checking System Requirements and Configuring Installation" -printf "%$(tput cols)s" | tr ' ' '#' -printf "%$(tput cols)s${ENDC}" | tr ' ' '#' +# Print section header +section_header() { + if tput cols > /dev/null 2>&1; then + printf "${SECTION_COLOR}%$(tput cols)s" | tr ' ' '#' + printf "%$(tput cols)s" | tr ' ' '#' + echo -e "$1" + printf "%$(tput cols)s" | tr ' ' '#' + printf "%$(tput cols)s${ENDC}" | tr ' ' '#' + else + echo -e "${SECTION_COLOR}$1${ENDC}" + fi +} + +section_header "Checking System Requirements and Configuring Installation" # Get distribution information test -e /etc/os-release && os_release="/etc/os-release" || os_release="/usr/lib/os-release" diff --git a/bin/wally-package-install.sh b/bin/wally-package-install.sh index 52ce5a9e2..5228d6855 100755 --- a/bin/wally-package-install.sh +++ b/bin/wally-package-install.sh @@ -84,12 +84,7 @@ fi # Check if required packages are installed or install/update them depending on passed flag. if [ "${1}" == "--check" ]; then - printf "${SECTION_COLOR}%$(tput cols)s" | tr ' ' '#' - printf "%$(tput cols)s" | tr ' ' '#' - echo -e "Checking Dependencies from Package Manager" - printf "%$(tput cols)s" | tr ' ' '#' - printf "%$(tput cols)s${ENDC}" | tr ' ' '#' - + section_header "Checking Dependencies from Package Manager" if [ "$FAMILY" == rhel ]; then for pack in "${GENERAL_PACKAGES[@]}" "${GNU_PACKAGES[@]}" "${QEMU_PACKAGES[@]}" "${SPIKE_PACKAGES[@]}" "${VERILATOR_PACKAGES[@]}" "${SAIL_PACKAGES[@]}" "${BUILDROOT_PACKAGES[@]}" "${OTHER_PACKAGES[@]}"; do rpm -q "$pack" > /dev/null || (echo -e "${FAIL_COLOR}Missing packages detected (${WARNING_COLOR}$pack${FAIL_COLOR}). Run as root to auto-install or run wally-package-install.sh first.${ENDC}" && exit 1) @@ -104,12 +99,7 @@ else # Check if root, otherwise exit with error message [ "${EUID:=$(id -u)}" -ne 0 ] && echo -e "\n${FAIL_COLOR}Must be run as root${ENDC}" && exit 1 - printf "${SECTION_COLOR}%$(tput cols)s" | tr ' ' '#' - printf "%$(tput cols)s" | tr ' ' '#' - echo -e ""Installing/Updating Dependencies from Package Manager"" - printf "%$(tput cols)s" | tr ' ' '#' - printf "%$(tput cols)s${ENDC}" | tr ' ' '#' - + section_header "Installing/Updating Dependencies from Package Manager" # Enable extra repos necessary for rhel if [ "$FAMILY" == rhel ]; then sudo dnf install -y dnf-plugins-core diff --git a/bin/wally-tool-chain-install.sh b/bin/wally-tool-chain-install.sh index 804deee30..2a4b7c4e8 100755 --- a/bin/wally-tool-chain-install.sh +++ b/bin/wally-tool-chain-install.sh @@ -52,15 +52,6 @@ error() { exit 1 } -# Print section header -section_header() { - printf "${SECTION_COLOR}%$(tput cols)s" | tr ' ' '#' - printf "%$(tput cols)s" | tr ' ' '#' - echo -e "$1" - printf "%$(tput cols)s" | tr ' ' '#' - printf "%$(tput cols)s${ENDC}" | tr ' ' '#' -} - # Check if a git repository exists, is up to date, and has been installed # Clones the repository if it doesn't exist git_check() {