-
Notifications
You must be signed in to change notification settings - Fork 3
Add tui-sh #121
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Add tui-sh #121
Changes from all commits
34a6e45
304ab04
d25d2d2
0e4c693
508faf9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -3,6 +3,7 @@ | |||||
| # SPDX-FileCopyrightText: 2024 3mdeb <contact@3mdeb.com> | ||||||
| # | ||||||
| # 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 | ||||||
|
Comment on lines
-14
to
-16
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why have you deleted the traps?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. tui-sh already traps 2 of those (except https://github.com/3mdeb/tui-sh/blob/24e778398c4fdc2c6be06ec271a1bb6737a426d2/lib/tui-lib.sh#L46 |
||||||
| # those won't change | ||||||
| DTS_VERSION=$(grep "VERSION_ID" ${OS_VERSION_FILE} | cut -d "=" -f 2-) | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why cant't wwe do it in |
||||||
| 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" | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A typo?
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes |
||||||
| 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 | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should add a function for |
||||||
| 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" | ||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't we dynamically determine free file descriptor and use it? We must not hardcode anything.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We create it ourselves, so why not? What's the possible problematic scenario here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Race condition with other application for the hardcoded file descriptor.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could be done in e.g.
dts-bootbut then we will have to keep separate state file perdts-boot(or at least pertty) so there is no race condition (which we might want to do anyway). This could probably be implemented better, as I think it won't work with multiline variables. I just needed some way to change variables from callbacks and this was quick workaround.