Skip to content

Commit 2d80b86

Browse files
committed
fix: action_on_failure not defined. Use raise
1 parent bec657d commit 2d80b86

5 files changed

Lines changed: 67 additions & 45 deletions

File tree

‎system/cuos/do-update-lxc.sh‎

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,73 +18,69 @@ fi
1818
export CONFIG_PATH="/system_next.json"
1919

2020
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"
2222
LXC_IMAGE_DIGEST="$(jq -r '.lxc_image_digest // empty' "${CONFIG_PATH}")"
2323

2424
IMAGE_VERSION="${LXC_IMAGE}"
2525
IMAGE_VERSION_STRING="${LXC_IMAGE}@${LXC_IMAGE_DIGEST}"
2626

2727
if [[ "${IMAGE_VERSION_STRING}" == "$(cat /etc/image)" ]]; then
28-
echo "No new image version available. Exiting."
2928
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."
3130
fi
3231

3332
AVAIL_BYTES=$(df -B1 "/" | awk 'NR==2 {print $4}')
3433
REQUIRED_BYTES=$((2 * 1024 * 1024 * 1024))
3534
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
3735
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
3937
fi
4038

4139
state jq '.last_update_check = (now | todate)'
4240

43-
"${SCRIPT_DIR}/utils-docker-login.sh" || raise "Docker login failed"
41+
"${SCRIPT_DIR}/utils-docker-login.sh" || raise 42 "Docker login failed"
4442

45-
docker image pull "${IMAGE_VERSION}" || raise "Faild to fetch image"
43+
docker image pull "${IMAGE_VERSION}" || raise 43 "Faild to fetch image"
4644
NEW_DIGEST=$(docker inspect --format='{{index .RepoDigests 0}}' "${IMAGE_VERSION}" 2>/dev/null | cut -d '@' -f 2)
4745
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}"
5047
fi
5148

5249
if [[ "${IMAGE_VERSION}@${NEW_DIGEST}" == "$(cat /etc/image)" ]]; then
53-
echo "No new image version available (post). Exiting."
5450
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."
5652
fi
5753

5854
rm -Rf /next /prev
5955
mkdir -p /next
6056

6157
CONTAINER="$(docker create "${IMAGE_VERSION}")"
6258
if ! docker export "${CONTAINER}" | (cd /next && tar xf -); then
63-
raise "Failed to export the container"
59+
raise 44 "Failed to export the container"
6460
fi
6561
docker rm "${CONTAINER}" \
66-
|| raise "Failed to remove the container"
62+
|| raise 45 "Failed to remove the container"
6763

6864
cd /next || exit 127
6965
rm -Rf .dockerenv sys dev proc data
7066
cd / || exit 127
7167

7268
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"
7470

7571
if [[ -d "/next${SCRIPT_DIR}/lxc-swaproot/" ]]; then
7672
cp -R "/next${SCRIPT_DIR}/lxc-swaproot/" /swaproot/ \
77-
|| raise "Failed to copy swaproot scripts"
73+
|| raise 47 "Failed to copy swaproot scripts"
7874
else
7975
cp -R "${SCRIPT_DIR}/lxc-swaproot/" /swaproot/ \
80-
|| raise "Failed to copy swaproot scripts"
76+
|| raise 48 "Failed to copy swaproot scripts"
8177
fi
8278
if [[ -f "/next/bin/busybox" ]]; then
8379
cp /next/bin/busybox /swaproot/ \
84-
|| raise "Failed to copy busybox"
80+
|| raise 49 "Failed to copy busybox"
8581
else
8682
cp /bin/busybox /swaproot/ \
87-
|| raise "Failed to copy busybox"
83+
|| raise 50 "Failed to copy busybox"
8884
fi
8985

9086
mv /sbin/init /sbin/init-old

‎system/cuos/do-update-shell.sh‎

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,19 @@ set -x
44

55
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
66

7-
raise() {
8-
echo "Error: $*" >&2
9-
exit 1
10-
}
11-
127
# shellcheck source=/dev/null
138
source "${SCRIPT_DIR}/utils.sh"
149

1510
UPDATE_IMAGE="$(image_url "updater")" || \
16-
action_on_failure "cuos:updater:image_not_defined" "Updater image not defined"
11+
raise "Updater image not defined"
1712
UPDATE_IMAGE_DIGEST="$(jq -r '.updater_image_digest // empty' "${CONFIG_PATH}")"
1813

1914
"${SCRIPT_DIR}/utils-docker-login.sh" || raise "Docker login failed"
2015

2116
docker image pull "${UPDATE_IMAGE}" || raise "Faild to fetch image"
2217
NEW_DIGEST=$(docker inspect --format='{{index .RepoDigests 0}}' "${UPDATE_IMAGE}" 2>/dev/null | cut -d '@' -f 2)
2318
if [[ -n "${UPDATE_IMAGE_DIGEST}" && "${UPDATE_IMAGE_DIGEST}" != "${NEW_DIGEST}" ]]; then
24-
echo "Image digest mismatch: ${UPDATE_IMAGE_DIGEST} != ${NEW_DIGEST}"
25-
exit 1
19+
raise "Image digest mismatch: ${UPDATE_IMAGE_DIGEST} != ${NEW_DIGEST}"
2620
fi
2721

