|
18 | 18 | export CONFIG_PATH="/system_next.json" |
19 | 19 |
|
20 | 20 | LXC_IMAGE="$(image_url "lxc")" || \ |
21 | | - action_on_failure "cuos:updater:lxc_image_not_defined" "LXC image not defined" |
| 21 | + raise 41 "LXC image not defined" |
22 | 22 | LXC_IMAGE_DIGEST="$(jq -r '.lxc_image_digest // empty' "${CONFIG_PATH}")" |
23 | 23 |
|
24 | 24 | IMAGE_VERSION="${LXC_IMAGE}" |
25 | 25 | IMAGE_VERSION_STRING="${LXC_IMAGE}@${LXC_IMAGE_DIGEST}" |
26 | 26 |
|
27 | 27 | if [[ "${IMAGE_VERSION_STRING}" == "$(cat /etc/image)" ]]; then |
28 | | - echo "No new image version available. Exiting." |
29 | 28 | report_info "cuos:update:not_needed" "The system is up-to-date" |
30 | | - exit 22 |
| 29 | + raise_info 22 "No new image version available. Exiting." |
31 | 30 | fi |
32 | 31 |
|
33 | 32 | AVAIL_BYTES=$(df -B1 "/" | awk 'NR==2 {print $4}') |
34 | 33 | REQUIRED_BYTES=$((2 * 1024 * 1024 * 1024)) |
35 | 34 | if [ "$AVAIL_BYTES" -le "$REQUIRED_BYTES" ]; then |
36 | | - echo "Not enough free space in ${TARGET_ROOT} (required: >2GB, available: $((AVAIL_BYTES/1024/1024)) MB). Aborting update." >&2 |
37 | 35 | report_info "cuos:update:no_space" "Not enough free disk space available" |
38 | | - exit 21 |
| 36 | + raise 21 "Not enough free space in ${TARGET_ROOT} (required: >2GB, available: $((AVAIL_BYTES/1024/1024)) MB). Aborting update." >&2 |
39 | 37 | fi |
40 | 38 |
|
41 | 39 | state jq '.last_update_check = (now | todate)' |
42 | 40 |
|
43 | | -"${SCRIPT_DIR}/utils-docker-login.sh" || raise "Docker login failed" |
| 41 | +"${SCRIPT_DIR}/utils-docker-login.sh" || raise 42 "Docker login failed" |
44 | 42 |
|
45 | | -docker image pull "${IMAGE_VERSION}" || raise "Faild to fetch image" |
| 43 | +docker image pull "${IMAGE_VERSION}" || raise 43 "Faild to fetch image" |
46 | 44 | NEW_DIGEST=$(docker inspect --format='{{index .RepoDigests 0}}' "${IMAGE_VERSION}" 2>/dev/null | cut -d '@' -f 2) |
47 | 45 | if [[ -n "${LXC_IMAGE_DIGEST}" && "${LXC_IMAGE_DIGEST}" != "${NEW_DIGEST}" ]]; then |
48 | | - echo "Image digest mismatch: ${LXC_IMAGE_DIGEST} != ${NEW_DIGEST}" |
49 | | - exit 30 |
| 46 | + raise 30 "Image digest mismatch: ${LXC_IMAGE_DIGEST} != ${NEW_DIGEST}" |
50 | 47 | fi |
51 | 48 |
|
52 | 49 | if [[ "${IMAGE_VERSION}@${NEW_DIGEST}" == "$(cat /etc/image)" ]]; then |
53 | | - echo "No new image version available (post). Exiting." |
54 | 50 | report_info "cuos:update:not_needed" "The system is up-to-date" |
55 | | - exit 22 |
| 51 | + raise_info 22 "No new image version available (post). Exiting." |
56 | 52 | fi |
57 | 53 |
|
58 | 54 | rm -Rf /next /prev |
59 | 55 | mkdir -p /next |
60 | 56 |
|
61 | 57 | CONTAINER="$(docker create "${IMAGE_VERSION}")" |
62 | 58 | if ! docker export "${CONTAINER}" | (cd /next && tar xf -); then |
63 | | - raise "Failed to export the container" |
| 59 | + raise 44 "Failed to export the container" |
64 | 60 | fi |
65 | 61 | docker rm "${CONTAINER}" \ |
66 | | - || raise "Failed to remove the container" |
| 62 | + || raise 45 "Failed to remove the container" |
67 | 63 |
|
68 | 64 | cd /next || exit 127 |
69 | 65 | rm -Rf .dockerenv sys dev proc data |
70 | 66 | cd / || exit 127 |
71 | 67 |
|
72 | 68 | chroot /next /usr/local/cuos/first-run.sh "${SLOT}" "${IMAGE_VERSION}" "${NEW_DIGEST}" \ |
73 | | - || raise "Failed to run first-run script in container" |
| 69 | + || raise 46 "Failed to run first-run script in container" |
74 | 70 |
|
75 | 71 | if [[ -d "/next${SCRIPT_DIR}/lxc-swaproot/" ]]; then |
76 | 72 | cp -R "/next${SCRIPT_DIR}/lxc-swaproot/" /swaproot/ \ |
77 | | - || raise "Failed to copy swaproot scripts" |
| 73 | + || raise 47 "Failed to copy swaproot scripts" |
78 | 74 | else |
79 | 75 | cp -R "${SCRIPT_DIR}/lxc-swaproot/" /swaproot/ \ |
80 | | - || raise "Failed to copy swaproot scripts" |
| 76 | + || raise 48 "Failed to copy swaproot scripts" |
81 | 77 | fi |
82 | 78 | if [[ -f "/next/bin/busybox" ]]; then |
83 | 79 | cp /next/bin/busybox /swaproot/ \ |
84 | | - || raise "Failed to copy busybox" |
| 80 | + || raise 49 "Failed to copy busybox" |
85 | 81 | else |
86 | 82 | cp /bin/busybox /swaproot/ \ |
87 | | - || raise "Failed to copy busybox" |
| 83 | + || raise 50 "Failed to copy busybox" |
88 | 84 | fi |
89 | 85 |
|
90 | 86 | mv /sbin/init /sbin/init-old |
|
0 commit comments