From ca14233bcdab44b0e61c9a278df9e4c01349c907 Mon Sep 17 00:00:00 2001 From: thorstenspille Date: Thu, 12 Oct 2023 11:34:52 +0200 Subject: [PATCH] Add virtio-win-updater --- postinstall | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/postinstall b/postinstall index 4baf43a..267fbfd 100755 --- a/postinstall +++ b/postinstall @@ -585,6 +585,41 @@ EOF EOF } +virtiowin_updater() { + log "Installing virtio-win-updater" + cat << EOF > /usr/local/bin/virtio-win-updater +#!/bin/bash +# +# This script updates the virtio-win iso in Proxmox local storage +content=\$(wget -q -O - https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/stable-virtio/) +server=https://fedorapeople.org +path=\$(echo -e "\$content" | grep -m1 title | cut -d "<" -f2 | cut -d " " -f3) +file=\$(echo -e "\$content" | grep -Eo "virtio-win-0.1.[0-9]+.iso" | grep -m1 virtio) +url=\$server\$path/\$file +if ! find /var/lib/vz/template/iso/\$file > /dev/null 2>&1 ; then + echo "\$(date) New version available. Downloading \$file." + wget -q -O /var/lib/vz/template/iso/\$file \$url + old_virtio=\$(find /var/lib/vz/template/iso/ -name virtio-win* | grep -v \$file) + if [ \$? -eq 0 ]; then + for line in \$old_virtio; do + if ! grep \$(echo \$line | cut -d'/' -f7) /etc/pve/qemu-server/* ; then + echo "\$(date) Deleting \$line." + rm -f \$line + else + echo "\$(date) Keeping \$line - Still in use by VMs." + fi + done + fi +else + echo "\$(date) Already on the current stable version: \$file." +fi +EOF + chmod +x /usr/local/bin/virtio-win-updater + ln -sf /usr/local/bin/virtio-win-updater /etc/cron.daily/virtio-win-updater + log "Running virtio-win-updater" + virtio-win-updater +} + installation_task(){ log "Starting Installation" @@ -604,6 +639,7 @@ installation_task(){ set_mail_delivery create_swap_pool set_default_volblocksize + virtiowin_updater log "Updating initramfs - This will take some time..." update-initramfs -u -k all > /dev/null 2>&1