Update import-disk-image.sh

This commit is contained in:
MacRimi 2025-02-06 18:28:36 +01:00 committed by GitHub
parent 656d6ce714
commit 555e7766b0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -41,32 +41,27 @@ initialize_cache
# Path where disk images are stored # Path where disk images are stored
IMAGES_DIR="/var/lib/vz/template/images/" IMAGES_DIR="/var/lib/vz/template/images/"
# Ensure directory exists
# Initial setup
if [ ! -d "$IMAGES_DIR" ]; then if [ ! -d "$IMAGES_DIR" ]; then
mkdir -p "$IMAGES_DIR" msg_info "$(translate 'Creating images directory')"
chmod 755 "$IMAGES_DIR" mkdir -p "$IMAGES_DIR"
msg_info "Created missing directory: $IMAGES_DIR" chmod 755 "$IMAGES_DIR"
msg_ok "$(translate 'Images directory created:') $IMAGES_DIR"
fi fi
# Check if there are any images in the directory # Check if there are any images in the directory
IMAGES=$(ls -A "$IMAGES_DIR" | grep -E "\.(img|qcow2|vmdk)$") IMAGES=$(ls -A "$IMAGES_DIR" | grep -E "\.(img|qcow2|vmdk)$")
if [ -z "$IMAGES" ]; then if [ -z "$IMAGES" ]; then
msg_error "$(translate 'No images available for import in') $IMAGES_DIR" whiptail --title "$(translate 'No Images Found')" \
echo -e "${YW}$(translate 'Supported formats: .img, .qcow2, .vmdk')${CL}" --msgbox "$(translate 'No images available for import in:')\n\n$IMAGES_DIR\n\n$(translate 'Supported formats: .img, .qcow2, .vmdk')\n\n$(translate 'Please add some images and try again.')" 15 60
echo -e "${YW}$(translate 'Please add some images and try again.')${CL}" exit 1
exit 0
fi fi
# Initial setup
if ! [ -d "$IMAGES_DIR" ]; then
msg_info "$(translate 'Creating images directory')"
mkdir -p "$IMAGES_DIR"
msg_ok "$(translate 'Images directory created')"
fi
# Display initial message # Display initial message
whiptail --title "$(translate 'Import Disk Image')" --msgbox "$(translate 'Make sure the disk images you want to import are located in:')\n\n$IMAGES_DIR\n\n$(translate 'Supported formats: .img, .qcow2, .vmdk.')" 12 60 whiptail --title "$(translate 'Import Disk Image')" --msgbox "$(translate 'Make sure the disk images you want to import are located in:')\n\n$IMAGES_DIR\n\n$(translate 'Supported formats: .img, .qcow2, .vmdk.')" 15 60