Last active
September 10, 2022 22:22
-
-
Save ShaRose/a3e0fd4f75ae4f23322ca997e0bd1e87 to your computer and use it in GitHub Desktop.
Script for updating Alpine diskless installs to the latest version: without canning it!
This file contains 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
#!/bin/bash | |
echo "Getting last image..." | |
LastImage="$(curl -s https://dl-cdn.alpinelinux.org/alpine/latest-stable/releases/x86_64/ | sed -n 's/.*"\(alpine-extended-[[:digit:]\.]*-x86_64.iso\)".*/\1/p' | sort -r | head -n 1)" | |
LastVer="$(echo $LastImage | sed -n 's/alpine-extended-\([[:digit:]\.]*\)-x86_64.iso/\1/p')" | |
LastMVer="$(echo $LastVer | sed -n 's/\([[:digit:]]*\.[[:digit:]]*\).*/\1/p')" | |
CurrentVer="$(cat /media/usb/.alpine-release | sed -n 's/alpine-extended-\([[:digit:]\.]*\).*/\1/p')" | |
CurrentMVer="$(echo $CurrentVer | sed -n 's/\([[:digit:]]*\.[[:digit:]]*\).*/\1/p')" | |
echo "Current boot media is $CurrentVer, latest is $LastVer" | |
if [ "$CurrentVer" == "$LastVer" ]; then echo "Already up to date."; return; fi | |
while true; do | |
read -p "Do you want to upgrade Alpine? [N] " yn | |
case $yn in | |
[Yy]* ) break;; | |
[Nn]* ) exit;; | |
* ) echo "Please answer yes or no.";; | |
esac | |
done | |
echo "Upgrading all packages for current version before backup" | |
sudo apk -U upgrade | |
sudo apk cache -v sync | |
sudo lbu st | |
while true; do | |
read -p "Do you want to commit first (You do)? [N] " yn | |
case $yn in | |
[Yy]* ) sudo lbu ci; break;; | |
[Nn]* ) break;; | |
* ) echo "Please answer yes or no.";; | |
esac | |
done | |
sudo lbu ci | |
BackupFile="/tmp/$HOSTNAME-backup-$(date +'%Y%m%d-%H%M%S').tar.gzip" | |
sudo tar -caf $BackupFile /media/usb/cache /media/usb/$HOSTNAME* | |
echo "Make sure you download $BackupFile JUST IN CASE. Note that it's $CurrentVer as well." | |
while true; do | |
read -p "Type READY to process. " rdy | |
case $rdy in | |
READY ) break;; | |
* ) echo "Please type READY or break out.";; | |
esac | |
done | |
if [ "$CurrentMVer" != "$LastMVer" ]; then echo "Repositories need an update first..."; sudo sed -i "s/$CurrentMVer/$LastMVer/g" /etc/apk/repositories; sudo apk -U upgrade; sudo apk cache -v sync; sudo lbu ci; fi | |
sudo setup-bootable -u "https://dl-cdn.alpinelinux.org/alpine/latest-stable/releases/x86_64/$LastImage" | |
echo "All set: Reboot." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment