Skip to content

Commit 82604b7

Browse files
committed
refact: dialogs
1 parent 7faaec8 commit 82604b7

3 files changed

Lines changed: 45 additions & 16 deletions

File tree

‎system/cuos/api.sh‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -101,15 +101,15 @@ EOF
101101
"patch")
102102
report_info "cuos:patch" "Patching the system"
103103
CONFIG="$(echo "${INPUT}" | jq -c '.config // empty')"
104-
if ! echo "${CONFIG}" | check_config; then
105-
report_err "cuos:update:err_invalid_config" "Update: Invalid configuration provided."
106-
echo "Invalid configuration provided."
107-
exit 0
108-
fi
109-
# save current config for rollback:
110-
cat "${CONFIG_PATH}" >"${NEXT_CONFIG_PATH}"
111-
112104
if [[ -n "${CONFIG}" ]]; then
105+
if ! echo "${CONFIG}" | check_config; then
106+
report_err "cuos:update:err_invalid_config" "Update: Invalid configuration provided."
107+
echo "Invalid configuration provided."
108+
exit 0
109+
fi
110+
# save current config for rollback:
111+
cat "${CONFIG_PATH}" >"${NEXT_CONFIG_PATH}"
112+
113113
jq_replace \
114114
--argjson config "${CONFIG}" \
115115
'. * $config' \

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,14 @@ is_valid_name_or_ip() {
4141
is_valid_hostname "$@" || is_valid_ip "$@"
4242
}
4343

44+
is_valid_names_or_ips() {
45+
[[ -z "$1" ]] && return 1
46+
for ip in $1; do
47+
is_valid_name_or_ip "${ip}" || return 1
48+
done
49+
return 0
50+
}
51+
4452
edit() {
4553
local field="$1"
4654
local displayname="$2"
@@ -117,7 +125,7 @@ if mode_network; then
117125
edit '.network['"$i"']["network-mask"]' "Network mask" is_valid_ip || exit 1
118126
edit '.network['"$i"']["gateway"]' "Gateway" is_valid_ip || exit 1
119127
edit '.network['"$i"']["dns-server"]' "DNS server(s)" is_valid_ips || exit 1
120-
edit '.network['"$i"']["ntp"]' "NTP server(s)" is_valid_name_or_ip || exit 1
128+
edit '.network['"$i"']["ntp"]' "NTP server(s)" is_valid_names_or_ips || exit 1
121129
fi
122130
done
123131

‎system/cuos/dialog-maintenance.sh‎

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ maintenance_menu() {
3838
done
3939
}
4040

41+
installation_precheck() {
42+
}
43+
4144
install_menu() {
4245
local extra
4346
extra=()
@@ -76,6 +79,21 @@ install_menu() {
7679
}
7780

7881

82+
hash_admin_password() {
83+
local password="$1"
84+
local saltlen=8
85+
local salt
86+
salt="$(head -c "$saltlen" /dev/urandom)"
87+
88+
local pwhash
89+
pwhash="$(printf "%s" "$password" | cat - <(printf "%s" "$salt") | openssl dgst -sha1 -binary)"
90+
91+
local ssha
92+
ssha="$(printf "%s%s" "$pwhash" "$salt" | base64)"
93+
94+
echo "{SSHA}$ssha"
95+
}
96+
7997
change_admin_password() {
8098
local p1 p2
8199
while true; do
@@ -92,8 +110,9 @@ change_admin_password() {
92110
(
93111
set +x
94112
jq_replace \
95-
--arg password "$p1" \
96-
'.system_admin_password = $password'
113+
--arg password "$(hash_admin_password "$p1")" \
114+
'.system_admin_password = $password' \
115+
"${CONFIG_PATH}"
97116
)
98117
msg "Administrator password set." "Password"
99118
return 0
@@ -106,8 +125,9 @@ system_actions_menu() {
106125
choice="$(fmenu "System Actions" "Select an action:" 17 72 10 \
107126
"reboot" "Reboot System" \
108127
"shutdown" "Shutdown System" \
109-
"update" "Apply System Update" \
110-
"rollback" "Rollback Last Update" \
128+
- " " \
129+
"update" "Trigger System Update" \
130+
"rollback" "Rollback Last Update (OS only)" \
111131
"expand" "Expand Filesystem" \
112132
"factory" "Factory Reset" \
113133
- " " \
@@ -129,7 +149,7 @@ system_actions_menu_installation() {
129149
local choice
130150
choice="$(fmenu "System Actions" "Select an action:" 17 72 10 \
131151
"shutdown" "Shutdown System" \
132-
"update" "Apply System Update" \
152+
"update" "Trigger System Update" \
133153
"expand" "Expand Filesystem" \
134154
- " " \
135155
"back" "\Z5Back\Z0")" || return 1
@@ -154,14 +174,14 @@ system_shutdown() {
154174
}
155175

156176
system_update() {
157-
if ! yesno "Apply the latest system update?\n\nThis may take several minutes and the system may reboot automatically." "System Update" 11 70; then
177+
if ! yesno "Trigger system update?\n\nThis may take several minutes to complete and the system may reboot automatically." "System Update" 11 70; then
158178
return
159179
fi
160180
api_stream "Applying System Update" cuos trigger-update
161181
}
162182

163183
system_rollback() {
164-
if ! yesno "Rollback to the previous system version?\n\nThe system will boot into the previous partition." "Rollback" 11 72; then
184+
if ! yesno "Rollback last update of the operating system?\n\nThe system will boot into the previous slot. User data will not be affected" "Rollback" 11 72; then
165185
return
166186
fi
167187
api_stream "Preparing Rollback" cuos rollback
@@ -282,6 +302,7 @@ change_vt
282302

283303
if [[ "${1:-}" == "--install" ]]; then
284304
shift
305+
installation_precheck
285306
install_menu "$@"
286307
sleep 1
287308
else

0 commit comments

Comments
 (0)