Skip to content

Commit b1e7e68

Browse files
committed
Merge remote-tracking branch 'origin/development'
2 parents fb1768b + 336f023 commit b1e7e68

18 files changed

Lines changed: 1005 additions & 29 deletions

‎.github/workflows/docker-image-factory.yml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ on:
44
push:
55
branches:
66
- main
7+
- development
78
tags:
89
- '*'
910
paths:

‎.github/workflows/docker-system.yml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ on:
44
push:
55
branches:
66
- main
7+
- development
78
tags:
89
- '*'
910
paths:

‎.github/workflows/docker-updater.yml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ on:
44
push:
55
branches:
66
- main
7+
- development
78
tags:
89
- '*'
910
paths:

‎system/Dockerfile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ RUN apt-get update && apt-get install --no-install-recommends -y \
4242
docker-cli \
4343
docker.io \
4444
gnupg2 \
45+
inetutils-ping \
4546
jq \
4647
jsonschema-jv \
4748
kbd \

‎system/cuos/api.sh‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ EOF
5151
"update")
5252
report_info "cuos:update:start" "Update process was triggered"
5353
CONFIG="$(echo "${INPUT}" | jq -c '.config // {}')"
54+
if ! echo "${CONFIG}" | check_config; then
55+
report_err "cuos:update:err_invalid_config" "Update: Invalid configuration provided."
56+
echo "Invalid configuration provided."
57+
exit 0
58+
fi
5459

5560
# update and swap configuration (config -> new)
5661
NEW_CONFIG="$(echo "${CONFIG}" | jq -s '.[0] * .[1]' "${CONFIG_PATH}" -)" || exit 0
@@ -81,6 +86,11 @@ EOF
8186
"patch")
8287
report_info "cuos:patch" "Patching the system"
8388
CONFIG="$(echo "${INPUT}" | jq -c '.config // empty')"
89+
if ! echo "${CONFIG}" | check_config; then
90+
report_err "cuos:update:err_invalid_config" "Update: Invalid configuration provided."
91+
echo "Invalid configuration provided."
92+
exit 0
93+
fi
8494
# save current config for rollback:
8595
cat "${CONFIG_PATH}" >"${NEXT_CONFIG_PATH}"
8696

‎system/cuos/app.sh‎

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ HOME="${HOME:-/root}"
1313
export CONFIG_PATH="/system.json"
1414
LAST_CONFIG_PATH="/system_next.json"
1515

