#!/bin/sh
[ $(id -u) = 0 ] || exit
echo deb [arch=amd64 signed-by=/usr/share/keyrings/proxmox-archive-keyring-trixie.gpg] http://download.proxmox.com/debian/pve trixie pve-no-subscription > /etc/apt/sources.list.d/pve-install-repo.list
wget -NP /usr/share/keyrings https://enterprise.proxmox.com/debian/proxmox-archive-keyring-trixie.gpg
apt update
dpkg -P os-prober linux-firmware linux-firmware-nonfree linux-image-amd64 linux-headers-amd64 systemd-timesyncd dhcpcd-base
apt --yes install proxmox-default-kernel
K=$(dpkg -l|awk '/-amd64/&&/linux/{print $2}')
[ "$K" ] && DEBIAN_FRONTEND=noninteractive dpkg -P $K
apt --yes full-upgrade
[ -d /sys/firmware/efi ] && grub-install
DEBIAN_FRONTEND=noninteractive apt --yes install proxmox-ve 
rm -vf /etc/apt/sources.list.d/pve-enterprise.sources
apt update
apt --yes autopurge
if ! grep -q vmbr0 /etc/network/interfaces; then
tee -a /etc/network/interfaces <<EOT
auto vmbr0
iface vmbr0 inet static
	address $(ip -4 -br a show scope global|awk '{print $3;exit}')
	gateway $(ip -4 route|awk '/default/{print $3}')
	bridge-ports $(ip -4 -br a show scope global|awk '{print $1;exit}')
        bridge-stp off
        bridge-fd 0
EOT
fi
[ -f /etc/hosts.1st ] || mv -v /etc/hosts /etc/hosts.1st
tee /etc/hosts <<EOT
127.0.0.1			localhost
$(ip -4 -br a show scope global|awk '{print $3;exit}'|cut -d/ -f1)	$(hostname -A) $(hostname)

# The following lines are desirable for IPv6 capable hosts
::1					localhost ip6-localhost ip6-loopback
ff02::1				ip6-allnodes
ff02::2				ip6-allrouters
EOT
systemctl restart networking.service
apt --yes autopurge network-manager