2822
# Get Root Disk:

‎system/cuos/do-update.sh‎

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,32 +18,30 @@ SLOT="$(cat "/etc/active_slot")"
1818
export CONFIG_PATH="/system_next.json"
1919

2020
UPDATE_IMAGE="$(image_url "updater")" || \
21-
action_on_failure "cuos:updater:image_not_defined" "Updater image not defined"
21+
raise 31 "Updater image not defined"
2222
UPDATE_IMAGE_DIGEST="$(jq -r '.updater_image_digest // empty' "${CONFIG_PATH}")"
2323

2424
OS_ARCH="$(cat "/etc/cuos-arch" 2>/dev/null || arch)"
2525

2626
OS_IMAGE="$(image_url "${OS_ARCH}" || image_url "os")" || \
27-
action_on_failure "cuos:updater:os_image_not_defined" "OS image not defined"
27+
raise 32 "OS image not defined"
2828
OS_DIGEST="$(jq -r --arg arch "${OS_ARCH}" '.[$arch+"_image_digest"] // .os_image_digest // empty' "${CONFIG_PATH}")"
2929

3030
IMAGE_VERSION_STRING="${OS_IMAGE}@${OS_DIGEST}"
3131

3232
if [[ "${IMAGE_VERSION_STRING}" == "$(cat /etc/image)" ]]; then
33-
echo "No new image version available. Exiting (pre)"
3433
report_info "cuos:update:not_needed" "The system is up-to-date"
35-
exit 22
34+
raise_info 22 "No new image version available. Exiting (pre)"
3635
fi
3736

3837
state jq '.last_update_check = (now | todate)'
3938

40-
"${SCRIPT_DIR}/utils-docker-login.sh" || raise "Docker login failed"
39+
"${SCRIPT_DIR}/utils-docker-login.sh" || raise 33 "Docker login failed"
4140

42-
docker image pull "${UPDATE_IMAGE}" || raise "Faild to fetch image"
41+
docker image pull "${UPDATE_IMAGE}" || raise 34 "Faild to fetch image"
4342
NEW_DIGEST=$(docker inspect --format='{{index .RepoDigests 0}}' "${UPDATE_IMAGE}" 2>/dev/null | cut -d '@' -f 2)
4443
if [[ -n "${UPDATE_IMAGE_DIGEST}" && "${UPDATE_IMAGE_DIGEST}" != "${NEW_DIGEST}" ]]; then
45-
echo "Image digest mismatch: ${UPDATE_IMAGE_DIGEST} != ${NEW_DIGEST}"
46-
exit 30
44+
raise 30 "Image digest mismatch: ${UPDATE_IMAGE_DIGEST} != ${NEW_DIGEST}"
4745
fi
4846

4947
# Get Root Disk:

‎system/cuos/utils.sh‎

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,31 @@ report_debug() {
5959
echo "[debug]" "${msg_id}" "$@" >&2
6060
}
6161

62+
6263
raise() {
63-
#report_err "cuos:programerror" "Update failed. Exit code ${DOCKER_EXIT_CODE}"
64-
echo "Error: $*" >&2
65-
exit 1
64+
local code=1
65+
local message="$*"
66+
67+
if [[ "${1:-}" =~ ^[0-9]+$ ]]; then
68+
code="${1:-}"
69+
message="${*:2}"
70+
fi
71+
72+
echo "Error: $message" >&2
73+
exit "$code"
74+
}
75+
76+
raise_info() {
77+
local code=1
78+
local message="$*"
79+
80+
if [[ "${1:-}" =~ ^[0-9]+$ ]]; then
81+
code="${1:-}"
82+
message="${*:2}"
83+
fi
84+
85+
echo "Info: $message" >&2
86+
exit "$code"
6687
}
6788

6889
raise_okay() {

‎updater/perform_update.sh‎

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,29 @@ set -x
55
export CONFIG_PATH="${CONFIG_PATH:-"/system.json"}"
66

77
raise() {
8-
local code="${1:-"1"}"
9-
shift
10-
echo "Error: $*" >&2
11-
exit "${code}"
8+
local code=1
9+
local message="$*"
10+
11+
if [[ "${1:-}" =~ ^[0-9]+$ ]]; then
12+
code="${1:-}"
13+
message="${*:2}"
14+
fi
15+
16+
echo "Error: $message" >&2
17+
exit "$code"
1218
}
19+
1320
raise_info() {
14-
local code="${1:-"1"}"
15-
shift
16-
echo "Info: $*" >&2
17-
exit "${code}"
21+
local code=1
22+
local message="$*"
23+
24+
if [[ "${1:-}" =~ ^[0-9]+$ ]]; then
25+
code="${1:-}"
26+
message="${*:2}"
27+
fi
28+
29+
echo "Info: $message" >&2
30+
exit "$code"
1831
}
1932

2033
# Check parameters:

0 commit comments

Comments
 (0)