16+
RUN_CONFIG="$(jq -r '.run_config' "${CONFIG_PATH}")"
17+
if [[ "${RUN_CONFIG}" = "true" ]]; then
18+
"${SCRIPT_DIR}/dialog-config.sh"
19+
fi
20+
21+
"${SCRIPT_DIR}/dialog-reports.sh" &
22+
1623
action_on_failure() {
1724
report_err "$@"
1825
sleep 60
@@ -56,7 +63,7 @@ download_image() {
5663

5764
while true; do
5865
check_rollback
59-
echo "Pulling $IMAGE ... (Digest should be ${IMAGE_DIGEST}, but is ${CURRENT_IMAGE_DIGEST})"
66+
echo "Pulling $IMAGE_PATH ... (Digest should be ${IMAGE_DIGEST})"
6067
if docker pull "${INITIAL_IMAGE}"; then
6168
CURRENT_IMAGE_DIGEST=$(docker image inspect --format '{{index .RepoDigests 0}}' "${IMAGE_PATH}" 2>/dev/null | cut -d'@' -f2)
6269
if [[ -n "${CURRENT_IMAGE_DIGEST}" && "${CURRENT_IMAGE_DIGEST}" = "${IMAGE_DIGEST}" ]]; then
@@ -124,18 +131,18 @@ if ! docker ps --format '{{.Names}}' | grep -q "^${CONTAINER_NAME}\$"; then
124131
DOCKER_ARGS="$(docker inspect --format '{{ index .Config.Labels "dev.cuos.app_command" }}' "${INITIAL_IMAGE}")"
125132
if [[ -z "${DOCKER_ARGS}" ]]; then
126133
DOCKER_ARGS="\
127-
--device /dev/tty1 \
134+
--device /dev/tty1 \
128135
--network=host \
129-
--volume /var/run/docker.sock:/var/run/docker.sock \
136+
--volume /var/run/docker.sock:/var/run/docker.sock \
130137
--volume /root/.docker/config.json:/root/.docker/config.json:ro \
131138
--volume /system.json:/system.json:ro \
132139
--volume /etc/partition_mode:/etc/partition_mode:ro \
133140
--volume /var/run/cuos.sock:/var/run/cuos.sock \
134141
--volume /usr/local/share/ca-certificates/custom:/usr/local/share/ca-certificates/custom:ro"
135-
fi
142+
fi
136143

137144
touch "${HOME}/.docker/config.json"
138-
# shellcheck disable=SC2086
145+
# shellcheck disable=SC2086
139146
docker run \
140147
--detach \
141148
--pull=never \

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

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
#!/bin/bash
2+
3+
SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)
4+
5+
# shellcheck source=/dev/null
6+
source "${SCRIPT_DIR}/utils.sh"
7+
# shellcheck source=/dev/null
8+
source "${SCRIPT_DIR}/lib-dialog.sh"
9+
10+
CONFIG_PATH="${CONFIG_PATH:-"/system.json"}"
11+
if [[ -n "${TEST:-}" ]]; then
12+
CONFIG_PATH="system.json"
13+
fi
14+
15+
16+
# Load initial config into a variable
17+
CONFIG_JSON="$(cat "$CONFIG_PATH" || echo '{}')"
18+
CONFIG_NEW="{}"
19+
20+
# --- Validation functions ---
21+
is_valid_hostname() {
22+
[[ "$1" =~ ^[a-zA-Z][a-zA-Z0-9\.-]+$ ]]
23+
}
24+
25+
is_valid_ip() {
26+
[[ "$1" =~ ^([0-9]{1,3}\.){3}[0-9]{1,3}$ ]] && \
27+
for octet in $(echo "$1" | tr '.' ' '); do
28+
[[ "$octet" -ge 0 && "$octet" -le 255 ]] || return 1
29+
done
30+
}
31+
32+
is_valid_ips() {
33+
[[ -z "$1" ]] && return 1
34+
for ip in $1; do
35+
is_valid_ip "${ip}" || return 1
36+
done
37+
return 0
38+
}
39+
40+
is_valid_name_or_ip() {
41+
is_valid_hostname "$@" || is_valid_ip "$@"
42+
}
43+
44+
edit() {
45+
local field="$1"
46+
local displayname="$2"
47+
local check_function="$3"
48+
49+
local value
50+
value="$(echo "$CONFIG_JSON" | jq -r "${field} // \"\"")"
51+
while true; do
52+
if ! value="$(term cuos_dialog --inputbox "${displayname}:" 8 40 "${value}" 3>&1 1>&2 2>&3)"; then
53+
return 1
54+
fi
55+
if [[ -z "${check_function}" ]] || "${check_function}" "${value}"; then
56+
CONFIG_NEW="$(echo "${CONFIG_NEW}" | jq --arg val "${value}" "${field}"' = $val')"
57+
CONFIG_JSON="$(echo "${CONFIG_JSON}" | jq --arg val "${value}" "${field}"' = $val')"
58+
return 0
59+
fi
60+
term cuos_dialog --no-cancel --msgbox "Invalid format. Please try again." 8 40
61+
done
62+
}
63+
64+
question() {
65+
local field="$1"
66+
local displayname="$2"
67+
local default="${3:-''}"
68+
69+
local value
70+
value="$(echo "$CONFIG_JSON" | jq -r "${field}")"
71+
if [[ "${value}" == "null" ]]; then
72+
value="${default}"
73+
fi
74+
local choise="--clear" # for nop
75+
if [[ "${value}" != "true" ]]; then
76+
choise="--defaultno"
77+
fi
78+
local newvalue=false
79+
if term cuos_dialog "${choise}" --yesno "${displayname}" 7 40; then
80+
newvalue=true
81+
fi
82+
CONFIG_NEW="$(echo "$CONFIG_NEW" | jq "${field} = ${newvalue}")"
83+
CONFIG_JSON="$(echo "$CONFIG_JSON" | jq "${field} = ${newvalue}")"
84+
85+
[[ "${newvalue}" == "true" ]]
86+
}
87+
88+
MODE="${1:-"all"}"
89+
90+
mode_hostname() {
91+
[[ "${MODE}" == "all" || "${MODE}" == "hostname" ]]
92+
}
93+
mode_network() {
94+
[[ "${MODE}" == "all" || "${MODE}" == "network" ]]
95+
}
96+
97+
98+
if mode_hostname; then
99+
edit '.hostname' "Hostname" is_valid_hostname || exit 1
100+
fi
101+
102+
103+
104+
if mode_network; then
105+
# Number of interfaces
106+
NUM_IFACES=1
107+
108+
# Loop through interfaces
109+
for ((i=0; i<NUM_IFACES; i++)); do
110+
if ! question '.network['"$i"']["dhcp"]' "Configure network via DHCP?" true; then
111+
edit '.network['"$i"']["ip-address"]' "IP address" is_valid_ip || exit 1
112+
edit '.network['"$i"']["network-mask"]' "Network mask" is_valid_ip || exit 1
113+
edit '.network['"$i"']["gateway"]' "Gateway" is_valid_ip || exit 1
114+
edit '.network['"$i"']["dns-server"]' "DNS server(s)" is_valid_ips || exit 1
115+
edit '.network['"$i"']["ntp"]' "NTP server(s)" is_valid_name_or_ip || exit 1
116+
fi
117+
done
118+
119+
if ! term cuos_dialog --clear --yesno "Do you want to save and load the configuration?\n\n${CONFIG_NEW}" 25 50; then
120+
exit 1
121+
fi
122+
fi
123+
124+
# Save to new config
125+
echo "${CONFIG_JSON}" >"${CONFIG_PATH}" || exit 1
126+
127+
if [[ -n "${TEST:-}" ]]; then exit; fi
128+
129+
if mode_hostname; then
130+
"${SCRIPT_DIR}/init.sh" --reinit set_hostname
131+
fi
132+
if mode_network; then
133+
"${SCRIPT_DIR}/init.sh" --reinit configure_network
134+
fi
135+

0 commit comments

Comments
 (0)