Skip to content

Commit

Permalink
add section about updates
Browse files Browse the repository at this point in the history
  • Loading branch information
CodaBool committed Apr 18, 2024
1 parent 7671254 commit 07835b5
Showing 1 changed file with 88 additions and 0 deletions.
88 changes: 88 additions & 0 deletions pages/blog/32.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,8 @@ Since I have a self-host server I am leveraging this to synchronize my notes acr


# Snapper rollbacks
This setup enables snapshots to be automatically made before and after every package update.
This also will add grub entries which allow you to boot to a previous version in case something breaks and you cannot login.


```bash
Expand Down Expand Up @@ -285,3 +287,89 @@ mount -a
# 3. edit /usr/lib/systemd/system/snapper-timeline.timer to weekly so less snapshots need to be made
```


# Automatic Updates
While they are not recommended in the Arch community. I have enabled automatic updates. I am taking this risk since I have the above rollbacks in place. I do write down for debugging exactly what versions everything had before the update and after.

The frequency for how often you should do your updates in Arch is not an aggreed upon value. Most people will update their system and all packages at least once a week to once a month. There are outliers which update daily and those that don't update for years. It is a balance of not collecting all bugs immediately as they are pushed out and not waiting for too long that you become an edge case for the developer. Waiting too long to update can be risky because you are now falling out of line with how the developers are testing their updates. Put another way, incremental updates are significantly safer than large versions jumps.

I have settled on weekly updates that happen on Thursday night (or whenever the closest boot to that time happens). Here is the script which updates everything and writes the versions to a file in my ~/Documents folder. Ideally I'd like to have some kind of automation that before shutdown on Thursday it would perform the update but I have looked into that yet.

```bash
#!/bin/bash

# records versions before and after updating
# updates all of official, AUR, and flatpaks to latest

# assumes using flatpak and paru

BACKUP_LOCATION=/home/codabool/Documents/codabool.packages.backup

function write_versions() {
# write packages and their description
# https://superuser.com/questions/1523973/archlinux-pacman-list-installed-packages-with-description?newreg=828a1d0f69b542a88afc8f1a2a35dddc
echo -e "\n\nPackages\n" >> $BACKUP_LOCATION
for line in "$(pacman -Qqe)"; do
pacman -Qi $(echo "$line"); done \
| perl -pe 's/ +/ /gm' \
| perl -pe 's/^(Groups +: )(.*)/$1($2)/gm' \
| perl -0777 -pe 's/^Name : (.*)\nVersion :(.*)\nDescription : ((?!None).*)?(?:.|\n)*?Groups :((?! \(None\)$)( )?.*)?(?:.|\n(?!Name))+/$1$2$4\n $3/gm' \
| grep -A1 --color -P "^[^\s]+" >> $BACKUP_LOCATION

echo -e "\n\nFlatpaks\n" >> $BACKUP_LOCATION
flatpak list >> $BACKUP_LOCATION

echo -e "\nkernal = $(uname -r)\n" >> $BACKUP_LOCATION

echo -e "\nplasma = $(pacman -Q plasma-desktop)\n" >> $BACKUP_LOCATION

systemctl --version | head -n 1 >> $BACKUP_LOCATION

echo -e "\n" >> $BACKUP_LOCATION

nvidia-smi >> $BACKUP_LOCATION
}


# move previous to a backup
mv $BACKUP_LOCATION "$BACKUP_LOCATION.old"

echo -e "====== Pre-update ======" >> $BACKUP_LOCATION
write_versions

# update keyring
sudo pacman -Sy archlinux-keyring --noconfirm && sudo pacman -Su --noconfirm

# update packages
paru -Syu --skipreview --removemake --nocleanafter --pgpfetch --noconfirm

/usr/bin/flatpak update --noninteractive --assumeyes

echo -e "\n\n====== Post-update ======" >> $BACKUP_LOCATION

write_versions
```


> this is then ran by a timer
```toml
[Unit]
Description=System update

[Timer]
OnCalendar=Thur 20:00 America/New_York

[Install]
WantedBy=timers.target
```

> paired with a service
```toml
[Unit]
Description=System update
After=network.target

[Service]
Type=oneshot
ExecStart=/home/codabool/code/scripts/bash-scripts/update
```

0 comments on commit 07835b5

Please sign in to comment.