fuixes
This commit is contained in:
parent
5cf528254a
commit
13b6ac8dba
@ -503,3 +503,41 @@ run_container_safe() {
|
|||||||
$cmd
|
$cmd
|
||||||
" || __handle_general_error "lxc-attach to CT $ct"
|
" || __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
|
||||||
|
}
|
||||||
|
@ -27,7 +27,6 @@ load_functions() {
|
|||||||
pve_check
|
pve_check
|
||||||
arch_check
|
arch_check
|
||||||
ssh_check
|
ssh_check
|
||||||
check_hostname_conflict
|
|
||||||
set_std_mode
|
set_std_mode
|
||||||
# add more
|
# add more
|
||||||
}
|
}
|
||||||
@ -443,8 +442,14 @@ exit_script() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
check_hostname_conflict() {
|
check_hostname_conflict() {
|
||||||
if qm list | awk '{print $2}' | grep -qx "$HN"; then
|
local hostname="${HN:-}"
|
||||||
msg_error "Hostname $HN already in use by another VM."
|
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
|
exit 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
@ -42,6 +42,8 @@ else
|
|||||||
header_info && echo -e "${CROSS}${RD}User exited script${CL}\n" && exit
|
header_info && echo -e "${CROSS}${RD}User exited script${CL}\n" && exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
check_hostname_conflict "$HN"
|
||||||
|
|
||||||
function default_settings() {
|
function default_settings() {
|
||||||
VMID=$(get_valid_nextid)
|
VMID=$(get_valid_nextid)
|
||||||
FORMAT=",efitype=4m"
|
FORMAT=",efitype=4m"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user