Initial Commit

This commit is contained in:
Sthope 2023-07-26 03:37:29 +02:00
parent 95eab4a904
commit ce7edeb5b5
3 changed files with 49 additions and 151 deletions

40
VM/Cloud-Init/debian Normal file
View File

@ -0,0 +1,40 @@
#!/bin/bash
# ____ _ _
#/ ___|| |_| |__ ___ _ __ ___
#\___ \| __| '_ \ / _ \| '_ \ / _ \
# ___) | |_| | | | (_) | |_) | __/
#|____/ \__|_| |_|\___/| .__/ \___|
# |_|
#
clear
# Ubuntu Server 22.04 (jammy)
distro_url="https://cloud.debian.org/images/cloud/bookworm/latest/debian-12-genericcloud-amd64.qcow2"
filename="proxmox_cloudinit"
wget -q "$distro_url" -O "$filename.${file##*.}"
file="$filename.${file##*.}"
NEXTID=$(pvesh get /cluster/nextid)
vm_id=$NEXTID
vm_name="Ubuntu"
qm create $vm_id --name $vm_name --net0 virtio,bridge=vmbr0 >/dev/null
qm importdisk $vm_id $file local-lvm >/dev/null
qm set $vm_id --scsihw virtio-scsi-pci --scsi0 local-lvm:vm-$vm_id-disk-0 >/dev/null
qm set $vm_id --ide2 local-lvm:cloudinit >/dev/null
qm set $vm_id --boot c --bootdisk scsi0 >/dev/null
qm set $vm_id --memory 2048 >/dev/null
qm set $vm_id --balloon 0 >/dev/null
qm set $vm_id --onboot 0 >/dev/null
qm set $vm_id --cores 2 >/dev/null
qm set $vm_id --tablet 0 >/dev/null
qm set $vm_id --agent enabled=1 >/dev/null
qm set $vm_id --serial0 socket --vga serial0 >/dev/null
qm set $vm_id --ipconfig0 ip=dhcp,ip6=dhcp >/dev/null
qm set $vm_id --ciuser test --cipassword test >/dev/null
function make_template() {
qm template $vm_id >/dev/null
}

View File

