diff --git a/Makefile b/Makefile index c11148ab..dbc84d5e 100644 --- a/Makefile +++ b/Makefile @@ -19,6 +19,7 @@ install: install -m 0755 scripts/dts $(DESTDIR)$(SBINDIR) install -m 0755 scripts/dts-boot $(DESTDIR)$(SBINDIR) install -m 0755 scripts/ec_transition $(DESTDIR)$(SBINDIR) + install -m 0755 scripts/logging $(DESTDIR)$(SBINDIR)/logging install -m 0755 reports/dasharo-hcl-report $(DESTDIR)$(SBINDIR) install -m 0755 reports/touchpad-info $(DESTDIR)$(SBINDIR) diff --git a/include/dts-environment.sh b/include/dts-environment.sh index 01ebf76f..f9d9ddb1 100644 --- a/include/dts-environment.sh +++ b/include/dts-environment.sh @@ -50,8 +50,6 @@ SSH_OPT_UP="K" SSH_OPT_LOW="$(echo $SSH_OPT_UP | awk '{print tolower($0)}')" SEND_LOGS_OPT="L" SEND_LOGS_OPT_LOW="$(echo $SEND_LOGS_OPT | awk '{print tolower($0)}')" -VERBOSE_OPT="V" -VERBOSE_OPT_LOW="$(echo $VERBOSE_OPT | awk '{print tolower($0)}')" # Hardware variables: SYSTEM_VENDOR="$($DMIDECODE dump_var_mock -s system-manufacturer)" @@ -89,7 +87,6 @@ FW_BACKUP_TAR="${FW_BACKUP_DIR}.tar.gz" FW_BACKUP_TAR="$(echo "$FW_BACKUP_TAR" | sed 's/\ /_/g')" # Paths to system files -ERR_LOG_FILE="/var/local/dts-err.log" FLASHROM_LOG_FILE="/var/local/flashrom.log" FLASH_INFO_FILE="/tmp/flash_info" OS_VERSION_FILE="/etc/os-release" diff --git a/include/dts-functions.sh b/include/dts-functions.sh index cbf0a2f2..68f5f095 100644 --- a/include/dts-functions.sh +++ b/include/dts-functions.sh @@ -83,20 +83,24 @@ check_if_ac() { fum_exit() { if [ "$FUM" == "fum" ]; then print_error "Update cannot be performed" - print_warning "Starting bash session - please make sure you get logs from\r - \r$ERR_LOG_FILE and $FLASHROM_LOG_FILE; then you can poweroff the platform" + print_warning "Starting bash session" + send_dts_logs ask /bin/bash fi } error_exit() { _error_msg="$1" + local exit_code=1 + if [ "$#" -eq 2 ]; then + exit_code=$2 + fi if [ -n "$_error_msg" ]; then # Avoid printing empty line if no message was passed print_error "$_error_msg" fi fum_exit - exit 1 + exit $exit_code } error_check() { @@ -150,7 +154,7 @@ it5570_shutdown() { } check_network_connection() { - if wget --spider cloud.3mdeb.com > /dev/null 2>&1; then + if wget --spider cloud.3mdeb.com > /dev/null 2>>"$ERR_LOG_FILE"; then return 0 else return 1 @@ -323,7 +327,7 @@ board_config() { # Dasharo 0.9.0-rc10 and higher have board model in baseboard-version if check_if_dasharo && compare_versions "$DASHARO_VERSION" 0.9.0-rc10; then BOARD_MODEL="$($DMIDECODE dump_var_mock -s baseboard-version)" - elif ! $DASHARO_ECTOOL check_for_opensource_firm_mock info 2>/dev/null; then + elif ! $DASHARO_ECTOOL check_for_opensource_firm_mock info 2>>"$ERR_LOG_FILE"; then ask_for_model V540TU V560TU else BOARD_MODEL=$($DASHARO_ECTOOL novacustom_check_sys_model_mock info | grep "board:" | @@ -686,22 +690,22 @@ check_flash_lock() { check_flash_chip() { echo "Gathering flash chip and chipset information..." - $FLASHROM flash_chip_name_mock -p "$PROGRAMMER_BIOS" --flash-name >> "$FLASH_INFO_FILE" 2>> "$ERR_LOG_FILE" + $FLASHROM flash_chip_name_mock -p "$PROGRAMMER_BIOS" --flash-name >> "$FLASH_INFO_FILE" 2>>"$ERR_LOG_FILE" if [ $? -eq 0 ]; then echo -n "Flash information: " tail -n1 "$FLASH_INFO_FILE" - FLASH_CHIP_SIZE=$(($($FLASHROM flash_chip_size_mock -p "$PROGRAMMER_BIOS" --flash-size 2>> /dev/null | tail -n1) / 1024 / 1024)) + FLASH_CHIP_SIZE=$(($($FLASHROM flash_chip_size_mock -p "$PROGRAMMER_BIOS" --flash-size 2>>"$ERR_LOG_FILE" | tail -n1) / 1024 / 1024)) echo -n "Flash size: " echo ${FLASH_CHIP_SIZE}M else for flash_name in $FLASH_CHIP_LIST do - $FLASHROM flash_chip_name_mock -p "$PROGRAMMER_BIOS" -c "$flash_name" --flash-name >> "$FLASH_INFO_FILE" 2>> "$ERR_LOG_FILE" + $FLASHROM flash_chip_name_mock -p "$PROGRAMMER_BIOS" -c "$flash_name" --flash-name >> "$FLASH_INFO_FILE" 2>>"$ERR_LOG_FILE" if [ $? -eq 0 ]; then echo "Chipset found" tail -n1 "$FLASH_INFO_FILE" FLASH_CHIP_SELECT="-c ${flash_name}" - FLASH_CHIP_SIZE=$(($($FLASHROM flash_chip_size_mock -p "$PROGRAMMER_BIOS" ${FLASH_CHIP_SELECT} --flash-size 2>> /dev/null | tail -n1) / 1024 / 1024)) + FLASH_CHIP_SIZE=$(($($FLASHROM flash_chip_size_mock -p "$PROGRAMMER_BIOS" ${FLASH_CHIP_SELECT} --flash-size 2>>"$ERR_LOG_FILE" | tail -n1) / 1024 / 1024)) echo "Chipset size" echo ${FLASH_CHIP_SIZE}M break @@ -738,24 +742,24 @@ compare_versions() { download_bios() { if [ "${BIOS_LINK}" == "${BIOS_LINK_COMM}" ] || [ "${BIOS_LINK}" == "${BIOS_LINK_COMM_CAP}" ]; then - curl -s -L -f "$BIOS_LINK" -o $BIOS_UPDATE_FILE + curl -s -S -L -f "$BIOS_LINK" -o $BIOS_UPDATE_FILE 2>>"$ERR_LOG_FILE" error_check "Cannot access $FW_STORE_URL while downloading binary. Please check your internet connection" - curl -s -L -f "$BIOS_HASH_LINK" -o $BIOS_HASH_FILE + curl -s -S -L -f "$BIOS_HASH_LINK" -o $BIOS_HASH_FILE 2>>"$ERR_LOG_FILE" error_check "Cannot access $FW_STORE_URL while downloading signature. Please check your internet connection" - curl -s -L -f "$BIOS_SIGN_LINK" -o $BIOS_SIGN_FILE + curl -s -S -L -f "$BIOS_SIGN_LINK" -o $BIOS_SIGN_FILE 2>>"$ERR_LOG_FILE" error_check "Cannot access $FW_STORE_URL while downloading signature. Please check your internet connection" else USER_DETAILS="$CLOUDSEND_DOWNLOAD_URL:$CLOUDSEND_PASSWORD" - curl -s -L -f -u "$USER_DETAILS" -H "$CLOUD_REQUEST" "$BIOS_LINK" -o $BIOS_UPDATE_FILE + curl -s -S -L -f -u "$USER_DETAILS" -H "$CLOUD_REQUEST" "$BIOS_LINK" -o $BIOS_UPDATE_FILE 2>>"$ERR_LOG_FILE" error_check "Cannot access $FW_STORE_URL_DPP while downloading binary. Please check your internet connection and credentials" - curl -s -L -f -u "$USER_DETAILS" -H "$CLOUD_REQUEST" "$BIOS_HASH_LINK" -o $BIOS_HASH_FILE + curl -s -S -L -f -u "$USER_DETAILS" -H "$CLOUD_REQUEST" "$BIOS_HASH_LINK" -o $BIOS_HASH_FILE 2>>"$ERR_LOG_FILE" error_check "Cannot access $FW_STORE_URL_DPP while downloading signature. Please check your internet connection and credentials" - curl -s -L -f -u "$USER_DETAILS" -H "$CLOUD_REQUEST" "$BIOS_SIGN_LINK" -o $BIOS_SIGN_FILE + curl -s -S -L -f -u "$USER_DETAILS" -H "$CLOUD_REQUEST" "$BIOS_SIGN_LINK" -o $BIOS_SIGN_FILE 2>>"$ERR_LOG_FILE" error_check "Cannot access $FW_STORE_URL_DPP while downloading signature. Please check your internet connection and credentials" fi @@ -763,23 +767,23 @@ download_bios() { download_ec() { if [ "${BIOS_LINK}" = "${BIOS_LINK_COMM}" ] || [ "${BIOS_LINK}" = "${BIOS_LINK_COMM_CAP}" ]; then - curl -s -L -f "$EC_LINK" -o "$EC_UPDATE_FILE" + curl -s -S -L -f "$EC_LINK" -o "$EC_UPDATE_FILE" 2>>"$ERR_LOG_FILE" error_check "Cannot access $FW_STORE_URL while downloading binary. Please check your internet connection" - curl -s -L -f "$EC_HASH_LINK" -o $EC_HASH_FILE + curl -s -S -L -f "$EC_HASH_LINK" -o $EC_HASH_FILE 2>>"$ERR_LOG_FILE" error_check "Cannot access $FW_STORE_URL while downloading signature. Please check your internet connection" - curl -s -L -f "$EC_SIGN_LINK" -o $EC_SIGN_FILE + curl -s -S -L -f "$EC_SIGN_LINK" -o $EC_SIGN_FILE 2>>"$ERR_LOG_FILE" error_check "Cannot access $FW_STORE_URL while downloading signature. Please check your internet connection" else - curl -s -L -f -u "$USER_DETAILS" -H "$CLOUD_REQUEST" "$EC_LINK" -o $EC_UPDATE_FILE + curl -s -S -L -f -u "$USER_DETAILS" -H "$CLOUD_REQUEST" "$EC_LINK" -o $EC_UPDATE_FILE 2>>"$ERR_LOG_FILE" error_check "Cannot access $FW_STORE_URL while downloading binary. Please check your internet connection and credentials" - curl -s -L -f -u "$USER_DETAILS" -H "$CLOUD_REQUEST" "$EC_HASH_LINK" -o $EC_HASH_FILE + curl -s -S -L -f -u "$USER_DETAILS" -H "$CLOUD_REQUEST" "$EC_HASH_LINK" -o $EC_HASH_FILE 2>>"$ERR_LOG_FILE" error_check "Cannot access $FW_STORE_URL while downloading signature. Please check your internet connection and credentials" - curl -s -L -f -u "$USER_DETAILS" -H "$CLOUD_REQUEST" "$EC_SIGN_LINK" -o $EC_SIGN_FILE + curl -s -S -L -f -u "$USER_DETAILS" -H "$CLOUD_REQUEST" "$EC_SIGN_LINK" -o $EC_SIGN_FILE 2>>"$ERR_LOG_FILE" error_check "Cannot access $FW_STORE_URL while downloading signature. Please check your internet connection and credentials" fi @@ -888,7 +892,7 @@ check_blobs_in_binary() { # If there is no descriptor, there is no ME as well, so skip the check if [ $BOARD_HAS_FD_REGION -ne 0 ]; then - ME_OFFSET=$($IFDTOOL check_blobs_in_binary_mock -d $1 2> /dev/null | grep "Flash Region 2 (Intel ME):" | sed 's/Flash Region 2 (Intel ME)\://' | awk '{print $1;}') + ME_OFFSET=$($IFDTOOL check_blobs_in_binary_mock -d $1 2>>"$ERR_LOG_FILE" | grep "Flash Region 2 (Intel ME):" | sed 's/Flash Region 2 (Intel ME)\://' | awk '{print $1;}') # Check for IFD signature at offset 0 (old descriptors) if [ "$(tail -c +0 $1|head -c 4|xxd -ps)" == "5aa5f00f" ]; then BINARY_HAS_FD=1 @@ -1000,11 +1004,11 @@ set_flashrom_update_params() { # We need to read whole binary (or BIOS region), otherwise cbfstool will # return different attributes for CBFS regions echo "Checking flash layout." - $FLASHROM read_flash_layout_mock -p "$PROGRAMMER_BIOS" ${FLASH_CHIP_SELECT} ${FLASHROM_ADD_OPT_UPDATE} -r $BIOS_DUMP_FILE > /dev/null 2>&1 + $FLASHROM read_flash_layout_mock -p "$PROGRAMMER_BIOS" ${FLASH_CHIP_SELECT} ${FLASHROM_ADD_OPT_UPDATE} -r $BIOS_DUMP_FILE > /dev/null 2>>"$ERR_LOG_FILE" if [ $? -eq 0 ] && [ -f "$BIOS_DUMP_FILE" ]; then - BOARD_FMAP_LAYOUT=$($CBFSTOOL layout_mock $BIOS_DUMP_FILE layout -w 2> /dev/null) - BINARY_FMAP_LAYOUT=$($CBFSTOOL layout_mock $1 layout -w 2> /dev/null) - diff <(echo "$BOARD_FMAP_LAYOUT") <(echo "$BINARY_FMAP_LAYOUT") > /dev/null 2>&1 + BOARD_FMAP_LAYOUT=$($CBFSTOOL layout_mock $BIOS_DUMP_FILE layout -w 2>>"$ERR_LOG_FILE") + BINARY_FMAP_LAYOUT=$($CBFSTOOL layout_mock $1 layout -w 2>>"$ERR_LOG_FILE") + diff <(echo "$BOARD_FMAP_LAYOUT") <(echo "$BINARY_FMAP_LAYOUT") > /dev/null 2>>"$ERR_LOG_FILE" # If layout is identical, perform standard update using FMAP only if [ $? -eq 0 ]; then # Simply update RW_A fmap region if exists @@ -1110,7 +1114,7 @@ handle_fw_switching() { done elif [ -n "$DPP_IS_LOGGED" ] && [ -n "$HEADS_LINK_DPP" ]; then local _heads_dpp=1 - curl -sfI -u "$USER_DETAILS" -H "$CLOUD_REQUEST" "$HEADS_LINK_DPP" -o /dev/null + curl -sSfI -u "$USER_DETAILS" -H "$CLOUD_REQUEST" "$HEADS_LINK_DPP" -o /dev/null 2>>"$ERR_LOG_FILE" _heads_dpp=$? # We are on heads, offer switch back or perform update if DPP gives access to heads if [ "$DASHARO_FLAVOR" == "Dasharo (coreboot+heads)" ]; then @@ -1207,7 +1211,7 @@ handle_fw_switching() { sync_clocks() { echo "Waiting for system clock to be synced ..." - chronyc waitsync 10 0 0 5 &> /dev/null + chronyc waitsync 10 0 0 5 >/dev/null 2>>"$ERR_LOG_FILE" if [[ $? -ne 0 ]]; then print_warning "Failed to sync system clock with NTP server!" print_warning "Some time critical tasks might fail!" @@ -1230,6 +1234,10 @@ You can find more info about HCL in docs.dasharo.com/glossary\r" } show_ram_inf() { + # Trace logging is quite slow due to creating timestamp for each line + # (calls 'date'). In QEMU this function results in 650 trace lines + # out of 800 for every UI refresh, which is noticeable + stop_trace_logging # Get the data: local data="" data=$($DMIDECODE) @@ -1272,6 +1280,7 @@ show_ram_inf() { for entry in "${memory_devices_array[@]}"; do echo -e "${BLUE}**${YELLOW} RAM ${entry}" done + start_trace_logging } show_header() { @@ -1310,7 +1319,7 @@ show_dpp_credentials() { } show_ssh_info() { - if systemctl is-active sshd.service &> /dev/null; then + if systemctl is-active sshd.service >/dev/null 2>>"$ERR_LOG_FILE"; then local ip="" ip=$(ip -br -f inet a show scope global | grep UP | awk '{ print $3 }' | tr '\n' ' ') # Display "check your connection" in red color in IP field in case no IPV4 @@ -1349,6 +1358,7 @@ show_main_menu() { main_menu_options(){ local OPTION=$1 + local result case ${OPTION} in "${HCL_REPORT_OPT}") @@ -1402,6 +1412,10 @@ main_menu_options(){ if [ -n "${LOGS_SENT}" ]; then ${CMD_DASHARO_DEPLOY} install + result=$? + if [ "$result" -ne 0 ] && [ "$result" -ne 2 ]; then + send_dts_logs ask + fi fi else # TODO: This should be placed in dasharo-deploy: @@ -1429,7 +1443,11 @@ main_menu_options(){ fi # Use regular update process for everything else - ${CMD_DASHARO_DEPLOY} update + ${CMD_DASHARO_DEPLOY} update; + result=$? + if [ "$result" -ne 0 ] && [ "$result" -ne 2 ]; then + send_dts_logs ask + fi fi read -p "Press Enter to continue." @@ -1441,7 +1459,9 @@ main_menu_options(){ [ "${SYSTEM_VENDOR}" = "QEMU" ] || [ "${SYSTEM_VENDOR}" = "Emulation" ] && return 0 if check_if_dasharo; then - ${CMD_DASHARO_DEPLOY} restore + if ! ${CMD_DASHARO_DEPLOY} restore; then + send_dts_logs ask + fi fi read -p "Press Enter to continue." @@ -1494,7 +1514,7 @@ show_footer(){ echo -ne "${RED}${REBOOT_OPT_UP}${NORMAL} to reboot ${NORMAL}" echo -ne "${RED}${POWEROFF_OPT_UP}${NORMAL} to poweroff ${NORMAL}" echo -e "${RED}${SHELL_OPT_UP}${NORMAL} to enter shell ${NORMAL}" - if systemctl is-active sshd.service &> /dev/null; then + if systemctl is-active sshd.service >/dev/null 2>>"$ERR_LOG_FILE"; then echo -ne "${RED}${SSH_OPT_UP}${NORMAL} to stop SSH server ${NORMAL}" else echo -ne "${RED}${SSH_OPT_UP}${NORMAL} to launch SSH server ${NORMAL}" @@ -1504,11 +1524,6 @@ show_footer(){ else echo -e "${RED}${SEND_LOGS_OPT}${NORMAL} to enable sending DTS logs ${NORMAL}" fi - if [ "${VERBOSE_ACTIVE}" == "true" ]; then - echo -ne "${RED}${VERBOSE_OPT}${NORMAL} to disable verbose mode ${NORMAL}" - else - echo -ne "${RED}${VERBOSE_OPT}${NORMAL} to enable verbose mode ${NORMAL}" - fi echo -ne "${YELLOW}\nEnter an option:${NORMAL}" } @@ -1519,7 +1534,7 @@ footer_options(){ "${SSH_OPT_UP}" | "${SSH_OPT_LOW}") wait_for_network_connection || return 0 - if systemctl is-active sshd.service> /dev/null 2>&1; then + if systemctl is-active sshd.service >/dev/null 2>>"$ERR_LOG_FILE"; then print_ok "Turning off the SSH server..." systemctl stop sshd.service else @@ -1538,8 +1553,9 @@ footer_options(){ echo "Entering shell, to leave type exit and press Enter or press LCtrl+D" echo "" send_dts_logs - set_verbose "false" + stop_logging ${CMD_SHELL} + start_logging # If in submenu before going to shell - return to main menu after exiting # shell: @@ -1560,20 +1576,19 @@ footer_options(){ SEND_LOGS_ACTIVE="true" fi ;; - "${VERBOSE_OPT}" | "${VERBOSE_OPT_LOW}") - if [ "${VERBOSE_ACTIVE}" == "true" ]; then - set_verbose "false" - else - set_verbose "true" - fi - ;; esac return 1 } -send_dts_logs(){ - if [ "${SEND_LOGS_ACTIVE}" == "true" ]; then +send_dts_logs() { + local send_logs="false" + if [ "${SEND_LOGS_ACTIVE}" = "true" ]; then + send_logs="true" + elif [ "$1" = "ask" ] && ask_for_confirmation "Do you want to send console logs to 3mdeb?"; then + send_logs="true" + fi + if [ "$send_logs" = "true" ]; then echo "Sending logs..." log_dir=$(dmidecode -s system-manufacturer)_$(dmidecode -s system-product-name)_$(dmidecode -s bios-version) @@ -1591,15 +1606,16 @@ send_dts_logs(){ mkdir $log_dir cp ${DTS_LOG_FILE} $log_dir + cp ${DTS_VERBOSE_LOG_FILE} $log_dir - if [ -f ${ERR_LOG_FILE} ]; then - cp ${ERR_LOG_FILE} $log_dir + if [ -f ${ERR_LOG_FILE_REALPATH} ]; then + cp ${ERR_LOG_FILE_REALPATH} $log_dir fi if [ -f ${FLASHROM_LOG_FILE} ]; then cp ${FLASHROM_LOG_FILE} $log_dir fi - tar czf "${log_dir}.tar.gz" $log_dir + tar czf "${log_dir}.tar.gz" -C "$(dirname "$log_dir")" "$(basename "$log_dir")" FULL_DTS_URL="https://cloud.3mdeb.com/index.php/s/"${BASE_DTS_LOGS_URL} @@ -1614,6 +1630,9 @@ send_dts_logs(){ fi unset SEND_LOGS_ACTIVE fi + if [ "$1" = "ask" ]; then + read -p "Press Enter to continue." + fi } check_if_fused() { @@ -1722,21 +1741,16 @@ check_if_intel() { fi } -set_verbose() { - if [ $1 == "true" ]; then - VERBOSE_ACTIVE="true" - CMD_DASHARO_DEPLOY="/usr/bin/env bash -x $CMD_DASHARO_DEPLOY" - CMD_DASHARO_HCL_REPORT="/usr/bin/env bash -x $CMD_DASHARO_HCL_REPORT" - CMD_EC_TRANSITION="/usr/bin/env bash -x $CMD_EC_TRANSITION" - CMD_CLOUD_LIST="/usr/bin/env bash -x $CMD_CLOUD_LIST" - set -x - elif [ $1 == "false" ]; then - unset VERBOSE_ACTIVE - # Remove the -x option - CMD_DASHARO_DEPLOY=$(echo $CMD_DASHARO_DEPLOY | sed 's|^/usr/bin/env bash -x ||') - CMD_DASHARO_HCL_REPORT=$(echo $CMD_DASHARO_HCL_REPORT | sed 's|^/usr/bin/env bash -x ||') - CMD_EC_TRANSITION=$(echo $CMD_EC_TRANSITION | sed 's|^/usr/bin/env bash -x ||') - CMD_CLOUD_LIST=$(echo $CMD_CLOUD_LIST | sed 's|^/usr/bin/env bash -x ||') - set +x - fi +ask_for_confirmation() { + local text="$1" + + read -p "$text [N/y]: " + case ${REPLY} in + yes|y|Y|Yes|YES) + return 0 + ;; + *) + return 1 + ;; + esac } diff --git a/include/dts-subscription.sh b/include/dts-subscription.sh index 5f8505bf..4c2631c1 100644 --- a/include/dts-subscription.sh +++ b/include/dts-subscription.sh @@ -39,22 +39,22 @@ check_for_dasharo_firmware() { # Check for firmware binaries: if wait_for_network_connection; then if [ -n "$BIOS_LINK_DPP" ]; then - _check_dwn_req_resp_uefi=$(curl -L -I -s -f -u "$USER_DETAILS" -H "$CLOUD_REQUEST" "$BIOS_LINK_DPP" -o /dev/null -w "%{http_code}") + _check_dwn_req_resp_uefi=$(curl -L -I -s -S -f -u "$USER_DETAILS" -H "$CLOUD_REQUEST" "$BIOS_LINK_DPP" -o /dev/null -w "%{http_code}" 2>>"$ERR_LOG_FILE") fi if [ -n "$BIOS_LINK_DPP_CAP" ]; then - _check_dwn_req_resp_uefi_cap=$(curl -L -I -s -f -u "$USER_DETAILS" -H "$CLOUD_REQUEST" "$BIOS_LINK_DPP_CAP" -o /dev/null -w "%{http_code}") + _check_dwn_req_resp_uefi_cap=$(curl -L -I -s -S -f -u "$USER_DETAILS" -H "$CLOUD_REQUEST" "$BIOS_LINK_DPP_CAP" -o /dev/null -w "%{http_code}" 2>>"$ERR_LOG_FILE") fi if [ -n "$HEADS_LINK_DPP" ]; then - _check_dwn_req_resp_heads=$(curl -L -I -s -f -u "$USER_DETAILS" -H "$CLOUD_REQUEST" "$HEADS_LINK_DPP" -o /dev/null -w "%{http_code}") + _check_dwn_req_resp_heads=$(curl -L -I -s -S -f -u "$USER_DETAILS" -H "$CLOUD_REQUEST" "$HEADS_LINK_DPP" -o /dev/null -w "%{http_code}" 2>>"$ERR_LOG_FILE") fi if [ -n "$BIOS_LINK_DPP_SEABIOS" ]; then - _check_dwn_req_resp_seabios=$(curl -L -I -s -f -u "$USER_DETAILS" -H "$CLOUD_REQUEST" "$BIOS_LINK_DPP_SEABIOS" -o /dev/null -w "%{http_code}") + _check_dwn_req_resp_seabios=$(curl -L -I -s -S -f -u "$USER_DETAILS" -H "$CLOUD_REQUEST" "$BIOS_LINK_DPP_SEABIOS" -o /dev/null -w "%{http_code}" 2>>"$ERR_LOG_FILE") fi - _check_logs_req_resp=$(curl -L -I -s -f -H "$CLOUD_REQUEST" "$TEST_LOGS_URL" -o /dev/null -w "%{http_code}") + _check_logs_req_resp=$(curl -L -I -s -S -f -H "$CLOUD_REQUEST" "$TEST_LOGS_URL" -o /dev/null -w "%{http_code}" 2>>"$ERR_LOG_FILE") # Return 0 if any of Dasharo Firmware binaries is available: if [ ${_check_dwn_req_resp_uefi} -eq 200 ] || [ ${_check_dwn_req_resp_uefi_cap} -eq 200 ] || [ ${_check_dwn_req_resp_heads} -eq 200 ] || [ ${_check_dwn_req_resp_seabios} -eq 200 ]; then diff --git a/include/hal/dts-hal.sh b/include/hal/dts-hal.sh index 69e3e45f..d5fd8602 100644 --- a/include/hal/dts-hal.sh +++ b/include/hal/dts-hal.sh @@ -144,7 +144,7 @@ tool_wrapper(){ check_for_opensource_firmware() { echo "Checking for Open Source Embedded Controller firmware..." - $DASHARO_ECTOOL check_for_opensource_firm_mock info > /dev/null 2>&1 + $DASHARO_ECTOOL check_for_opensource_firm_mock info > /dev/null 2>>"$ERR_LOG_FILE" return $? } @@ -190,7 +190,7 @@ check_me_op_mode(){ # Checks ME Current Operation Mode at offset 0x40 bits 19:16: local _mode - _mode="$($SETPCI check_me_op_mode_mock -s 00:16.0 42.B 2> /dev/null | cut -c2-)" + _mode="$($SETPCI check_me_op_mode_mock -s 00:16.0 42.B 2>>"$ERR_LOG_FILE" | cut -c2-)" echo "$_mode" diff --git a/reports/dasharo-hcl-report b/reports/dasharo-hcl-report index 4ccf385f..c86516e3 100644 --- a/reports/dasharo-hcl-report +++ b/reports/dasharo-hcl-report @@ -219,10 +219,10 @@ printf '#################################### |\r' # echo "Decompiling ACPI tables..." mkdir -p logs/acpi -if pushd logs/acpi &> /dev/null; then - acpixtract -a ../acpidump.log &>/dev/null - iasl -d ./*.dat &>/dev/null - popd &> /dev/null || return 1 +if pushd logs/acpi >/dev/null 2>>"$ERR_LOG_FILE"; then + acpixtract -a ../acpidump.log >/dev/null 2>>"$ERR_LOG_FILE" + iasl -d ./*.dat >/dev/null 2>>"$ERR_LOG_FILE" + popd >/dev/null 2>>"$ERR_LOG_FILE" || return 1 fi update_result "ACPI tables" 0 UNKNOWN printf '###################################### |\r' @@ -325,7 +325,7 @@ fi # warning: # shellcheck disable=SC2046 MAC_ADDR=`cat /sys/class/net/$(ip route show default | head -1 | awk '/default/ {print $5}')/address` -grep -rl "${MAC_ADDR}" logs > /dev/null && grep -rl "${MAC_ADDR}" logs | xargs sed -i 's/'${MAC_ADDR}'/MAC ADDRESS REMOVED/g' +grep -rl "${MAC_ADDR}" logs >/dev/null && grep -rl "${MAC_ADDR}" logs | xargs sed -i 's/'${MAC_ADDR}'/MAC ADDRESS REMOVED/g' tar -zcf "$filename.tar.gz" logs/* rm -rf logs diff --git a/scripts/cloud_list b/scripts/cloud_list index 4488cfd2..dd764715 100644 --- a/scripts/cloud_list +++ b/scripts/cloud_list @@ -30,7 +30,7 @@ CLOUD_REQUEST="X-Requested-With: XMLHttpRequest" tmpURL="https://cloud.3mdeb.com/public.php/webdav/" -curl -L -f -u "$USER_DETAILS" -H "$CLOUD_REQUEST" -X PROPFIND "$tmpURL" -o "$TMP_RESPONSE" +curl -L -f -u "$USER_DETAILS" -H "$CLOUD_REQUEST" -X PROPFIND "$tmpURL" -o "$TMP_RESPONSE" 2>>"$ERR_LOG_FILE" error_check "Cannot access list of files on cloud." # parse response @@ -53,7 +53,7 @@ HCL_REPORT_NAME=$(cat $TMP_LIST | grep -m1 $HW_UUID) # download HCL report tmpURL="https://cloud.3mdeb.com/public.php/webdav/$HCL_REPORT_NAME" -curl -L -f -u "$USER_DETAILS" -H "$CLOUD_REQUEST" -X GET "$tmpURL" -o /$HCL_REPORT_NAME +curl -L -f -u "$USER_DETAILS" -H "$CLOUD_REQUEST" -X GET "$tmpURL" -o /$HCL_REPORT_NAME 2>>"$ERR_LOG_FILE" if [ -f /$HCL_REPORT_NAME ]; then echo "Report downloaded" else diff --git a/scripts/dasharo-deploy b/scripts/dasharo-deploy index 3c5def55..e3104320 100644 --- a/scripts/dasharo-deploy +++ b/scripts/dasharo-deploy @@ -80,7 +80,7 @@ check_for_firmware_access() { # This firmware type require user to provide creds: [ "$DPP_IS_LOGGED" == "true" ] || return 1 - curl -sfI -u "$USER_DETAILS" -H "$CLOUD_REQUEST" "$BIOS_LINK_DPP" -o /dev/null + curl -sfI -u "$USER_DETAILS" -H "$CLOUD_REQUEST" "$BIOS_LINK_DPP" -o /dev/null 2>>"$ERR_LOG_FILE" [ $? -ne 0 ] && return 1 ;; @@ -88,7 +88,7 @@ check_for_firmware_access() { # This firmware type require user to provide creds: [ "$DPP_IS_LOGGED" == "true" ] || return 1 - curl -sfI -u "$USER_DETAILS" -H "$CLOUD_REQUEST" "$BIOS_LINK_DPP_CAP" -o /dev/null + curl -sfI -u "$USER_DETAILS" -H "$CLOUD_REQUEST" "$BIOS_LINK_DPP_CAP" -o /dev/null 2>>"$ERR_LOG_FILE" [ $? -ne 0 ] && return 1 ;; @@ -96,7 +96,7 @@ check_for_firmware_access() { # This firmware type require user to provide creds: [ "$DPP_IS_LOGGED" == "true" ] || return 1 - curl -sfI -u "$USER_DETAILS" -H "$CLOUD_REQUEST" "$BIOS_LINK_DPP_SEABIOS" -o /dev/null + curl -sfI -u "$USER_DETAILS" -H "$CLOUD_REQUEST" "$BIOS_LINK_DPP_SEABIOS" -o /dev/null 2>>"$ERR_LOG_FILE" [ $? -ne 0 ] && return 1 ;; @@ -104,7 +104,7 @@ check_for_firmware_access() { # This firmware type require user to provide creds: [ "$DPP_IS_LOGGED" == "true" ] || return 1 - curl -sfI -u "$USER_DETAILS" -H "$CLOUD_REQUEST" "$HEADS_LINK_DPP" -o /dev/null + curl -sfI -u "$USER_DETAILS" -H "$CLOUD_REQUEST" "$HEADS_LINK_DPP" -o /dev/null 2>>"$ERR_LOG_FILE" [ $? -ne 0 ] && return 1 ;; @@ -511,16 +511,16 @@ romhole_migration() { if check_if_dasharo; then $CBFSTOOL layout_mock /tmp/rom.bin layout -w | grep -q "ROMHOLE" || return # This one is rather unlikely to fail, but just in case print a warning - $CBFSTOOL read_romhole_mock /tmp/rom.bin read -r ROMHOLE -f /tmp/romhole.bin 2> /dev/null + $CBFSTOOL read_romhole_mock /tmp/rom.bin read -r ROMHOLE -f /tmp/romhole.bin 2>>"$ERR_LOG_FILE" if [ $? -ne 0 ]; then print_warning "Failed to migrate MSI ROMHOLE, your platform's unique SMBIOS/DMI data may be lost" return fi else - dd if=/tmp/rom.bin of=/tmp/romhole.bin skip=$((0x17C0000)) bs=128K count=1 iflag=skip_bytes > /dev/null 2>&1 + dd if=/tmp/rom.bin of=/tmp/romhole.bin skip=$((0x17C0000)) bs=128K count=1 iflag=skip_bytes >/dev/null 2>>"$ERR_LOG_FILE" fi - $CBFSTOOL "$BIOS_UPDATE_FILE" write -r ROMHOLE -f /tmp/romhole.bin -u 2> /dev/null + $CBFSTOOL "$BIOS_UPDATE_FILE" write -r ROMHOLE -f /tmp/romhole.bin -u 2>>"$ERR_LOG_FILE" } smbios_migration() { @@ -601,10 +601,10 @@ check_vboot_keys() { FLASHROM_ADD_OPT_READ="--ifd -i bios" fi echo "Checking vboot keys." - $FLASHROM read_firm_mock -p "$PROGRAMMER_BIOS" ${FLASH_CHIP_SELECT} ${FLASHROM_ADD_OPT_READ} -r $BIOS_DUMP_FILE > /dev/null 2>/dev/null + $FLASHROM read_firm_mock -p "$PROGRAMMER_BIOS" ${FLASH_CHIP_SELECT} ${FLASHROM_ADD_OPT_READ} -r $BIOS_DUMP_FILE >/dev/null 2>>"$ERR_LOG_FILE" if [ $? -eq 0 ] && [ -f $BIOS_DUMP_FILE ]; then FLASH_KEYS=$(CBFSTOOL=$(which cbfstool) $FUTILITY dump_vboot_keys show $BIOS_DUMP_FILE | grep -i 'key sha1sum') - diff <(echo "$BINARY_KEYS") <(echo "$FLASH_KEYS") > /dev/null 2>&1 + diff <(echo "$BINARY_KEYS") <(echo "$FLASH_KEYS") >/dev/null 2>>"$ERR_LOG_FILE" # If keys are different we must additionally flash at least GBB region as well if [ $? -ne 0 ]; then FLASHROM_ADD_OPT_UPDATE+=" -i GBB" @@ -994,7 +994,7 @@ update_workflow() { else compare_versions $DASHARO_VERSION $UPDATE_VERSION if [ $? -ne 1 ]; then - error_exit "No update available for your machine" + error_exit "No update available for your machine" 2 fi fi diff --git a/scripts/dts-boot b/scripts/dts-boot index b99d68df..51bde634 100644 --- a/scripts/dts-boot +++ b/scripts/dts-boot @@ -5,7 +5,6 @@ # SPDX-License-Identifier: Apache-2.0 SBIN_DIR="/usr/sbin" -BIN_DIR="/usr/bin" FUM_EFIVAR="/sys/firmware/efi/efivars/FirmwareUpdateMode-d15b327e-ff2d-4fc1-abf6-c12bd08c1359" export DTS_FUNCS="$SBIN_DIR/dts-functions.sh" @@ -13,7 +12,29 @@ export DTS_ENV="$SBIN_DIR/dts-environment.sh" export DTS_SUBS="$SBIN_DIR/dts-subscription.sh" export DTS_HAL="$SBIN_DIR/dts-hal.sh" export DTS_MOCK_COMMON="$SBIN_DIR/common-mock-func.sh" -export DTS_LOG_FILE="/tmp/dts.log" +export BASH_ENV="$SBIN_DIR/logging" +export ERR_LOG_FILE_REALPATH +export DTS_LOG_FILE +export DTS_VERBOSE_LOG_FILE +export ERR_LOG_FILE +export SHELLOPTS + +# $ERR_LOG_FILE is fd that can only be written to: '>()'. To copy logs +# we need underlying file that can be copied +ERR_LOG_FILE_REALPATH="/var/local/dts-err_$(basename "$(tty)").log" +DTS_LOG_FILE="/tmp/dts_$(basename "$(tty)").log" +DTS_VERBOSE_LOG_FILE="/tmp/dts-verbose_$(basename "$(tty)").log" + +# shellcheck source=./logging +source "$BASH_ENV" +start_trace_logging +start_logging +if [ -z "$ERR_LOG_FILE" ]; then + # pass everything written to $ERR_LOG_FILE to logger function and save it's + # output to $ERR_LOG_FILE_REALPATH file + exec {ERR_LOG_FILE}> >(logger >> "$ERR_LOG_FILE_REALPATH") + ERR_LOG_FILE="/proc/$$/fd/$ERR_LOG_FILE" +fi # shellcheck source=../include/dts-environment.sh source $DTS_ENV @@ -25,5 +46,5 @@ source $DTS_HAL if [ -f $FUM_EFIVAR ]; then $SBIN_DIR/dasharo-deploy update fum else - $BIN_DIR/script -c $SBIN_DIR/dts "$DTS_LOG_FILE" + $SBIN_DIR/dts fi diff --git a/scripts/logging b/scripts/logging new file mode 100644 index 00000000..a712be91 --- /dev/null +++ b/scripts/logging @@ -0,0 +1,48 @@ +#!/bin/bash + +logger() { + while read -r LINE + do + echo "[$(date +%T.%3N)]: $LINE" + done +} + +start_logging() { + local file="$DTS_LOG_FILE" + if [ -z "$LOGGING" ]; then + LOGGING="true" + if [ -z "$DESC" ]; then + # Create file descriptor that echoes back anything written to it + # and also logs that line to file with added timestamp prefix + exec {DESC}> >(tee >(stdbuf -i0 -oL -eL ts "[%T]: " >> "$file")) + fi + exec 1>&$DESC + fi +} + +stop_logging() { + if [ -n "$LOGGING" ]; then + exec >&0 + LOGGING= + fi +} + +start_trace_logging() { + local file="$DTS_VERBOSE_LOG_FILE" + if [ -z "$BASH_XTRACEFD" ]; then + exec {xtrace_fd}>>"$file" + export BASH_XTRACEFD=${xtrace_fd} + set -x + fi +} + +stop_trace_logging() { + if [ -n "$BASH_XTRACEFD" ]; then + set +x + BASH_XTRACEFD= + fi +} + +export PS4="+[\$(date +%T.%3N)]:\${BASH_SOURCE[0]}:\${LINENO[0]}:\${FUNCNAME[0]:-main}: " +export LOGGING +export DESC