diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..4191946 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +images/*.qcow2 filter=lfs diff=lfs merge=lfs -text diff --git a/.githooks/post-checkout b/.githooks/post-checkout new file mode 100755 index 0000000..ca7fcb4 --- /dev/null +++ b/.githooks/post-checkout @@ -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 "$@" diff --git a/.githooks/post-commit b/.githooks/post-commit new file mode 100755 index 0000000..52b339c --- /dev/null +++ b/.githooks/post-commit @@ -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 "$@" diff --git a/.githooks/post-merge b/.githooks/post-merge new file mode 100755 index 0000000..a912e66 --- /dev/null +++ b/.githooks/post-merge @@ -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 "$@" diff --git a/.githooks/pre-push b/.githooks/pre-push new file mode 100755 index 0000000..0f0089b --- /dev/null +++ b/.githooks/pre-push @@ -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 "$@" diff --git a/.gitignore b/.gitignore index d4777d2..ccc0c54 100644 --- a/.gitignore +++ b/.gitignore @@ -26,3 +26,4 @@ Network Trash Folder Temporary Items .apdisk +qemu.log diff --git a/cloud-init.sh b/cloud-init.sh new file mode 100755 index 0000000..2fe4749 --- /dev/null +++ b/cloud-init.sh @@ -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 diff --git a/id_rsa.pub b/id_rsa.pub new file mode 100644 index 0000000..2edd798 --- /dev/null +++ b/id_rsa.pub @@ -0,0 +1 @@ +ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAILxqXeI3o6CQb3TqRibikLGH5q8g2GD/f6TVKILix8QS eric@ericxliu.me diff --git a/images/debian-12-generic-amd64-20240507-1740.qcow2 b/images/debian-12-generic-amd64-20240507-1740.qcow2 new file mode 100644 index 0000000..67b63e9 --- /dev/null +++ b/images/debian-12-generic-amd64-20240507-1740.qcow2 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f4b8a20e4503bfc9e7c3b2862cceeb5d5a4b6470b3dadc893b63d63886e55687 +size 697303040