@ -1,144 +0,0 @@
#!/bin/bash
# ____ _ _
#/ ___|| |_| |__ ___ _ __ ___
#\___ \| __| '_ \ / _ \| '_ \ / _ \
# ___) | |_| | | | (_) | |_) | __/
#|____/ \__|_| |_|\___/| .__/ \___|
# |_|
#
# Associative array to hold the URLs for different distributions
declare -A distros=(
["1"]="https://cloud.debian.org/images/cloud/bookworm/latest/debian-12-genericcloud-amd64.qcow2"
["2"]="https://cloud-images.ubuntu.com/jammy/current/jammy-server-cloudimg-amd64.img"
)
# Associative array to hold the names of different distributions
declare -A distro_names=(
["1"]="Debian 12 (bookworm)"
["2"]="Ubuntu Server 22.04 (jammy)"
)
# Function to download the distribution
function download_distro() {
local distro_url="$1"
local filename="proxmox_cloudinit"
file=$(basename "$distro_url")
if wget -q "$distro_url" -O "$filename.${file##*.}"; then
echo "Download completed: $filename.${file##*.}"
else
echo "Download failed. Please check the distribution URL and try again."
exit 1
fi
file="$filename.${file##*.}"
}
# Display usage/help message
function display_usage() {
echo "Usage: proxmox_vms [OPTION]"
echo "Options:"
echo " --distro NUM Download the specified distribution automatically"
echo " -h, --help Display this help message"
echo
echo "Available distributions:"
for distro_num in "${!distros[@]}"; do
echo " $distro_num: ${distro_names[$distro_num]}"
done
}
# Check if the wget command is available
if ! command -v wget &> /dev/null; then
echo "Error: wget command not found. Please install wget to use this script."
exit 1
fi
# Parse command-line arguments using getopts
while getopts ":h-:" opt; do
case "${opt}" in
h)
display_usage
exit 0
;;
-)
case "${OPTARG}" in
distro)
# Long option --distro for specifying the distribution number
distro_number="${!OPTIND}"
((OPTIND++))
;;
help)
display_usage
exit 0
;;
*) # Invalid option
echo "Invalid option: --${OPTARG}"
display_usage
exit 1
;;
esac
;;
*)
# Invalid option
echo "Invalid option: -$OPTARG"
display_usage
exit 1
;;
esac
done
# If a distro number is provided, download the specified distribution
if [[ -n "$distro_number" ]]; then
distro_url="${distros[$distro_number]}"
if [[ -z "$distro_url" ]]; then
echo "Invalid distribution number. Please choose one of the available options."
exit 1
fi
download_distro "$distro_url"
else
# If no distro number provided, ask the user interactively
echo "Available distributions:"
for distro_num in "${!distros[@]}"; do
echo "$distro_num: ${distro_names[$distro_num]}"
done
read -p "Enter the number corresponding to the distribution you want to install: " choice
if [[ -z "${distros[$choice]}" ]]; then
echo "Invalid choice. Please choose one of the available options."
exit 1
fi
download_distro "${distros[$choice]}"
fi
function show_usage() {
echo "Usage: $0 [--config_file <file.json>]"
exit 1
}
function create_vm() {
local vm_id=666
local vm_name="template"
qm create $vm_id --name $vm_name --net0 virtio,bridge=vmbr0
qm importdisk $vm_id $file local-lvm
qm set $vm_id --scsihw virtio-scsi-pci --scsi0 local-lvm:vm-$vm_id-disk-0
qm set $vm_id --ide2 local-lvm:cloudinit
qm set $vm_id --boot c --bootdisk scsi0
qm set $vm_id --memory 2048
qm set $vm_id --balloon 0
qm set $vm_id --onboot 0
qm set $vm_id --cores 2
qm set $vm_id --tablet 0
qm set $vm_id --agent enabled=1
qm set $vm_id --serial0 socket --vga serial0
qm set $vm_id --ipconfig0 ip=dhcp,ip6=dhcp
qm set $vm_id --ciuser test --cipassword test
}
create_vm
function make_template() {
qm template $vm_id
}

View File

@ -9,7 +9,7 @@
clear
# Ubuntu Server 22.04 (jammy)
distro_url="https://cloud.debian.org/images/cloud/bookworm/latest/debian-12-genericcloud-amd64.qcow2"
distro_url="https://cloud-images.ubuntu.com/jammy/current/jammy-server-cloudimg-amd64.img"
filename="proxmox_cloudinit"
wget -q "$distro_url" -O "$filename.${file##*.}"
@ -19,22 +19,24 @@ NEXTID=$(pvesh get /cluster/nextid)
vm_id=$NEXTID
vm_name="Ubuntu"
qm create $vm_id --name $vm_name --net0 virtio,bridge=vmbr0 >/dev/null
qm create $vm_id --memory 2048 --core 2 --name $vm_name --net0 virtio,bridge=vmbr0 >/dev/null
qm importdisk $vm_id $file local-lvm >/dev/null
qm set $vm_id --scsihw virtio-scsi-pci --scsi0 local-lvm:vm-$vm_id-disk-0 >/dev/null
qm set $vm_id --ide2 local-lvm:cloudinit >/dev/null
qm set $vm_id --boot c --bootdisk scsi0 >/dev/null
qm set $vm_id --memory 2048 >/dev/null
qm set $vm_id --serial0 socket --vga serial0 >/dev/null
qm set $vm_id --balloon 0 >/dev/null
qm set $vm_id --onboot 0 >/dev/null
qm set $vm_id --cores 2 >/dev/null
qm set $vm_id --tablet 0 >/dev/null
qm set $vm_id --agent enabled=1 >/dev/null
qm set $vm_id --serial0 socket --vga serial0 >/dev/null
qm set $vm_id --ipconfig0 ip=dhcp,ip6=dhcp >/dev/null
qm set $vm_id --ciuser test --cipassword test >/dev/null
function make_template() {
qm template $vm_id >/dev/null
qm template $vm_id >/dev/null
}
function clone_template() {
qm clone $vm_id $vm_cloned_id --name $vm_cloned_name --full >/dev/null
}