Skip to content

Instantly share code, notes, and snippets.

@pkejval
Last active April 26, 2021 12:24
Show Gist options
  • Save pkejval/3c5a2dce94080185a05de6c08508ba04 to your computer and use it in GitHub Desktop.
Save pkejval/3c5a2dce94080185a05de6c08508ba04 to your computer and use it in GitHub Desktop.
Update script for pve-edge-kernel
#!/bin/bash
set +m
shopt -s lastpipe
DEBUG=0
RESTART=0
INDEX=0
while getopts ":dr" options; do
case "${options}" in
d)
DEBUG=1
;;
r)
RESTART=1
;;
*)
echo "Use -r argument to automaticaly reboot machine after installing new kernel version"
echo "Use -d argument to initiate DEBUG MODE. This mode WON'T download nor install new update. This is for debugging only."
exit 1
;;
esac
done
KERNEL=$(uname -r)
echo "Running kernel version: $KERNEL"
# Get newest tag from GitHub
NEWEST=$(wget -qO- https://api.github.com/repos/fabianishere/pve-edge-kernel/tags | jq -r '[.[].name][0]')
echo "Found version: $NEWEST"
for version in $(dpkg --list | grep pve-edge-kernel | awk '{print $3}'); do
if [ "$NEWEST" == "$KERNEL" ] || [ "$NEWEST" == "$version" ]; then
echo "Update not needed. This version is already installed."
exit 0
fi
done
DIR=$(mktemp -d -t pve-kernel-edge-XXXXXXXX)
cd "$DIR"
# Download and parse kernel information from GitHub
wget -qO- https://api.github.com/repos/fabianishere/pve-edge-kernel/releases | jq -r --arg NEWEST "$NEWEST" '[.[] | select(.tag_name | index($NEWEST))][0].assets[] | select(.name | index("lake") | not) | select(.name | index("zen") | not).browser_download_url' | while read object; do
if [ $DEBUG -eq 0 ]; then
wget -q "$object" --show-progress
else
echo "DEBUG: Should download $object"
fi
let INDEX++
done
# Install kernel
if [ $INDEX -gt 0 ]; then
echo "Installing new kernel"
if [ $DEBUG -eq 0 ]; then
dpkg -i linux* pve-*
else
echo "DEBUG: Actually not installing"
fi
fi
# Cleanup temp
if [ -d "$DIR" ]; then
rm -rf "$DIR"
fi
# Reboot machine if kernel was updated and user requested it
if [ $INDEX -gt 0 ] && [ $RESTART -gt 0 ]; then
echo "Rebooting machine"
if [ $DEBUG -eq 0 ]; then
reboot
else
echo "DEBUG: Actually not restarting"
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment