Skip to content

Commit 69a454a

Browse files
committed
refact: dialogs
1 parent 823e33b commit 69a454a

4 files changed

Lines changed: 38 additions & 18 deletions

File tree

‎system/cuos/app-init.sh‎

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

16-
INSTALL_MENU="$(jq -r '.install_menu // false' "${CONFIG_PATH}")"
17-
if [[ "${INSTALL_MENU}" != "false" ]]; then
18-
report_info "cuos:installation:started" "Starting installation ..."
19-
"${SCRIPT_DIR}/dialog-maintenance.sh" --install "${INSTALL_MENU}"
20-
report_info "cuos:installation:done" "Installation done. Starting up system.."
21-
fi
16+
init_dialogs() {
17+
INSTALL_MENU="$(jq -r '.install_menu // false' "${CONFIG_PATH}")"
18+
if [[ "${INSTALL_MENU}" != "false" && ! -f "/data/installed" ]]; then
19+
report_info "cuos:installation:started" "Starting installation ..."
20+
"${SCRIPT_DIR}/dialog-maintenance.sh" --install "${INSTALL_MENU}"
21+
report_info "cuos:installation:done" "Installation done. Starting up system.."
22+
fi
23+
touch "/data/installed"
2224

23-
"${SCRIPT_DIR}/dialog-reports.sh" &
25+
"${SCRIPT_DIR}/dialog-reports.sh" &
26+
}
2427

2528
action_on_failure() {
2629
sleep 60
@@ -89,15 +92,23 @@ download_image() {
8992
done
9093
}
9194

95+
if [[ -f "${SCRIPT_DIR}/custom-app-init.sh" ]]; then
96+
# shellcheck source=/dev/null
97+
source "${SCRIPT_DIR}/custom-app-init.sh"
98+
fi
99+
100+
init_dialogs
101+
92102
CONTAINER_NAME="cuos-app"
93103
if ! INITIAL_IMAGE="$(image_url "init" || image_url "initial")"; then
94104
report_err "cuos:application:image_not_defined" "Application image not defined"
95105
action_on_failure
96106
fi
97107
INITIAL_IMAGE_VERSION="$(image_version "${INITIAL_IMAGE}")"
108+
INITIAL_DIGEST="$(jq -r '.init_image_digest // .initial_image_digest // empty' "${CONFIG_PATH}")"
98109

99-
LAST_INITIAL_IMAGE_VERSION="$(jq -r '.initial_image_version // empty' "${LAST_CONFIG_PATH}" 2>/dev/null)"
100-
INITIAL_DIGEST="$(jq -r '.initial_image_digest // empty' "${CONFIG_PATH}")"
110+
LAST_INITIAL_IMAGE="$(docker inspect --format='{{.Config.Image}}' "${CONTAINER_NAME}" 2>/dev/null)" || true
111+
LAST_INITIAL_IMAGE_VERSION="$(image_version "${LAST_INITIAL_IMAGE}")" || true
101112

102113

103114
echo "Waiting for Docker to be ready..."
@@ -171,7 +182,6 @@ if [[ "${UPDATE}" -eq 1 ]]; then
171182
docker exec "${CONTAINER_NAME}" /api/update 2>/dev/null || true
172183

173184
state '.state' 'running'
174-
state jq '.start_date = (now | todate)'
175185

176186
report_notice "cuos:update:done" "System successfully updated."
177187
fi

‎system/cuos/dialog-maintenance.sh‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@ change_vt
283283
if [[ "${1:-}" == "--install" ]]; then
284284
shift
285285
install_menu "$@"
286+
sleep 1
286287
else
287288
maintenance_menu "$@"
288289
fi

‎system/cuos/dialog-reports.sh‎

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,21 @@ SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)
55
# shellcheck source=/dev/null
66
source "${SCRIPT_DIR}/lib-dialog.sh"
77

8+
dialog_reports_header() {
9+
cat <<EOF
10+
11+
## Operating System started successfully.
12+
13+
Host: $(hostname)
14+
Start Time: $(jq -r '.start_date | sub("T"; " ") | sub("Z"; " UTC")' /data/state.json)
15+
Last Update: $(jq -r '.last_update_date | sub("T"; " ") | sub("Z"; " UTC")' /data/state.json)
16+
17+
## Reports
18+
19+
EOF
20+
21+
}
22+
823
if [[ -f "${SCRIPT_DIR}/custom-dialog.sh" ]]; then
924
# shellcheck source=/dev/null
1025
source "${SCRIPT_DIR}/custom-dialog.sh"
@@ -21,14 +36,7 @@ change_vt
2136
trap cleanup EXIT
2237

2338
tmpfile=$(mktemp)
24-
cat <<EOF >"$tmpfile"
25-
26-
Host: $(hostname)
27-
28-
Start Time: $(jq -r '.start_date | sub("T"; " ") | sub("Z"; " UTC")' /data/state.json)
29-
Last Update: $(jq -r '.last_update_date | sub("T"; " ") | sub("Z"; " UTC")' /data/state.json)
30-
31-
EOF
39+
dialog_reports_header >"$tmpfile"
3240

3341
journalctl \
3442
--identifier=cuos \

‎system/cuos/init.sh‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,7 @@ if [[ "${1:-}" = "--reinit" ]]; then
466466
fi
467467
else
468468
report_info "cuos:init:start" "System startup"
469+
state jq '.start_date = (now | todate)'
469470
fi
470471

471472
prepare_data_volume

0 commit comments

Comments
 (0)