Arch Linux Update Script

If you are running Arch, I'm sure you are updating fairly regularly, why not automate it?

This script will update yay, remove orphan packages, clean cache, clear system logs, update anaconda and its packages.

import os

# Update yay packages
os.system("yay -Syyu --noconfirm")

# Remove orphans
orphans = os.popen('yay -Qtdq | wc -l').read()
if int(orphans) > 0:
    print("Removing orphans...")
    os.system("yay -Rns $(pacman -Qtdq) --noconfirm")
else:
    print("No orphans to remove")

# Clean yay cache
os.system("yay -Scc --noconfirm")

# Clear journalctl logs
os.system("sudo journalctl --rotate && sudo journalctl --vacuum-time=1s")

# Update conda and packages
os.system("yes | sudo conda update -n root conda && yes | conda update --all")

You could attach this to a cron job but I prefer to just alias it to 'update' in my .zshrc like so:

alias update="python /path/to/update.py"

Going a step further you could add:

update

to your .zshrc so the script is run each time you open the terminal, nice!