From 5610e60007bf5815c7e82c67cba76772ac178ffa Mon Sep 17 00:00:00 2001 From: Daniil Klimuk Date: Mon, 8 Apr 2024 16:19:07 +0200 Subject: [PATCH] rework colors and print functions Signed-off-by: Daniil Klimuk --- include/dts-environment.sh | 3 ++- include/dts-functions.sh | 30 +++++++++++++++++++++--------- reports/dasharo-hcl-report | 18 +++++++++--------- scripts/cloud_list | 2 +- scripts/dasharo-deploy | 38 +++++++++++++++++++------------------- scripts/dts | 8 ++++---- 6 files changed, 56 insertions(+), 43 deletions(-) diff --git a/include/dts-environment.sh b/include/dts-environment.sh index eae5071..5c54058 100644 --- a/include/dts-environment.sh +++ b/include/dts-environment.sh @@ -7,10 +7,11 @@ # shellcheck disable=SC2034 # Text Reset -COLOR_OFF='\033[0m' +NORMAL='\033[0m' RED='\033[0;31m' YELLOW='\033[0;33m' GREEN='\033[0;32m' +BLUE='\033[0;36m' BOARD_VENDOR="$(dmidecode -s system-manufacturer)" SYSTEM_MODEL="$(dmidecode -s system-product-name)" diff --git a/include/dts-functions.sh b/include/dts-functions.sh index c441c2c..4b0dcda 100644 --- a/include/dts-functions.sh +++ b/include/dts-functions.sh @@ -8,17 +8,29 @@ # shellcheck source=../include/dts-environment.sh source $DTS_ENV -### Color functions +### Color functions: +function echo_green() { + echo -e "$GREEN""$1""$NORMAL" +} + +function echo_red() { + echo -e "$RED""$1""$NORMAL" +} + +function echo_yellow() { + echo -e "$YELLOW""$1""$NORMAL" +} + print_warning() { - echo -e "$YELLOW""$1""$COLOR_OFF" + echo_yellow "$1" } print_error() { - echo -e "$RED""$1""$COLOR_OFF" + echo_red "$1" } -print_green() { - echo -e "$GREEN""$1""$COLOR_OFF" +print_ok() { + echo_green "$1" } check_if_dasharo() { @@ -837,7 +849,7 @@ download_artifacts() { fi fi fi - print_green "Done" + print_ok "Done" } download_keys() { @@ -856,7 +868,7 @@ get_signing_keys() { wget -q https://raw.githubusercontent.com/3mdeb/3mdeb-secpack/master/$key -O - | gpg --import - >> $ERR_LOG_FILE 2>&1 error_check "Cannot get $key key to verify signatures." done - print_green "Done" + print_ok "Done" } verify_artifacts() { @@ -886,12 +898,12 @@ verify_artifacts() { echo -n "Checking $_name firmware checksum... " sha256sum --check <(echo "$(cat $_hash_file | cut -d ' ' -f 1)" $_update_file) >> $ERR_LOG_FILE 2>&1 error_check "Failed to verify $_name firmware checksum" - print_green "Verified." + print_ok "Verified." if [ -v PLATFORM_SIGN_KEY ]; then echo -n "Checking $_name firmware signature... " _sig_result="$(cat $_hash_file | gpg --verify $_sign_file - >> $ERR_LOG_FILE 2>&1)" error_check "Failed to verify $_name firmware signature.$'\n'$_sig_result" - print_green "Verified." + print_ok "Verified." fi echo "$_sig_result" } diff --git a/reports/dasharo-hcl-report b/reports/dasharo-hcl-report index 8b6a2c7..f2cc8f7 100755 --- a/reports/dasharo-hcl-report +++ b/reports/dasharo-hcl-report @@ -16,7 +16,7 @@ update_result() { # check if status was set as a unknown if [ ! -v $3 ]; then - echo -e [$YELLOW"UNKNOWN"$COLOR_OFF]"\t"$TOOL >> result + echo -e [$YELLOW"UNKNOWN"$NORMAL]"\t"$TOOL >> result return fi @@ -33,20 +33,20 @@ update_result() { # specific check for firmware dump if [ $LOGFILE == "logs/flashrom_read.log" ]; then if [ $LOG -ne 0 ] && [ -f "logs/rom.bin" ]; then - echo -e [$GREEN"OK"$COLOR_OFF]"\t\t"$TOOL >> result + echo -e [$GREEN"OK"$NORMAL]"\t\t"$TOOL >> result else - echo -e [$RED"ERROR"$COLOR_OFF]"\t\t"$TOOL >> result + echo -e [$RED"ERROR"$NORMAL]"\t\t"$TOOL >> result fi return fi # generic checks if [ $LOG -ne 0 ] && [ $ERR -eq 0 ]; then - echo -e [$GREEN"OK"$COLOR_OFF]"\t\t"$TOOL >> result + echo -e [$GREEN"OK"$NORMAL]"\t\t"$TOOL >> result elif [ $LOG -eq 0 ] && [ $ERR -ne 0 ]; then - echo -e [$RED"ERROR"$COLOR_OFF]"\t\t"$TOOL >> result + echo -e [$RED"ERROR"$NORMAL]"\t\t"$TOOL >> result else - echo -e [$YELLOW"UNKNOWN"$COLOR_OFF]"\t"$TOOL >> result + echo -e [$YELLOW"UNKNOWN"$NORMAL]"\t"$TOOL >> result fi } @@ -271,9 +271,9 @@ echo echo "Results of getting data:" >> result echo -e "\nLegend:" >> result -echo -e [$GREEN"OK"$COLOR_OFF]"\t\t Data get successfully" >> result -echo -e [$YELLOW"UNKNOWN"$COLOR_OFF]"\t Result is unknown" >> result -echo -e [$RED"ERROR"$COLOR_OFF]"\t\t Error during getting data\n" >> result +echo -e [$GREEN"OK"$NORMAL]"\t\t Data get successfully" >> result +echo -e [$YELLOW"UNKNOWN"$NORMAL]"\t Result is unknown" >> result +echo -e [$RED"ERROR"$NORMAL]"\t\t Error during getting data\n" >> result mv result logs/result if [ $DEPLOY_REPORT = "false" ]; then diff --git a/scripts/cloud_list b/scripts/cloud_list index 2c66f0f..4488cfd 100755 --- a/scripts/cloud_list +++ b/scripts/cloud_list @@ -10,7 +10,7 @@ HW_UUID="$1" ### Error checks print_error() { - echo -e "$RED""$1""$COLOR_OFF" + echo -e "$RED""$1""$NORMAL" } error_exit() { diff --git a/scripts/dasharo-deploy b/scripts/dasharo-deploy index a3836ab..f6bacd6 100755 --- a/scripts/dasharo-deploy +++ b/scripts/dasharo-deploy @@ -262,7 +262,7 @@ smmstore_migration() { print_warning "Failed! Default settings will be used." cbfstool "$BIOS_UPDATE_FILE" write -r SMMSTORE -f /tmp/smmstore.bin -u >> $ERR_LOG_FILE 2>&1 || \ print_warning "Failed! Default settings will be used." - print_green Done. + print_ok Done. } bootsplash_migration() { @@ -273,7 +273,7 @@ bootsplash_migration() { echo -n "Backing up custom boot logo... " dcu logo $BIOS_UPDATE_FILE -l /tmp/logo.bmp >> $ERR_LOG_FILE 2>&1 || \ print_warning "Failed! Default boot splash will be used." || return 1 - print_green Done. + print_ok Done. } resign_binary() { @@ -344,21 +344,21 @@ blob_transmission() { error_file_check "$SCH5545_FW" "Failed to find SCH5545 EC firmware binary." echo -n "Adding SCH5545 EC firmware..." cbfstool "$BIOS_UPDATE_FILE" add -f "$SCH5545_FW" -n sch5545_ecfw.bin -t raw - print_green "Done" + print_ok "Done" fi if [ -n "$ACM_BIN" ]; then error_file_check "$ACM_BIN" "Failed to find BIOS ACM binary." echo -n "Adding BIOS ACM..." cbfstool "$BIOS_UPDATE_FILE" add -f "$ACM_BIN" -n txt_bios_acm.bin -t raw - print_green "Done" + print_ok "Done" fi if [ -n "$SINIT_ACM" ]; then error_file_check "$SINIT_ACM" "Failed to find Intel SINIT ACM binary." echo -n "Adding SINIT ACM..." cbfstool "$BIOS_UPDATE_FILE" add -f "$SINIT_ACM" -n txt_sinit_acm.bin -t raw - print_green "Done" + print_ok "Done" fi } @@ -421,7 +421,7 @@ install() { $FLASHROM -p "$PROGRAMMER_BIOS" ${FLASH_CHIP_SELECT} ${FLASHROM_ADD_OPT_REGIONS} -w "$BIOS_UPDATE_FILE" >> $FLASHROM_LOG_FILE 2>> $ERR_LOG_FILE error_check "Failed to install Dasharo firmware" - print_green "Successfully installed Dasharo firmware" + print_ok "Successfully installed Dasharo firmware" echo -n "Syncing disks... " sync @@ -522,8 +522,8 @@ update() { else # Access to the heads FW is possible, allow to switch to heads _can_switch_to_heads="true" - print_green "Dasharo Heads firmware version is available and your subscription" - print_green "gives you access to this firmware." + print_ok "Dasharo Heads firmware version is available and your subscription" + print_ok "gives you access to this firmware." fi elif [ -v HAVE_HEADS_FW ] && [ "$DASHARO_FLAVOR" == "Dasharo (coreboot+heads)" ]; then # Set the switch flag to offer switch back @@ -532,8 +532,8 @@ update() { fi else if [ -v DASHARO_REL_VER_DES ]; then - print_green "DES version available, if you are interested" - print_green "please visit https://shop.3mdeb.com/product-category/dasharo-entry-subscription/" + print_ok "DES version available, if you are interested" + print_ok "please visit https://shop.3mdeb.com/product-category/dasharo-entry-subscription/" fi if [ "$DASHARO_FLAVOR" != "Dasharo (coreboot+heads)" ]; then echo "Latest available Dasharo version: $DASHARO_REL_VER" @@ -550,9 +550,9 @@ update() { fi UPDATE_VERSION=$DASHARO_REL_VER if [ -v HAVE_HEADS_FW ] && [ "$DASHARO_FLAVOR" != "Dasharo (coreboot+heads)" ]; then - print_green "Dasharo heads firmware version is available. If you are interested," - print_green "please provide your subscription credentials in the main DTS menu" - print_green "and select 'Update Dasharo firmware' again to check if you are eligible." + print_ok "Dasharo heads firmware version is available. If you are interested," + print_ok "please provide your subscription credentials in the main DTS menu" + print_ok "and select 'Update Dasharo firmware' again to check if you are eligible." elif [ -v HAVE_HEADS_FW ] && [ "$DASHARO_FLAVOR" == "Dasharo (coreboot+heads)" ]; then # Set the switch flag to offer switch back _can_switch_to_heads="true" @@ -680,11 +680,11 @@ update() { # Any post-branch-switch messaging should go here case "$SWITCHING_TO" in "uefi") - print_green "Successfully switched to Dasharo UEFI firmware." + print_ok "Successfully switched to Dasharo UEFI firmware." print_warning "You may need to re-create boot manager entries!" ;; "heads") - print_green "Successfully switched to Dasharo Heads firmware." + print_ok "Successfully switched to Dasharo Heads firmware." print_warning "On first boot you will see a warning about unsealing TOTP secrets." print_warning "This is expected. Run OEM Factory Reset / Re-Ownership to finish deploying Heads." ;; @@ -692,7 +692,7 @@ update() { read -p "Press enter to continue" # Make sure the user acknowledges. else # Regular update flow - print_green "Successfully updated Dasharo firmware." + print_ok "Successfully updated Dasharo firmware." fi if [ "$HAVE_EC" == "true" ]; then @@ -762,7 +762,7 @@ restore() { tar -zxf "$HCL_REPORT_PACKAGE" -C /tmp echo "Restoring BIOS firmware..." if [ -f "/tmp/logs/rom.bin" ]; then - print_green "Found $HCL_REPORT_PACKAGE" + print_ok "Found $HCL_REPORT_PACKAGE" read -p "Do you want to restore firmware from the given HCL report? [N/y] " case ${REPLY} in yes|y|Y|Yes|YES) @@ -777,7 +777,7 @@ restore() { set_intel_regions_update_params "-N --ifd -i bios" $FLASHROM -p "$PROGRAMMER_BIOS" ${FLASH_CHIP_SELECT} ${FLASHROM_ADD_OPT_REGIONS} -w "/tmp/logs/rom.bin" >> $FLASHROM_LOG_FILE 2>> $ERR_LOG_FILE error_check "Failed to restore BIOS firmware! You can try one more time." - print_green "Successfully restored firmware" + print_ok "Successfully restored firmware" echo "Returning to main menu..." exit 0 ;; @@ -817,7 +817,7 @@ restore() { set_intel_regions_update_params "-N --ifd -i bios" flashrom -p "$PROGRAMMER_BIOS" ${FLASH_CHIP_SELECT} ${FLASHROM_ADD_OPT_REGIONS} -w "/tmp/logs/rom.bin" >> $FLASHROM_LOG_FILE 2>> $ERR_LOG_FILE error_check "Failed to restore BIOS firmware! You can try one more time." - print_green "Successfully restored firmware" + print_ok "Successfully restored firmware" else print_error "Report does not have firmware backup!" fi diff --git a/scripts/dts b/scripts/dts index 5c4e358..0f88b22 100644 --- a/scripts/dts +++ b/scripts/dts @@ -157,12 +157,12 @@ while : ; do echo ${TMP_CLOUDSEND_DOWNLOAD_URL} >> ${SE_credential_file} echo ${TMP_CLOUDSEND_PASSWORD} >> ${SE_credential_file} - print_green "Dasharo DES credentials have been saved" + print_ok "Dasharo DES credentials have been saved" echo "Verifying Dasharo DES credentials..." check_se_creds if [ $? -eq 0 ]; then - print_green "Verification of the Dasharo DES was successful. They are valid and will be used." + print_ok "Verification of the Dasharo DES was successful. They are valid and will be used." else echo -e "Something may be wrong with the DES credentials. Please use option 4 to change the DES keys \rand make sure that there is no typo." @@ -204,14 +204,14 @@ while : ; do ;; 8) if systemctl is-active sshd.socket > /dev/null 2>&1; then - print_green "Turning off the SSH server..." + print_ok "Turning off the SSH server..." systemctl stop sshd.socket else print_warning "Starting SSH server!" print_warning "Now you can log in into the system using root account." print_warning "Stopping server will not drop all connected sessions." systemctl start sshd.socket - print_green "Listening on IPs: $(ip -br -f inet a show scope global | grep UP | awk '{ print $3 }' | tr '\n' ' ')" + print_ok "Listening on IPs: $(ip -br -f inet a show scope global | grep UP | awk '{ print $3 }' | tr '\n' ' ')" fi ;; 9)