Skip to content

Instantly share code, notes, and snippets.

@Carlgo11
Last active August 23, 2023 20:51
Show Gist options
  • Save Carlgo11/c7d5c6ba37cb5b0aa54dcfa779a12170 to your computer and use it in GitHub Desktop.
Save Carlgo11/c7d5c6ba37cb5b0aa54dcfa779a12170 to your computer and use it in GitHub Desktop.
APK Update cron job with auto-reboot
#!/bin/sh
# This script runs apk (Alpine Package Keeper) upgrade and checks if the installed kernel version differs from the running.
# If the versions differ, the system reboots.
# Script only runs on Alpine Linux.
apk -U upgrade
sync
installed_version=$(apk -I list | grep '^linux-lts' | sed -n 's/.*-\([0-9.]\+\)-r.*/\1/p')
running_version=$(uname -r | sed 's/\([0-9.]\+\)-.*/\1/')
if [ "$installed_version" != "$running_version" ]; then
reboot
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment