add initial script

This commit is contained in:
Eric X. Liu 2024-06-23 04:59:11 +00:00
parent e07f2b97d5
commit 699f96e371
9 changed files with 92 additions and 0 deletions

1
.gitattributes vendored Normal file
View File

@ -0,0 +1 @@
images/*.qcow2 filter=lfs diff=lfs merge=lfs -text

3
.githooks/post-checkout Executable file
View File

@ -0,0 +1,3 @@
#!/bin/sh
command -v git-lfs >/dev/null 2>&1 || { echo >&2 "\nThis repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting the 'post-checkout' file in the hooks directory (set by 'core.hookspath'; usually '.git/hooks').\n"; exit 2; }
git lfs post-checkout "$@"

3
.githooks/post-commit Executable file
View File

@ -0,0 +1,3 @@
#!/bin/sh
command -v git-lfs >/dev/null 2>&1 || { echo >&2 "\nThis repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting the 'post-commit' file in the hooks directory (set by 'core.hookspath'; usually '.git/hooks').\n"; exit 2; }
git lfs post-commit "$@"

3
.githooks/post-merge Executable file
View File

@ -0,0 +1,3 @@
#!/bin/sh
command -v git-lfs >/dev/null 2>&1 || { echo >&2 "\nThis repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting the 'post-merge' file in the hooks directory (set by 'core.hookspath'; usually '.git/hooks').\n"; exit 2; }
git lfs post-merge "$@"

3
.githooks/pre-push Executable file
View File

@ -0,0 +1,3 @@
#!/bin/sh
command -v git-lfs >/dev/null 2>&1 || { echo >&2 "\nThis repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting the 'pre-push' file in the hooks directory (set by 'core.hookspath'; usually '.git/hooks').\n"; exit 2; }
git lfs pre-push "$@"

1
.gitignore vendored
View File

@ -26,3 +26,4 @@ Network Trash Folder
Temporary Items
.apdisk
qemu.log

74
cloud-init.sh Executable file
View File

@ -0,0 +1,74 @@
#!/usr/bin/env bash
set -x
# Define the Debian version (e.g., 11, 12, 13)
DEBIAN_VERSION="12"
# Map Debian version to its codename
case $DEBIAN_VERSION in
11)
CODENAME="bullseye"
;;
12)
CODENAME="bookworm"
;;
13)
CODENAME="trixie" # Update with the correct codename when known
;;
*)
echo "Unsupported Debian version"
exit 1
;;
esac
# Define the Debian cloud image directory URL
DEBIAN_IMG_DIR="https://cloud.debian.org/images/cloud/${CODENAME}/"
# Create the local images directory if it doesn't exist
LOCAL_IMG_DIR="images"
mkdir -p $LOCAL_IMG_DIR
# Get the latest image URL using wget and grep
LATEST_IMG=$(wget -qO- $DEBIAN_IMG_DIR | grep -oP '(?<=href=")[^"]*(?=/")' | grep -E '20[0-9]{6}-[0-9]{3}' | sort -V | tail -n 1)
SRC_IMG="${DEBIAN_IMG_DIR}${LATEST_IMG}/debian-${DEBIAN_VERSION}-generic-amd64-${LATEST_IMG}.qcow2"
IMG_NAME="${LOCAL_IMG_DIR}/debian-${DEBIAN_VERSION}-generic-amd64-${LATEST_IMG}.qcow2"
# Download the image if it doesn't already exist
if [ ! -f "$IMG_NAME" ]; then
wget -O $IMG_NAME $SRC_IMG
fi
# Install libguestfs-tools if virt-customize is not available
if ! which virt-customize > /dev/null; then
apt-get update
apt-get install -y libguestfs-tools
fi
# Check if qm is installed and exit if not
if ! which qm > /dev/null; then
echo "qm tool not found. Please install Proxmox VE tools and try again."
exit 1
fi
# Inject SSH key and install qemu-guest-agent
SSH_KEY_PATH="id_rsa.pub"
virt-customize -v -x --install qemu-guest-agent -a $IMG_NAME --root-password password:coolpass --ssh-inject root:file:$SSH_KEY_PATH |& tee qemu.log
# Define VM parameters
TEMPL_NAME="debian-${DEBIAN_VERSION}-generic-$(date +%Y%m%d)"
VMID="9004"
MEM="2048"
DISK_SIZE="64G"
DISK_STOR="local-lvm"
NET_BRIDGE="vmbr0"
# Create the VM and configure its settings
qm create $VMID --name $TEMPL_NAME --memory $MEM --net0 virtio,bridge=$NET_BRIDGE
qm importdisk $VMID $IMG_NAME $DISK_STOR
qm set $VMID --scsihw virtio-scsi-pci --scsi0 $DISK_STOR:vm-$VMID-disk-0
qm set $VMID --ide2 $DISK_STOR:cloudinit
qm set $VMID --boot c --bootdisk scsi0
qm set $VMID --serial0 socket --vga serial0
qm set $VMID --ipconfig0 ip=dhcp,gw=10.10.0.1
qm resize $VMID scsi0 $DISK_SIZE
qm template $VMID

1
id_rsa.pub Normal file
View File

@ -0,0 +1 @@
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAILxqXeI3o6CQb3TqRibikLGH5q8g2GD/f6TVKILix8QS eric@ericxliu.me

BIN
images/debian-12-generic-amd64-20240507-1740.qcow2 (Stored with Git LFS) Normal file

Binary file not shown.