Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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/
2 changes: 2 additions & 0 deletions include/dts-environment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
66 changes: 45 additions & 21 deletions include/dts-functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,24 @@ function echo_yellow() {
# print_warning <msg>
# Print yellow warning <msg>
print_warning() {
echo_yellow "$1"
tui_echo_yellow "$1"
}

# print_error <msg>
# Print red error <msg>
print_error() {
echo_red "$1"
tui_echo_red "$1"
}

# print_error <msg>
# Print green <msg>
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() {
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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 <val> in first occurrence of <var>=<val>
awk -F '=' -v var="${var}" '$0 ~ "^" var "=" {print $2; exit}' "${DTS_STATE}"

) 200>"${DTS_STATE_LOCKFILE}"
}
22 changes: 10 additions & 12 deletions include/dts-subscription.sh
Original file line number Diff line number Diff line change
Expand Up @@ -102,18 +102,16 @@ 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
# sibscribtions will be megrated to MinIO):
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() {
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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

Expand All @@ -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

Expand All @@ -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
Expand Down
12 changes: 6 additions & 6 deletions scripts/dasharo-deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
9 changes: 8 additions & 1 deletion scripts/dts-boot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
Expand Down
102 changes: 64 additions & 38 deletions scripts/dts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# SPDX-FileCopyrightText: 2024 3mdeb <[email protected]>
#
# SPDX-License-Identifier: Apache-2.0
# shellcheck disable=SC2034

# shellcheck source=../include/dts-environment.sh
source $DTS_ENV
Expand All @@ -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"
Loading