Created
March 3, 2025 15:36
-
-
Save danielbodnar/4cca649f83014fce7e3b6c937df597f4 to your computer and use it in GitHub Desktop.
proxmox.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -e | |
# Find next available container ID starting from 1000 | |
function get_next_ctid() { | |
local NEXT_ID=1000 | |
local EXISTING_IDS=$(pct list | tail -n +2 | awk '{print $1}') | |
if [ -n "$EXISTING_IDS" ]; then | |
local MAX_ID=$(echo "$EXISTING_IDS" | sort -n | tail -1) | |
if [ $MAX_ID -ge 1000 ]; then | |
NEXT_ID=$((MAX_ID + 1)) | |
fi | |
fi | |
echo $NEXT_ID | |
} | |
# Configuration | |
CTID=$(get_next_ctid) | |
HOSTNAME="arch-dev" # Container hostname | |
MEMORY="8192" # Memory in MB | |
CORES="4" # CPU cores | |
DISK_SIZE="50G" # Disk size | |
STORAGE="local-lvm" # Storage location | |
USERNAME="bodnar" # Username | |
FULLNAME="Daniel Bodnar" # Full name | |
SSH_KEY_URL="https://github.com/danielbodnar.keys" # SSH keys URL | |
TIMEZONE="America/Central" # Timezone (adjust as needed) | |
echo "Creating Arch Linux container with ID: $CTID..." | |
# Download latest Arch Linux template if not present | |
if [ ! -f /var/lib/vz/template/cache/archlinux-latest.tar.xz ]; then | |
echo "Downloading Arch Linux template..." | |
pveam update | |
pveam available | grep archlinux | |
pveam download local archlinux-latest | |
fi | |
# Create container | |
pct create $CTID /var/lib/vz/template/cache/archlinux-latest.tar.xz \ | |
--hostname $HOSTNAME \ | |
--memory $MEMORY \ | |
--cores $CORES \ | |
--rootfs $STORAGE:$DISK_SIZE \ | |
--net0 name=eth0,bridge=vmbr0,ip=dhcp \ | |
--features nesting=1 \ | |
--start 0 \ | |
--unprivileged 0 # Must be privileged for nested virtualization | |
# Configure container features for nested virtualization and display | |
pct set $CTID -features "nesting=1,keyctl=1,mount=nfs,fuse=1" | |
# Start the container | |
pct start $CTID | |
sleep 5 # Wait for container to start | |
echo "Installing packages and configuring system..." | |
# Rest of the installation steps remain the same as before | |
# Base system update and pacman configuration | |
pct exec $CTID -- bash -c "sed -i 's/^#Color/Color/' /etc/pacman.conf && pacman -Sy" | |
pct exec $CTID -- pacman -Syu --noconfirm | |
# Install base development packages | |
pct exec $CTID -- pacman -S --noconfirm base-devel git zsh vim curl wget sudo | |
# Install Wayland display manager and desktop environment | |
pct exec $CTID -- pacman -S --noconfirm sway waybar xorg-xwayland xdg-desktop-portal-wlr foot | |
# Install development tools | |
pct exec $CTID -- pacman -S --noconfirm nodejs npm yarn python python-pip bun go rust docker | |
# Install VSCode Insiders | |
pct exec $CTID -- bash -c "curl -L https://aka.ms/linux-arm64-insider > /tmp/vscode-insiders.tar.gz && | |
mkdir -p /opt/vscode-insiders && | |
tar -xzf /tmp/vscode-insiders.tar.gz -C /opt/vscode-insiders --strip-components=1 && | |
ln -sf /opt/vscode-insiders/bin/code-insiders /usr/bin/code-insiders" | |
# Install VSCode Server | |
pct exec $CTID -- bash -c "curl -fsSL https://code-server.dev/install.sh | sh" | |
# Set timezone | |
pct exec $CTID -- ln -sf /usr/share/zoneinfo/$TIMEZONE /etc/localtime | |
pct exec $CTID -- hwclock --systohc | |
# Set locale | |
pct exec $CTID -- bash -c "echo 'en_US.UTF-8 UTF-8' > /etc/locale.gen" | |
pct exec $CTID -- locale-gen | |
pct exec $CTID -- bash -c "echo 'LANG=en_US.UTF-8' > /etc/locale.conf" | |
# Create user account | |
pct exec $CTID -- useradd -m -G wheel,video,audio,input -s /bin/zsh $USERNAME | |
pct exec $CTID -- bash -c "echo '$USERNAME ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers.d/$USERNAME" | |
pct exec $CTID -- chfn -f "$FULLNAME" $USERNAME | |
# Set up SSH keys | |
pct exec $CTID -- bash -c "mkdir -p /home/$USERNAME/.ssh" | |
pct exec $CTID -- bash -c "curl -s $SSH_KEY_URL > /home/$USERNAME/.ssh/authorized_keys" | |
pct exec $CTID -- bash -c "chmod 700 /home/$USERNAME/.ssh" | |
pct exec $CTID -- bash -c "chmod 600 /home/$USERNAME/.ssh/authorized_keys" | |
pct exec $CTID -- bash -c "chown -R $USERNAME:$USERNAME /home/$USERNAME/.ssh" | |
# Install Oh My Zsh | |
pct exec $CTID -- bash -c "su - $USERNAME -c 'curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh | sh'" | |
# Enable necessary services | |
pct exec $CTID -- systemctl enable systemd-networkd | |
pct exec $CTID -- systemctl enable systemd-resolved | |
pct exec $CTID -- systemctl enable code-server@$USERNAME | |
echo "Container $CTID has been created and configured successfully!" | |
echo "Access the container with: pct enter $CTID" | |
echo "VSCode Server should be available at: http://<container-ip>:8080" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment