fix: Error codes

* fix: Error codes
This commit is contained in:
Kroese 2023-12-16 06:54:47 +01:00 committed by GitHub
parent 5266ee88ac
commit ddcf40b68f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 15 deletions

View file

@ -30,7 +30,7 @@ fmt2ext() {
echo "img" echo "img"
;; ;;
*) *)
error "Unrecognized disk format: $DISK_FMT" && exit 88 error "Unrecognized disk format: $DISK_FMT" && exit 78
;; ;;
esac esac
} }
@ -46,7 +46,7 @@ ext2fmt() {
echo "raw" echo "raw"
;; ;;
*) *)
error "Unrecognized file extension: .$DISK_EXT" && exit 88 error "Unrecognized file extension: .$DISK_EXT" && exit 78
;; ;;
esac esac
} }
@ -66,7 +66,7 @@ getSize() {
qemu-img info "$DISK_FILE" -f "$DISK_FMT" | grep '^virtual size: ' | sed 's/.*(\(.*\) bytes)/\1/' 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 esac
} }
@ -85,7 +85,7 @@ resizeDisk() {
FAIL="Could not resize $DISK_FMT file of $DISK_DESC ($DISK_FILE) from ${GB}G to $DISK_SPACE .." FAIL="Could not resize $DISK_FMT file of $DISK_DESC ($DISK_FILE) from ${GB}G to $DISK_SPACE .."
REQ=$((DATA_SIZE-CUR_SIZE)) 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 case "${DISK_FMT,,}" in
raw) raw)
@ -93,7 +93,7 @@ resizeDisk() {
# Resize file by changing its length # Resize file by changing its length
if ! truncate -s "$DISK_SPACE" "$DISK_FILE"; then if ! truncate -s "$DISK_SPACE" "$DISK_FILE"; then
error "$FAIL" && exit 85 error "$FAIL" && exit 75
fi fi
else else
@ -104,13 +104,13 @@ resizeDisk() {
if (( REQ > SPACE )); then 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 "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 fi
# Resize file by allocating more space # Resize file by allocating more space
if ! fallocate -l "$DISK_SPACE" "$DISK_FILE"; then if ! fallocate -l "$DISK_SPACE" "$DISK_FILE"; then
if ! truncate -s "$DISK_SPACE" "$DISK_FILE"; then if ! truncate -s "$DISK_SPACE" "$DISK_FILE"; then
error "$FAIL" && exit 85 error "$FAIL" && exit 75
fi fi
fi fi
@ -118,7 +118,7 @@ resizeDisk() {
;; ;;
qcow2) qcow2)
if ! qemu-img resize -f "$DISK_FMT" "$DISK_FILE" "$DISK_SPACE" ; then if ! qemu-img resize -f "$DISK_FMT" "$DISK_FILE" "$DISK_SPACE" ; then
error "$FAIL" && exit 85 error "$FAIL" && exit 72
fi fi
;; ;;
esac esac
@ -157,7 +157,7 @@ createDisk() {
# Create an empty file # Create an empty file
if ! truncate -s "$DISK_SPACE" "$DISK_FILE"; then if ! truncate -s "$DISK_SPACE" "$DISK_FILE"; then
rm -f "$DISK_FILE" rm -f "$DISK_FILE"
error "$FAIL" && exit 87 error "$FAIL" && exit 77
fi fi
else else
@ -168,14 +168,14 @@ createDisk() {
if (( DATA_SIZE > SPACE )); then 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 "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 fi
# Create an empty file # Create an empty file
if ! fallocate -l "$DISK_SPACE" "$DISK_FILE"; then if ! fallocate -l "$DISK_SPACE" "$DISK_FILE"; then
if ! truncate -s "$DISK_SPACE" "$DISK_FILE"; then if ! truncate -s "$DISK_SPACE" "$DISK_FILE"; then
rm -f "$DISK_FILE" rm -f "$DISK_FILE"
error "$FAIL" && exit 87 error "$FAIL" && exit 77
fi fi
fi fi
@ -184,7 +184,7 @@ createDisk() {
qcow2) qcow2)
if ! qemu-img create -f "$DISK_FMT" -- "$DISK_FILE" "$DISK_SPACE" ; then if ! qemu-img create -f "$DISK_FMT" -- "$DISK_FILE" "$DISK_SPACE" ; then
rm -f "$DISK_FILE" rm -f "$DISK_FILE"
error "$FAIL" && exit 89 error "$FAIL" && exit 70
fi fi
;; ;;
esac esac
@ -230,7 +230,7 @@ addDisk () {
if ! convertDisk "$PREV_FILE" "$PREV_FMT" "$TMP_FILE" "$DISK_FMT" ; then if ! convertDisk "$PREV_FILE" "$PREV_FMT" "$TMP_FILE" "$DISK_FMT" ; then
rm -f "$TMP_FILE" 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 fi
mv "$TMP_FILE" "$DISK_FILE" mv "$TMP_FILE" "$DISK_FILE"

View file

@ -195,7 +195,7 @@ if [ ! -c /dev/net/tun ]; then
chmod 666 /dev/net/tun chmod 666 /dev/net/tun
fi 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 # Create the necessary file structure for /dev/vhost-net
if [ ! -c /dev/vhost-net ]; then if [ ! -c /dev/vhost-net ]; then
@ -220,7 +220,7 @@ if [[ "$DHCP" == [Yy1]* ]]; then
if [[ "$DEBUG" == [Yy1]* ]]; then if [[ "$DEBUG" == [Yy1]* ]]; then
info "Warning: Are you sure the container is on a macvlan network?" info "Warning: Are you sure the container is on a macvlan network?"
else 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
fi fi