Skip to content

Commit 2ae9a21

Browse files
committed
refact+fix: dialogs and hostname
1 parent f637670 commit 2ae9a21

5 files changed

Lines changed: 20 additions & 20 deletions

File tree

‎system/cuos/dialog-edit-network.sh‎

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22

33
SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)
44

5-
export DIALOGRC="${SCRIPT_DIR}/dialog.rc"
5+
# shellcheck source=/dev/null
6+
source "${SCRIPT_DIR}/utils.sh"
7+
# shellcheck source=/dev/null
8+
source "${SCRIPT_DIR}/lib-dialog.sh"
69

7-
CONFIG_PATH="/system.json"
10+
CONFIG_PATH="${CONFIG_PATH:-"/system.json"}"
811
if [[ -n "${TEST}" ]]; then
912
CONFIG_PATH="system.json"
1013
fi
@@ -14,20 +17,6 @@ fi
1417
CONFIG_JSON="$(cat "$CONFIG_PATH" || echo '{}')"
1518
CONFIG_NEW="{}"
1619

17-
term() {
18-
if [[ -n "${TEST}" ]]; then "$@"; return; fi
19-
TERM=linux "$@" >/dev/tty1 </dev/tty1
20-
}
21-
22-
cuos_dialog() {
23-
dialog \
24-
--colors \
25-
--no-trim \
26-
--no-collapse \
27-
--cr-wrap \
28-
"$@"
29-
}
30-
3120
# --- Validation functions ---
3221
is_valid_hostname() {
3322
[[ "$1" =~ ^[a-zA-Z][a-zA-Z0-9\.-]+$ ]]

‎system/cuos/dialog-maintenance.sh‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ diagnostics_menu() {
183183
resources) check_resources ;;
184184
clogs) term_all cuos_logs ;;
185185
logs) term_all view_logs ;;
186-
docker) api_stream "docker ps" 30 120 docker ps ;;
186+
docker) api_stream_size "docker ps" 30 120 docker ps ;;
187187
ping) diagnostics_ping ;;
188188
dns) diagnostics_dns ;;
189189
"expert") expert ;;
@@ -247,7 +247,16 @@ diagnostics_dns() {
247247
expert() {
248248
confirm=$(DIALOGRC="${SCRIPT_DIR}/dialog-red.rc" term cuos_dialog --title "Expert Settings" --inputbox "You found the hidden expert settings.\nOnly continue, when you know what you are doing." 13 72 3>&1 1>&2 2>&3) || return 1
249249
if [[ "$confirm" != "CuOS" ]]; then msg "Aborted." "Expert Settings"; return 1; fi
250-
term_all vim "+set backupcopy=yes" /system.json
250+
cp "/system.json" /tmp/edit-system.json
251+
chown nobody:nogroup /tmp/edit-system.json
252+
term_all sudo -u nobody rvim /tmp/edit-system.json
253+
if ! jq . /tmp/edit-system.json >/dev/null 2>&1; then
254+
term msg "Invalid JSON"
255+
else
256+
cat /tmp/edit-system.json >/system.json
257+
api_stream "Applying system.json" cuos patch
258+
fi
259+
rm -f /tmp/edit-system.json
251260
}
252261

253262

‎system/cuos/dialog-reports.sh‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ change_vt
3232
JOURNAL_PID=$!
3333

3434
term cuos_dialog \
35-
--title "System Reports" \
35+
--title "System Reports: $(hostname)" \
3636
--exit-label "Intervention: Start configuration" \
3737
--tailbox "$tmpfile" 40 100
3838
EXIT_CODE_DIALOG="$?"

‎system/cuos/init.sh‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ set_hostname() {
100100
SYSTEM_HOSTNAME="device-${r1}${r2}"
101101
jq_replace \
102102
--arg hn "${SYSTEM_HOSTNAME}" \
103-
'.hostname = $hn'
103+
'.hostname = $hn' \
104+
"${CONFIG_PATH}"
104105
fi
105106
if [[ -n "${SYSTEM_HOSTNAME}" ]]; then
106107
echo "Setting hostname to $SYSTEM_HOSTNAME"

‎system/cuos/lib-dialog.sh‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ cuos_dialog() {
4141
"$@"
4242
}
4343

44+
4445
change_vt() {
4546
#alternative: TERM=linux setsid -w openvt -s -e -w -- dialog --clear --yesno Hi 6 40
4647
if [[ -z "${TEST:-}" && -z "${DIALOG_SUB}" ]]; then

0 commit comments

Comments
 (0)