This commit is contained in:
CanbiZ 2025-05-26 13:43:36 +02:00
parent 5cf528254a
commit 13b6ac8dba
3 changed files with 48 additions and 3 deletions

View File

@ -503,3 +503,41 @@ run_container_safe() {
$cmd
" || __handle_general_error "lxc-attach to CT $ct"
}
check_or_create_swap() {
msg_info "Checking for active swap"
if swapon --noheadings --show | grep -q 'swap'; then
msg_ok "Swap is active"
return 0
fi
msg_error "No active swap detected"
read -p "Do you want to create a swap file? [y/N]: " create_swap
create_swap="${create_swap,,}" # to lowercase
if [[ "$create_swap" != "y" && "$create_swap" != "yes" ]]; then
msg_info "Skipping swap file creation"
return 1
fi
read -p "Enter swap size in MB (e.g., 2048 for 2GB): " swap_size_mb
if ! [[ "$swap_size_mb" =~ ^[0-9]+$ ]]; then
msg_error "Invalid size input. Aborting."
return 1
fi
local swap_file="/swapfile"
msg_info "Creating ${swap_size_mb}MB swap file at $swap_file"
if dd if=/dev/zero of="$swap_file" bs=1M count="$swap_size_mb" status=progress &&
chmod 600 "$swap_file" &&
mkswap "$swap_file" &&
swapon "$swap_file"; then
msg_ok "Swap file created and activated successfully"
else
msg_error "Failed to create or activate swap"
return 1
fi
}

View File

@ -27,7 +27,6 @@ load_functions() {
pve_check
arch_check
ssh_check
check_hostname_conflict
set_std_mode
# add more
}
@ -443,8 +442,14 @@ exit_script() {
}
check_hostname_conflict() {
if qm list | awk '{print $2}' | grep -qx "$HN"; then
msg_error "Hostname $HN already in use by another VM."
local hostname="${HN:-}"
if [[ -z "$hostname" ]]; then
msg_error "HN is not set cannot check hostname conflict."
exit 1
fi
if qm list | awk '{print $2}' | grep -qx "$hostname"; then
msg_error "Hostname $hostname already in use by another VM."
exit 1
fi
}

View File

@ -42,6 +42,8 @@ else
header_info && echo -e "${CROSS}${RD}User exited script${CL}\n" && exit
fi
check_hostname_conflict "$HN"
function default_settings() {
VMID=$(get_valid_nextid)
FORMAT=",efitype=4m"