Skip to content

Commit f637670

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

6 files changed

Lines changed: 35 additions & 13 deletions

File tree

‎system/cuos/dialog-maintenance.sh‎

Lines changed: 5 additions & 4 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" docker ps ;;
186+
docker) api_stream "docker ps" 30 120 docker ps ;;
187187
ping) diagnostics_ping ;;
188188
dns) diagnostics_dns ;;
189189
"expert") expert ;;
@@ -202,23 +202,24 @@ cuos_logs() {
202202
(
203203
echo -e "\033[1;36m[ Log View - Press 'Q' to quit the view ]\033[0m";
204204
SYSTEMD_COLORS=true journalctl \
205-
-t cuos \
206-
--priority "emerg".."info" \
205+
--identifier=cuos \
206+
--priority="emerg".."info" \
207207
--lines=2000 \
208208
--output=short \
209209
--no-hostname \
210210
--no-pager
211211
) | \
212212
LESSSECURE=1 less \
213213
--header=1,0 \
214+
-R \
214215
+G
215216
}
216217

217218
view_logs() {
218219
(
219220
echo -e "\033[1;36m[ Log View - Press 'Q' to quit the view ]\033[0m";
220221
SYSTEMD_COLORS=true journalctl \
221-
--priority "emerg".."info" \
222+
--priority="emerg".."info" \
222223
--lines=10000 \
223224
--output=short \
224225
--no-hostname \

‎system/cuos/dialog-reports.sh‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,14 @@ change_vt
1616

1717
tmpfile=$(mktemp)
1818

19-
journalctl -f -t cuos -n 12 --output=json | jq --unbuffered -r '
19+
journalctl \
20+
--identifier=cuos \
21+
--merge \
22+
--follow \
23+
--lines=20 \
24+
--boot=all \
25+
--no-pager \
26+
--output=json | jq --unbuffered -r '
2027
. as $e
2128
| (($e.__REALTIME_TIMESTAMP | tonumber) / 1000000 | strflocaltime("%Y-%m-%d %H:%M:%S")) + " [" +
2229
(["emerg","alert","crit","err","warning","notice","info","debug"][$e.PRIORITY | tonumber]) + "] " +
@@ -27,7 +34,7 @@ change_vt
2734
term cuos_dialog \
2835
--title "System Reports" \
2936
--exit-label "Intervention: Start configuration" \
30-
--tailbox "$tmpfile" 30 70
37+
--tailbox "$tmpfile" 40 100
3138
EXIT_CODE_DIALOG="$?"
3239

3340
kill "$JOURNAL_PID"

‎system/cuos/do-update.sh‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,10 @@ echo "Exit Code: ${DOCKER_EXIT_CODE}"
7777

7878
docker network rm cuos-internet
7979

80+
PARTITION_NEXT="A"
81+
[[ "${PARTITION}" == "A" ]] && PARTITION_NEXT="B"
82+
8083
if [[ "${DOCKER_EXIT_CODE}" = "0" ]]; then
81-
PARTITION_NEXT="A"
82-
[[ "${PARTITION}" == "A" ]] && PARTITION_NEXT="B"
8384
touch "/data/run-update"
8485
state '.state' 'updating'
8586
state jq '.last_update_date = (now | todate)'
@@ -92,6 +93,9 @@ if [[ "${DOCKER_EXIT_CODE}" = "0" ]]; then
9293
elif [[ "${DOCKER_EXIT_CODE}" = "2" ]]; then
9394
echo "No new image version available."
9495
report_info "cuos:update:not_needed" "No new image version available"
96+
elif [[ "${DOCKER_EXIT_CODE}" = "3" ]]; then
97+
echo "Not enough free disk space available"
98+
report_info "cuos:update:no_space" "Not enough free disk space available"
9599
else
96100
state '.update_state' "update of partition ${PARTITION_NEXT} to ${OS_IMAGE}:${OS_VERSION} failed"
97101
report_err "cuos:update:failed" "Update failed. Exit code ${DOCKER_EXIT_CODE}"

‎system/cuos/init.sh‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ set_hostname() {
9898
r1=$(printf "%02X" $(( RANDOM % 256 )))
9999
r2=$(printf "%02X" $(( RANDOM % 256 )))
100100
SYSTEM_HOSTNAME="device-${r1}${r2}"
101+
jq_replace \
102+
--arg hn "${SYSTEM_HOSTNAME}" \
103+
'.hostname = $hn'
101104
fi
102105
if [[ -n "${SYSTEM_HOSTNAME}" ]]; then
103106
echo "Setting hostname to $SYSTEM_HOSTNAME"

‎system/cuos/lib-dialog.sh‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,15 @@ api_stream() {
102102
prgbox "$*" "$title" 22 90
103103
}
104104

105+
api_stream_size() {
106+
# Stream API output in prgbox
107+
# Usage: api_stream <title> <h> <w> <action> [args...]
108+
local title="$1"; shift
109+
local h="$1"; shift
110+
local w="$1"; shift
111+
prgbox "$*" "$title" "$h" "$w"
112+
}
113+
105114
yesno() { dialog --backtitle "$BACKTITLE" --title "${2:-Confirm}" --yesno "$1" ${3:-9} ${4:-70}; }
106115

107116
valid_hostname() {

‎updater/perform_update.sh‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ if [[ "${INSTALLIMAGE}" != "true" ]]; then
2323
AVAIL_BYTES=$(df -B1 "${TARGET_ROOT}" | awk 'NR==2 {print $4}')
2424
REQUIRED_BYTES=$((2 * 1024 * 1024 * 1024))
2525
if [ "$AVAIL_BYTES" -le "$REQUIRED_BYTES" ]; then
26-
echo "Not enough free space in ${TARGET_ROOT} (required: >2GB, available: $((AVAIL_BYTES/1024/1024)) MB). Aborting update."
26+
echo "Not enough free space in ${TARGET_ROOT} (required: >2GB, available: $((AVAIL_BYTES/1024/1024)) MB). Aborting update." >&2
2727
exit 3
2828
fi
2929
fi
@@ -96,17 +96,15 @@ CONTAINER_ID="$(docker inspect --format '{{ .Id }}' "${CONTAINER_NAME}")" \
9696
|| raise "Failed to get container id"
9797

9898
if [ -z "${CONTAINER_ID}" ]; then
99-
echo "Container not found: ${CONTAINER_NAME}"
100-
exit 2
99+
raise "Container not found: ${CONTAINER_NAME}"
101100
fi
102101

103102
CONTAINER_ROOTFS_FS="$(jq -r '.config.rootfs' \
104103
"/var/run/docker/runtime-runc/moby/${CONTAINER_ID}/state.json")" \
105104
|| raise "Failed to get container rootfs"
106105

107106
if [ -z "${CONTAINER_ROOTFS_FS}" ]; then
108-
echo "Rootfs not found: ${CONTAINER_NAME}"
109-
exit 2
107+
raise "Rootfs not found: ${CONTAINER_NAME}"
110108
fi
111109

112110
CONTAINER_ROOTFS="@os/docker/${CONTAINER_ROOTFS_FS#"${DOCKER_DIR}/"}"

0 commit comments

Comments
 (0)