From ddcf40b68f22179231f35a68a357631a638c892e Mon Sep 17 00:00:00 2001 From: Kroese Date: Sat, 16 Dec 2023 06:54:47 +0100 Subject: [PATCH] fix: Error codes * fix: Error codes --- src/disk.sh | 26 +++++++++++++------------- src/network.sh | 4 ++-- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/disk.sh b/src/disk.sh index 25dcd8d..c68d56f 100644 --- a/src/disk.sh +++ b/src/disk.sh @@ -30,7 +30,7 @@ fmt2ext() { echo "img" ;; *) - error "Unrecognized disk format: $DISK_FMT" && exit 88 + error "Unrecognized disk format: $DISK_FMT" && exit 78 ;; esac } @@ -46,7 +46,7 @@ ext2fmt() { echo "raw" ;; *) - error "Unrecognized file extension: .$DISK_EXT" && exit 88 + error "Unrecognized file extension: .$DISK_EXT" && exit 78 ;; esac } @@ -66,7 +66,7 @@ getSize() { qemu-img info "$DISK_FILE" -f "$DISK_FMT" | grep '^virtual size: ' | sed 's/.*(\(.*\) bytes)/\1/' ;; *) - error "Unrecognized disk format: $DISK_FMT" && exit 88 + error "Unrecognized disk format: $DISK_FMT" && exit 78 ;; esac } @@ -85,7 +85,7 @@ resizeDisk() { FAIL="Could not resize $DISK_FMT file of $DISK_DESC ($DISK_FILE) from ${GB}G to $DISK_SPACE .." REQ=$((DATA_SIZE-CUR_SIZE)) - (( REQ < 1 )) && error "Shrinking disks is not supported!" && exit 84 + (( REQ < 1 )) && error "Shrinking disks is not supported!" && exit 71 case "${DISK_FMT,,}" in raw) @@ -93,7 +93,7 @@ resizeDisk() { # Resize file by changing its length if ! truncate -s "$DISK_SPACE" "$DISK_FILE"; then - error "$FAIL" && exit 85 + error "$FAIL" && exit 75 fi else @@ -104,13 +104,13 @@ resizeDisk() { if (( REQ > SPACE )); then error "Not enough free space to resize $DISK_DESC to $DISK_SPACE in $DIR, it has only $SPACE_GB GB available.." - error "Please specify a smaller ${DISK_DESC^^}_SIZE or disable preallocation by setting DISK_FMT to \"qcow2\"." && exit 84 + error "Please specify a smaller ${DISK_DESC^^}_SIZE or disable preallocation by setting DISK_FMT to \"qcow2\"." && exit 74 fi # Resize file by allocating more space if ! fallocate -l "$DISK_SPACE" "$DISK_FILE"; then if ! truncate -s "$DISK_SPACE" "$DISK_FILE"; then - error "$FAIL" && exit 85 + error "$FAIL" && exit 75 fi fi @@ -118,7 +118,7 @@ resizeDisk() { ;; qcow2) if ! qemu-img resize -f "$DISK_FMT" "$DISK_FILE" "$DISK_SPACE" ; then - error "$FAIL" && exit 85 + error "$FAIL" && exit 72 fi ;; esac @@ -157,7 +157,7 @@ createDisk() { # Create an empty file if ! truncate -s "$DISK_SPACE" "$DISK_FILE"; then rm -f "$DISK_FILE" - error "$FAIL" && exit 87 + error "$FAIL" && exit 77 fi else @@ -168,14 +168,14 @@ createDisk() { if (( DATA_SIZE > SPACE )); then error "Not enough free space to create a $DISK_DESC of $DISK_SPACE in $DIR, it has only $SPACE_GB GB available.." - error "Please specify a smaller ${DISK_DESC^^}_SIZE or disable preallocation by setting DISK_FMT to \"qcow2\"." && exit 86 + error "Please specify a smaller ${DISK_DESC^^}_SIZE or disable preallocation by setting DISK_FMT to \"qcow2\"." && exit 76 fi # Create an empty file if ! fallocate -l "$DISK_SPACE" "$DISK_FILE"; then if ! truncate -s "$DISK_SPACE" "$DISK_FILE"; then rm -f "$DISK_FILE" - error "$FAIL" && exit 87 + error "$FAIL" && exit 77 fi fi @@ -184,7 +184,7 @@ createDisk() { qcow2) if ! qemu-img create -f "$DISK_FMT" -- "$DISK_FILE" "$DISK_SPACE" ; then rm -f "$DISK_FILE" - error "$FAIL" && exit 89 + error "$FAIL" && exit 70 fi ;; esac @@ -230,7 +230,7 @@ addDisk () { if ! convertDisk "$PREV_FILE" "$PREV_FMT" "$TMP_FILE" "$DISK_FMT" ; then rm -f "$TMP_FILE" - error "Failed to convert $DISK_DESC to $DISK_FMT format." && exit 89 + error "Failed to convert $DISK_DESC to $DISK_FMT format." && exit 79 fi mv "$TMP_FILE" "$DISK_FILE" diff --git a/src/network.sh b/src/network.sh index 09222d2..7a9b9ee 100644 --- a/src/network.sh +++ b/src/network.sh @@ -195,7 +195,7 @@ if [ ! -c /dev/net/tun ]; then chmod 666 /dev/net/tun fi -[ ! -c /dev/net/tun ] && error "TUN network interface not available..." && exit 85 +[ ! -c /dev/net/tun ] && error "TUN network interface not available..." && exit 25 # Create the necessary file structure for /dev/vhost-net if [ ! -c /dev/vhost-net ]; then @@ -220,7 +220,7 @@ if [[ "$DHCP" == [Yy1]* ]]; then if [[ "$DEBUG" == [Yy1]* ]]; then info "Warning: Are you sure the container is on a macvlan network?" else - error "You can only enable DHCP while the container is on a macvlan network!" && exit 86 + error "You can only enable DHCP while the container is on a macvlan network!" && exit 26 fi fi