diff --git a/Makefile b/Makefile index 02de9112..7cd79699 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ SBINDIR ?= /usr/sbin SYSCONFDIR ?= /etc install: - install -d $(DESTDIR)$(SBINDIR) + install -d $(DESTDIR)$(SBINDIR)/tui_callbacks install -m 0755 include/dts-environment.sh $(DESTDIR)$(SBINDIR) install -m 0755 include/dts-functions.sh $(DESTDIR)$(SBINDIR) @@ -20,9 +20,11 @@ install: install -m 0755 scripts/dts-boot.sh $(DESTDIR)$(SBINDIR)/dts-boot install -m 0755 scripts/ec_transition.sh $(DESTDIR)$(SBINDIR)/ec_transition install -m 0755 scripts/logging.sh $(DESTDIR)$(SBINDIR)/logging + install -m 0755 tui/tui_callbacks/* $(DESTDIR)$(SBINDIR)/tui_callbacks/ install -m 0755 reports/dasharo-hcl-report.sh $(DESTDIR)$(SBINDIR)/dasharo-hcl-report install -m 0755 reports/touchpad-info.sh $(DESTDIR)$(SBINDIR)/touchpad-info - install -d $(DESTDIR)$(SYSCONFDIR)/profile.d + install -d $(DESTDIR)$(SYSCONFDIR)/profile.d $(DESTDIR)$(SYSCONFDIR)/dts install -m 0755 dts-profile.sh $(DESTDIR)$(SYSCONFDIR)/profile.d + install -m 0644 tui/*.yaml $(DESTDIR)$(SYSCONFDIR)/dts/ diff --git a/include/dts-environment.sh b/include/dts-environment.sh index 53728cf9..7790ebdc 100644 --- a/include/dts-environment.sh +++ b/include/dts-environment.sh @@ -9,6 +9,8 @@ source $DTS_HAL # shellcheck source=../include/dts-functions.sh source $DTS_FUNCS +# shellcheck disable=SC1090 +source "$DTS_TUI_LIB" # Text colors: NORMAL='\033[0m' diff --git a/include/dts-functions.sh b/include/dts-functions.sh index d78fe905..8cac79c7 100644 --- a/include/dts-functions.sh +++ b/include/dts-functions.sh @@ -22,24 +22,24 @@ function echo_yellow() { # print_warning # Print yellow warning print_warning() { - echo_yellow "$1" + tui_echo_yellow "$1" } # print_error # Print red error print_error() { - echo_red "$1" + tui_echo_red "$1" } # print_error # Print green print_ok() { - echo_green "$1" + tui_echo_green "$1" } # Clears the line, usable for carriage returns to make sure no garbage is left. clear_line() { - printf '\r\033[K' + tui_clear_line } check_if_dasharo() { @@ -1122,18 +1122,19 @@ sync_clocks() { } print_disclaimer() { - echo -e \ - "Please note that the report is not anonymous, but we will use it only for\r -backup and future improvement of the Dasharo product. Every log is encrypted\r -and sent over HTTPS, so security is assured.\r -If you still have doubts, you can skip HCL report generation.\r\n -What is inside the HCL report? We gather information about:\r - - PCI, Super I/O, GPIO, EC, audio, and Intel configuration,\r - - MSRs, CMOS NVRAM, CPU info, DIMMs, state of touchpad, SMBIOS and ACPI tables,\r - - Decoded BIOS information, full firmware image backup, kernel dmesg,\r - - IO ports, input bus types, and topology - including I2C and USB,\r -\r -You can find more info about HCL in docs.dasharo.com/glossary\r" + tui_echo_normal \ + "Please note that the report is not anonymous, but we will use it only for +backup and future improvement of the Dasharo product. Every log is encrypted +and sent over HTTPS, so security is assured. +If you still have doubts, you can skip HCL report generation. + +What is inside the HCL report? We gather information about: + - PCI, Super I/O, GPIO, EC, audio, and Intel configuration, + - MSRs, CMOS NVRAM, CPU info, DIMMs, state of touchpad, SMBIOS and ACPI tables, + - Decoded BIOS information, full firmware image backup, kernel dmesg, + - IO ports, input bus types, and topology - including I2C and USB, + +You can find more info about HCL in docs.dasharo.com/glossary" } show_ram_inf() { @@ -1181,7 +1182,7 @@ show_ram_inf() { # Print the extracted values preformatted: for entry in "${memory_devices_array[@]}"; do - echo -e "${BLUE}**${YELLOW} RAM ${entry}" + echo -e "RAM ${entry}" done start_trace_logging } @@ -1232,11 +1233,9 @@ show_ssh_info() { # Display "check your connection" in red color in IP field in case no IPV4 # address is assigned, otherwise display IP/PORT: if [[ -z "$ip" ]]; then - echo -e "${BLUE}**${NORMAL} SSH status: ${GREEN}ON${NORMAL} IP: ${RED}check your connection${NORMAL}" - echo -e "${BLUE}*********************************************************${NORMAL}" + tui_echo_red "check your connection" else - echo -e "${BLUE}**${NORMAL} SSH status: ${GREEN}ON${NORMAL} IP: ${ip}${NORMAL}" - echo -e "${BLUE}*********************************************************${NORMAL}" + echo "${ip}" fi fi } @@ -1951,3 +1950,28 @@ ask_for_choice() { fi done } + +# change_global_state variable value +# after function finishes, state/variable value can be retrieved +# via get_global_state +set_global_state() { + local var="$1" + local value="$2" + ( + flock -x 200 + touch "${DTS_STATE}" + sed -i "/^${var}=/d" "${DTS_STATE}" + echo "${var}=${value}" >>"${DTS_STATE}" + ) 200>"${DTS_STATE_LOCKFILE}" +} + +get_global_state() { + local var="$1" + ( + flock -x 200 + touch "${DTS_STATE}" + # print in first occurrence of = + awk -F '=' -v var="${var}" '$0 ~ "^" var "=" {print $2; exit}' "${DTS_STATE}" + + ) 200>"${DTS_STATE_LOCKFILE}" +} diff --git a/include/dts-subscription.sh b/include/dts-subscription.sh index 1f8a16b8..20b8854e 100644 --- a/include/dts-subscription.sh +++ b/include/dts-subscription.sh @@ -102,10 +102,8 @@ check_dts_extensions_access() { } get_dpp_creds() { - echo "" - read -p "Enter DPP email: " 'DPP_EMAIL' - echo "" - read -p "Enter password: " 'DPP_PASSWORD' + DPP_EMAIL=$(tui_read_prompt "Enter DPP email") + DPP_PASSWORD=$(tui_read_prompt "Enter password") # Export DPP creds to a file for future use. Currently these are being used # for both: MinIO (and its mc CLI) and cloudsend (deprecated, all DPP @@ -113,7 +111,7 @@ get_dpp_creds() { echo ${DPP_EMAIL} >>${DPP_CREDENTIAL_FILE} echo ${DPP_PASSWORD} >>${DPP_CREDENTIAL_FILE} - print_ok "Dasharo DPP credentials have been saved" + tui_echo_green "Dasharo DPP credentials have been saved" } login_to_dpp_server() { @@ -143,10 +141,10 @@ subscription_routine() { if [ -e "${DPP_CREDENTIAL_FILE}" ]; then DPP_EMAIL=$(sed -n '1p' <${DPP_CREDENTIAL_FILE} | tr -d '\n') DPP_PASSWORD=$(sed -n '2p' <${DPP_CREDENTIAL_FILE} | tr -d '\n') - export DPP_IS_LOGGED="true" + set_global_state "DPP_IS_LOGGED" "true" else unset DPP_EMAIL - unset DPP_IS_LOGGED + set_global_state DPP_IS_LOGGED return 1 fi @@ -181,7 +179,7 @@ download_dpp_package() { # Make sure all paths exist: check_dasharo_package_env - echo "Downloading package $package_name..." + tui_echo_normal "Downloading package $package_name..." # Get package link: local download_link @@ -208,7 +206,7 @@ install_dpp_package() { check_dasharo_package_env - echo "Installing package $package_name..." + tui_echo_normal "Installing package $package_name..." update_package_list || return 1 @@ -231,7 +229,7 @@ install_dpp_package() { } install_all_dpp_packages() { - echo "Installing available DTS extensions..." + tui_echo_normal "Installing available DTS extensions..." update_package_list || return 1 @@ -240,7 +238,7 @@ install_all_dpp_packages() { packages_to_download=$(jq -r '.key' "$DPP_AVAIL_PACKAGES_LIST") if [ -z "$packages_to_download" ]; then - echo "No packages to install." + tui_echo_normal "No packages to install." return 1 fi @@ -256,7 +254,7 @@ install_all_dpp_packages() { } check_avail_dpp_packages() { - echo "Checking for available DTS extensions..." + tui_echo_normal "Checking for available DTS extensions..." AVAILABLE_PACKAGES=$(mc find --name "*.rpm" $DPP_SERVER_USER_ALIAS) if [ -z "$AVAILABLE_PACKAGES" ]; then diff --git a/scripts/dasharo-deploy.sh b/scripts/dasharo-deploy.sh index 3d0595ce..f612b3d7 100644 --- a/scripts/dasharo-deploy.sh +++ b/scripts/dasharo-deploy.sh @@ -56,12 +56,12 @@ print_firm_access_warning() { esac # Just a new line: - echo - echo " Dasharo Pro Package version (${_firm_type_print}) is also available." - echo " If you are interested, please visit" - echo " https://shop.3mdeb.com/product-category/dasharo-pro-package/" - # Just a new line: - echo + tui_echo_normal " + Dasharo Pro Package version (${_firm_type_print}) is also available. + If you are interested, please visit + https://shop.3mdeb.com/product-category/dasharo-pro-package/ + +" return 0 } diff --git a/scripts/dts-boot.sh b/scripts/dts-boot.sh index da24c4eb..9d2d417c 100644 --- a/scripts/dts-boot.sh +++ b/scripts/dts-boot.sh @@ -4,14 +4,20 @@ # # SPDX-License-Identifier: Apache-2.0 -SBIN_DIR="/usr/sbin" +export SBIN_DIR="/usr/sbin" FUM_EFIVAR="/sys/firmware/efi/efivars/FirmwareUpdateMode-d15b327e-ff2d-4fc1-abf6-c12bd08c1359" +export CONF_DIR="/etc/dts" +export RUN_DIR="/var/run/dts" export DTS_FUNCS="$SBIN_DIR/dts-functions.sh" 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_TUI_LIB="/usr/lib/tui/tui-lib.sh" +export DTS_TUI_CONF="$CONF_DIR/dts-tui.yaml" +export DTS_STATE="$RUN_DIR/state.sh" +export DTS_STATE_LOCKFILE="/var/lock/dts-state" export BASH_ENV="$SBIN_DIR/logging" export TMP_LOG_DIR="/tmp/logs" export ERR_LOG_FILE_REALPATH @@ -21,6 +27,7 @@ export ERR_LOG_FILE export SHELLOPTS mkdir -p "$TMP_LOG_DIR" +mkdir -p "$RUN_DIR" # $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" diff --git a/scripts/dts.sh b/scripts/dts.sh index 018b5dab..63cbdd28 100644 --- a/scripts/dts.sh +++ b/scripts/dts.sh @@ -3,6 +3,7 @@ # SPDX-FileCopyrightText: 2024 3mdeb # # SPDX-License-Identifier: Apache-2.0 +# shellcheck disable=SC2034 # shellcheck source=../include/dts-environment.sh source $DTS_ENV @@ -11,47 +12,72 @@ source $DTS_FUNCS # shellcheck source=../include/dts-subscription.sh source $DTS_SUBS -trap : 2 -trap : 3 -trap wait_for_input EXIT +# those won't change +DTS_VERSION=$(grep "VERSION_ID" ${OS_VERSION_FILE} | cut -d "=" -f 2-) +RAM_INFO="$(show_ram_inf)" +SHOW_DASHARO_FIRMWARE="true" +if check_if_dasharo; then + SHOW_TRANSITION="true" + SHOW_FUSE="true" +else + SHOW_TRANSITION="false" + SHOW_FALSE="false" +fi -wait_for_input() { - code=$? - if [[ $code -ne 0 ]]; then - read -p "Press Enter to continue." +set_menu_vars() { + DPP_IS_LOGGED=$(get_global_state DPP_IS_LOGGED) + export DPP_IS_LOGGED + DISPLAY_CREDENTIALS=$(get_global_state DISPLAY_CREDENTIALS) + + if check_if_dasharo; then + DASHARO_FIRMWARE_LABEL="Update Dasharo Firmware" + else + DASHARO_FIRMWARE_LABEL="Install Dasharo Firmware" + fi + if [ "${SYSTEM_VENDOR}" != "QEMU" ] && [ "${SYSTEM_VENDOR}" != "Emulation" ]; then + SHOW_RESTORE_FIRMWARE="true" + else + SHOW_RESTORE_FIRMWARE="false" + fi + + if [ "${DPP_IS_LOGGED}" = "true" ]; then + DPP_KEYS_LABEL="Edit your DPP keys" + else + DPP_KEYS_LABEL="Load your DPP keys" + fi + if systemctl is-active sshd &>/dev/null; then + SSH_STATUS="$(tui_echo_green ON)" + SSH_IP="$(show_ssh_info)" + SSH_LABEL="stop SSH server" + SSH_ACTIVE="true" + else + SSH_LABEL="launch SSH server" + SSH_ACTIVE="false" + fi + SEND_LOGS_ACTIVE=$(get_global_state SEND_LOGS_ACTIVE) + export SEND_LOGS_ACTIVE + if [ "${SEND_LOGS_ACTIVE}" = "true" ]; then + SEND_LOGS_LABEL="disable sending DTS logs" + else + SEND_LOGS_LABEL="enable sending DTS logs" fi - exit $code -} -while :; do - clear - # Do some subscription routine each time menu is rendered: - subscription_routine - - # Header should always be printed: - show_header - if [ -z "$DPP_SUBMENU_ACTIVE" ]; then - show_hardsoft_inf - show_dpp_credentials - show_ssh_info - show_main_menu - elif [ -n "$DPP_SUBMENU_ACTIVE" ]; then - show_dpp_submenu + if [ "${DISPLAY_CREDENTIALS}" = "true" ]; then + DPP_EMAIL_DISPLAY=$(mc alias ls premium --json | jq -r '.accessKey') + DPP_PASSWORD_DISPLAY=$(mc alias ls premium --json | jq -r '.secretKey') + DISPLAY_CRED_LABEL="hide DPP credentials" + else + DPP_EMAIL_DISPLAY="***************" + DPP_PASSWORD_DISPLAY="***************" + DISPLAY_CRED_LABEL="display DPP credentials" fi - show_footer - - echo - read -n 1 OPTION - echo - - # If OPTION is being matched with smth inside *_options functions the - # functions return 0 and loop start over, if not: next *_options function is - # being checked: - if [ -z "$DPP_SUBMENU_ACTIVE" ]; then - main_menu_options $OPTION && continue - elif [ -n "$DPP_SUBMENU_ACTIVE" ]; then - dpp_submenu_options $OPTION && continue + if [ -f "${DPP_SUBMENU_JSON}" ]; then + SHOW_DTS_EXTENSIONS="true" fi +} - footer_options $OPTION -done +tui_register_pre_render_callback subscription_routine +tui_register_pre_render_callback set_menu_vars +tui_register_pre_render_callback stop_trace_logging +tui_register_post_render_callback start_trace_logging +tui_run "$DTS_TUI_CONF" diff --git a/tui/dts-tui.yaml b/tui/dts-tui.yaml new file mode 100644 index 00000000..6b0f04c6 --- /dev/null +++ b/tui/dts-tui.yaml @@ -0,0 +1,96 @@ +--- +header: + title: " Dasharo Tools Suite Script ${DTS_VERSION} " + subtitle: " (c) Dasharo " + link: "https://github.com/Dasharo/dasharo-issues" + +sections: + - label: "HARDWARE INFORMATION" + entries: + - label: "System Inf." + value: "${SYSTEM_VENDOR} ${SYSTEM_MODEL}" + - label: "Baseboard Inf." + value: "${SYSTEM_VENDOR} ${BOARD_MODEL}" + - label: "CPU Inf." + value: "${CPU_VERSION}" + - label: "RAM Virtual" + value: "${RAM_INFO:-Not Specified}" + + - label: "FIRMWARE INFORMATION" + entries: + - label: "BIOS Inf." + value: "${BIOS_VENDOR} ${BIOS_VERSION}" + + - label: "DPP credentials" + condition: "${DPP_IS_LOGGED}" + entries: + - label: "Email" + value: "${DPP_EMAIL_DISPLAY}" + - label: "Password" + value: "${DPP_PASSWORD_DISPLAY}" + + - label: "SSH status: ${SSH_STATUS}" + condition: "${SSH_ACTIVE}" + entries: + - label: "IP" + value: "${SSH_IP}" + +menu: + - key: "1" + label: "Dasharo HCL report" + callback: "${SBIN_DIR}/tui_callbacks/hcl-report.sh" + + - key: "2" + label: "${DASHARO_FIRMWARE_LABEL}" + callback: "${SBIN_DIR}/tui_callbacks/dasharo-firmware.sh" + condition: "${SHOW_DASHARO_FIRMWARE}" + + - key: "3" + label: "Restore firmware from Dasharo HCL report" + callback: "${SBIN_DIR}/tui_callbacks/restore-firmware.sh" + condition: "${SHOW_RESTORE_FIRMWARE}" + + - key: "4" + label: "${DPP_KEYS_LABEL}" + callback: "${SBIN_DIR}/tui_callbacks/dpp-keys.sh" + + - key: "5" + label: "DTS extensions" + callback: "${SBIN_DIR}/tui_callbacks/dts-extensions.sh" + condition: "${SHOW_DTS_EXTENSIONS}" + + - key: "6" + label: "Transition Dasharo Firmware" + callback: "${SBIN_DIR}/tui_callbacks/transition.sh" + condition: "${SHOW_TRANSITION}" + + - key: "7" + label: "Fuse platform" + callback: "${SBIN_DIR}/tui_callbacks/fuse.sh" + condition: "${SHOW_FUSE}" + +footer: + - key: "R" + label: "reboot" + callback: "${SBIN_DIR}/tui_callbacks/reboot.sh" + + - key: "P" + label: "poweroff" + callback: "${SBIN_DIR}/tui_callbacks/poweroff.sh" + + - key: "S" + label: "enter shell" + callback: "${SBIN_DIR}/tui_callbacks/shell.sh" + + - key: "K" + label: "${SSH_LABEL}" + callback: "${SBIN_DIR}/tui_callbacks/ssh-toggle.sh" + + - key: "L" + label: "${SEND_LOGS_LABEL}" + callback: "${SBIN_DIR}/tui_callbacks/toggle-logs.sh" + + - key: "C" + label: "${DISPLAY_CRED_LABEL}" + callback: "${SBIN_DIR}/tui_callbacks/toggle-credentials.sh" + condition: "${DPP_IS_LOGGED}" diff --git a/tui/header.yaml b/tui/header.yaml new file mode 100644 index 00000000..dc9889fc --- /dev/null +++ b/tui/header.yaml @@ -0,0 +1,5 @@ +--- +header: + title: " Dasharo Tools Suite Script ${DTS_VERSION} " + subtitle: " (c) Dasharo " + link: "https://github.com/Dasharo/dasharo-issues" diff --git a/tui/tui_callbacks/dasharo-firmware.sh b/tui/tui_callbacks/dasharo-firmware.sh new file mode 100755 index 00000000..d93004f5 --- /dev/null +++ b/tui/tui_callbacks/dasharo-firmware.sh @@ -0,0 +1,65 @@ +#!/usr/bin/env bash + +# shellcheck source=../../include/dts-environment.sh +source "$DTS_ENV" +# shellcheck source=../../include/dts-functions.sh +source "$DTS_FUNCS" + +if ! check_if_dasharo; then + # flashrom does not support QEMU, but installation depends on flashrom. + # TODO: this could be handled in a better way: + [ "${SYSTEM_VENDOR}" = "QEMU" ] || [ "${SYSTEM_VENDOR}" = "Emulation" ] && exit 0 + + if wait_for_network_connection; then + tui_echo_normal "Preparing ..." + if [ -z "${LOGS_SENT}" ]; then + export SEND_LOGS="true" + export DEPLOY_REPORT="true" + if ! ${CMD_DASHARO_HCL_REPORT}; then + tui_echo_normal "Unable to connect to dl.dasharo.com for submitting the + \rHCL report. Please recheck your internet connection." + else + LOGS_SENT="1" + fi + fi + fi + + if [ -n "${LOGS_SENT}" ]; then + ${CMD_DASHARO_DEPLOY} install + result=$? + if [ "$result" -ne $OK ] && [ "$result" -ne $CANCEL ]; then + send_dts_logs ask && exit 0 + fi + fi +else + # TODO: This should be placed in dasharo-deploy: + # For NovaCustom TGL laptops with Dasharo version lower than 1.3.0, + # we shall run the ec_transition script instead. See: + # https://docs.dasharo.com/variants/novacustom_nv4x_tgl/releases/#v130-2022-10-18 + if [ "$SYSTEM_VENDOR" = "Notebook" ]; then + case "$SYSTEM_MODEL" in + "NS50_70MU" | "NV4XMB,ME,MZ") + compare_versions $DASHARO_VERSION 1.3.0 + if [ $? -eq 1 ]; then + # For Dasharo version lesser than 1.3.0 + print_warning "Detected NovaCustom hardware with version < 1.3.0" + print_warning "Need to perform EC transition after which the platform will turn off" + print_warning "Then, please power it on and proceed with update again" + print_warning "EC transition procedure will start in 5 seconds" + sleep 5 + ${CMD_EC_TRANSITION} + error_check "Could not perform EC transition" + fi + # Continue with regular update process for Dasharo version + # greater or equal 1.3.0 + ;; + esac + fi + + # Use regular update process for everything else + ${CMD_DASHARO_DEPLOY} update + result=$? + if [ "$result" -ne $OK ] && [ "$result" -ne $CANCEL ]; then + send_dts_logs ask && exit 0 + fi +fi diff --git a/tui/tui_callbacks/dpp-keys.sh b/tui/tui_callbacks/dpp-keys.sh new file mode 100755 index 00000000..5cc330eb --- /dev/null +++ b/tui/tui_callbacks/dpp-keys.sh @@ -0,0 +1,46 @@ +#!/usr/bin/env bash + +# shellcheck source=../../include/dts-environment.sh +source "$DTS_ENV" +# shellcheck source=../../include/dts-functions.sh +source "$DTS_FUNCS" +# shellcheck source=../../include/dts-subscription.sh +source $DTS_SUBS + +_result= +# Return if there was an issue when asking for credentials: +if ! get_dpp_creds; then + exit 0 +fi + +# Try to log in using available DPP credentials, start loop over if login +# was not successful: +if ! login_to_dpp_server; then + tui_echo_normal "Cannot log in to DPP server." + exit 0 +fi + +# Check for Dasharo Firmware for the current platform, continue to +# packages after checking: +check_for_dasharo_firmware +_result=$? +tui_echo_normal "Your credentials give access to:" +echo -n "Dasharo Pro Package (DPP): " +if [ $_result -eq 0 ]; then + # FIXME: what if credentials have access to + # firmware, but check_for_dasharo_firmware will not detect any platform? + # According to check_for_dasharo_firmware it will return 1 in both + # cases which means that we cannot detect such case. + tui_echo_normal "Dasharo Pro Package (DPP): $(tui_echo_green YES)" +else + tui_echo_normal "Dasharo Pro Package (DPP): NO" +fi + +echo -n "DTS Extensions: " + +if check_dts_extensions_access; then + tui_echo_normal "DTS Extensions: $(tui_echo_green YES)" + check_avail_dpp_packages && install_all_dpp_packages && parse_for_premium_submenu +else + tui_echo_normal "DTS Extensions: NO" +fi diff --git a/tui/tui_callbacks/dts-extensions.sh b/tui/tui_callbacks/dts-extensions.sh new file mode 100755 index 00000000..a8db3f6b --- /dev/null +++ b/tui/tui_callbacks/dts-extensions.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +# shellcheck source=../../include/dts-environment.sh +source "$DTS_ENV" + +extensions_yaml="/tmp/extensions.yaml" +cat "${CONF_DIR}/header.yaml" >"${extensions_yaml}" +yq -i '. += {"menu": [], "footer": [{"key": "Q", "label": "go back"}]}' "${extensions_yaml}" + +while IFS=$'\t' read -r file_name file_position _; do + export file_name file_position callback + callback="${DPP_PACKAGES_SCRIPTS_PATH}/${file_name}" + yq -i '.menu += {"key": strenv(file_position), "label": strenv(file_name), "callback": strenv(callback)}' "$extensions_yaml" +done < <(yq -p=json '.[] | [.file_name, .file_menu_position] | @tsv' "${DPP_SUBMENU_JSON}") + +tui_run "${extensions_yaml}" diff --git a/tui/tui_callbacks/fuse.sh b/tui/tui_callbacks/fuse.sh new file mode 100755 index 00000000..8429f04e --- /dev/null +++ b/tui/tui_callbacks/fuse.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash + +# shellcheck source=../../include/dts-environment.sh +source "$DTS_ENV" +# shellcheck source=../../include/dts-functions.sh +source "$DTS_FUNCS" + +check_if_dasharo || exit 0 + +${CMD_DASHARO_DEPLOY} fuse +result=$? +if [ "$result" -ne $OK ] && [ "$result" -ne $CANCEL ]; then + send_dts_logs ask && exit $OK +fi diff --git a/tui/tui_callbacks/hcl-report.sh b/tui/tui_callbacks/hcl-report.sh new file mode 100755 index 00000000..fa2c447d --- /dev/null +++ b/tui/tui_callbacks/hcl-report.sh @@ -0,0 +1,27 @@ +#!/usr/bin/env bash + +# shellcheck source=../../include/dts-environment.sh +source "$DTS_ENV" +# shellcheck source=../../include/dts-functions.sh +source "$DTS_FUNCS" + +print_disclaimer +if ask_for_confirmation "Do you want to support Dasharo development by sending us logs with your hardware configuration?"; then + export SEND_LOGS="true" + tui_echo_normal "Thank you for contributing to the Dasharo development!" +else + export SEND_LOGS="false" + tui_echo_normal "Logs will be saved in root directory." + tui_echo_normal "Please consider supporting Dasharo by sending the logs next time." +fi +if [ "${SEND_LOGS}" == "true" ]; then + # DEPLOY_REPORT variable is used in dasharo-hcl-report to determine + # which logs should be printed in the terminal, in the future whole + # dts scripting should get some LOGLEVEL and maybe dumping working + # logs to file + export DEPLOY_REPORT="false" + wait_for_network_connection && ${CMD_DASHARO_HCL_REPORT} +else + export DEPLOY_REPORT="false" + ${CMD_DASHARO_HCL_REPORT} +fi diff --git a/tui/tui_callbacks/poweroff.sh b/tui/tui_callbacks/poweroff.sh new file mode 100755 index 00000000..bf143029 --- /dev/null +++ b/tui/tui_callbacks/poweroff.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash + +# shellcheck source=../../include/dts-environment.sh +source "$DTS_ENV" + +$POWEROFF diff --git a/tui/tui_callbacks/reboot.sh b/tui/tui_callbacks/reboot.sh new file mode 100755 index 00000000..79b0b14a --- /dev/null +++ b/tui/tui_callbacks/reboot.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash + +# shellcheck source=../../include/dts-environment.sh +source "$DTS_ENV" + +$REBOOT diff --git a/tui/tui_callbacks/restore-firmware.sh b/tui/tui_callbacks/restore-firmware.sh new file mode 100755 index 00000000..d6cc00d5 --- /dev/null +++ b/tui/tui_callbacks/restore-firmware.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash + +# shellcheck source=../../include/dts-environment.sh +source "$DTS_ENV" +# shellcheck source=../../include/dts-functions.sh +source "$DTS_FUNCS" + +[ "${SYSTEM_VENDOR}" = "QEMU" ] || [ "${SYSTEM_VENDOR}" = "Emulation" ] && exit 0 + +if check_if_dasharo; then + if ! ${CMD_DASHARO_DEPLOY} restore; then + send_dts_logs ask && exit 0 + fi +fi diff --git a/tui/tui_callbacks/shell.sh b/tui/tui_callbacks/shell.sh new file mode 100755 index 00000000..bf0d50ba --- /dev/null +++ b/tui/tui_callbacks/shell.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash + +# shellcheck source=../../include/dts-environment.sh +source "$DTS_ENV" +# shellcheck source=../../include/dts-functions.sh +source "$DTS_FUNCS" + +tui_echo_normal "Entering shell, to leave type exit and press Enter or press LCtrl+D" +tui_echo_normal "" +send_dts_logs +stop_logging +${CMD_SHELL} +start_logging diff --git a/tui/tui_callbacks/ssh-toggle.sh b/tui/tui_callbacks/ssh-toggle.sh new file mode 100755 index 00000000..8549a55f --- /dev/null +++ b/tui/tui_callbacks/ssh-toggle.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash + +# shellcheck disable=SC1090 +source "$DTS_TUI_LIB" + +if systemctl is-active sshd &>/dev/null; then + tui_echo_green "Turning off the SSH server..." + systemctl stop sshd +else + tui_echo_yellow "Starting SSH server!" + tui_echo_yellow "Now you can log in into the system using root account." + tui_echo_yellow "Stopping server will not drop all connected sessions." + systemctl start sshd + tui_echo_green "Listening on IPs: $(ip -br -f inet a show scope global | grep UP | awk '{ print $3 }' | tr '\n' ' ')" +fi + +tui_read_key_to_continue diff --git a/tui/tui_callbacks/toggle-credentials.sh b/tui/tui_callbacks/toggle-credentials.sh new file mode 100755 index 00000000..1e8223dc --- /dev/null +++ b/tui/tui_callbacks/toggle-credentials.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash + +# shellcheck source=../../include/dts-environment.sh +source "$DTS_ENV" +# shellcheck source=../../include/dts-functions.sh +source "$DTS_FUNCS" + +DISPLAY_CREDENTIALS=$(get_global_state DISPLAY_CREDENTIALS) +if [ "${DISPLAY_CREDENTIALS}" = "true" ]; then + set_global_state DISPLAY_CREDENTIALS "false" +else + set_global_state DISPLAY_CREDENTIALS "true" +fi diff --git a/tui/tui_callbacks/toggle-logs.sh b/tui/tui_callbacks/toggle-logs.sh new file mode 100755 index 00000000..d7cd2520 --- /dev/null +++ b/tui/tui_callbacks/toggle-logs.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash + +# shellcheck source=../../include/dts-environment.sh +source "$DTS_ENV" +# shellcheck source=../../include/dts-functions.sh +source "$DTS_FUNCS" + +SEND_LOGS_ACTIVE=$(get_global_state SEND_LOGS_ACTIVE) +if [ "${SEND_LOGS_ACTIVE}" = "true" ]; then + set_global_state SEND_LOGS_ACTIVE "false" +else + set_global_state SEND_LOGS_ACTIVE "true" +fi diff --git a/tui/tui_callbacks/transition.sh b/tui/tui_callbacks/transition.sh new file mode 100755 index 00000000..013394c8 --- /dev/null +++ b/tui/tui_callbacks/transition.sh @@ -0,0 +1,15 @@ +#!/usr/bin/env bash + +# shellcheck source=../../include/dts-environment.sh +source "$DTS_ENV" +# shellcheck source=../../include/dts-functions.sh +source "$DTS_FUNCS" + +# No transition, if there is no Dasharo firmware installed: +check_if_dasharo || exit 0 + +${CMD_DASHARO_DEPLOY} transition +result=$? +if [ "$result" -ne $OK ] && [ "$result" -ne $CANCEL ]; then + send_dts_logs ask && exit $OK +fi