You are not logged in.
I saw some fancy notifiers using Desktop Notification or the systray on this forum, but nothing suitable for my arch server.
The following snippet check for updates once a day, whenever you spawn a new shell.
#!/bin/bash
# add this to your bashrc/zshrc
function _current_epoch {
echo "$(($(date +%s) / 60 / 60 / 24))"
}
function _check_updates {
(
flock -n 9 || return # one concurrent update process at the time
local ignored_pkgs="^linux"
#local updates=`wc -l < /var/log/pacman-updates.log`
local updates=`grep -Ev $ignored_pkgs /var/log/pacman-updates.log | wc -l`
if [ $updates -gt 0 ]; then
echo -n "There are $updates updates. Upgrade? (y/n) [n] "
read line
if [ "$line" = Y ] || [ "$line" = y ]; then
yaourt -Syu --aur
pacman -Qu | sudo tee /var/log/pacman-updates.log >/dev/null
fi
fi
echo "$(_current_epoch)" > $HOME/.pacman-update
) 9> ~/.pacman-update.lck
}
if [[ $- == *i* ]] && # only interactive shells
[ -e /var/log/pacman-updates.log ] && # only after first update
[ ! -e /var/lib/pacman/db.lck ]; then # not if pacman is running
if [ -e .pacman-update ]; then
read last_epoch < $HOME/.pacman-update
if [[ -n "$last_epoch" ]]; then
if [ $(($(_current_epoch) - $last_epoch)) -ge 1 ]; then
_check_updates
fi
fi
unset last_epoch
else
_check_updates
fi
fi
To keep my package cache up to date I use a systemd.timer unit.
It prefetchs all new packages without installing them or touching the database
#/etc/systemd/timer-daily.timer
[Unit]
Description=Daily Timer
[Timer]
OnBootSec=10min
OnUnitActiveSec=1d
Unit=timer-daily.target
[Install]
WantedBy=basic.target
#/etc/systemd/timer-daily.target
[Unit]
Description=Daily Timer Target
StopWhenUnneeded=yes
#/etc/systemd/timer-daily.target.wants/pacman-update.service
[Unit]
Description=Update pacman's package cache
[Service]
Type=oneshot
Nice=19
IOSchedulingClass=2
IOSchedulingPriority=7
Environment=CHECKUPDATE_DB=/var/lib/pacman/checkupdate
ExecStartPre=/bin/sh -c "/usr/bin/checkupdates > /var/log/pacman-updates.log"
ExecStart=/usr/bin/pacman --sync --upgrades --downloadonly --noconfirm --dbpath=/var/lib/pacman/checkupdate
Have fun.
UPDATE
Use the safer checkupdates script, so it will not touch the sync database, which prevents dangerous partial system upgrades
UPDATE 2
Do not check for updates if pacman is running. Use Type=oneshot to prevent timeout.
Last edited by Mic92 (2013-07-20 05:04:33)
Offline
Running -Sy automatically is quite bad. Instead replace all this with the "checkupdates" command that already comes with pacman.
Offline
Thank you Mic92, I appreciate this effort. Pacman needs more control options. Automatic update is an area for work though some may think otherwise. My experience is that logging pacnew files with nightly or weekly auto-reboot keeps auto-updates running fine. I inspect pacnew files by remote SSH once a month.
Pierre, what command line(s) did you mean by "checkupdates"?
Offline
Pierre, what command line(s) did you mean by "checkupdates"?
Run "checkupdates"... It is a script provided by pacman.
Offline
Running -Sy automatically is quite bad. Instead replace all this with the "checkupdates" command that already comes with pacman.
What are the possible consequence of just using pacman -Syuw.
As far a as I understand it only updates my local package database and download the packages?
Offline
The problem is that it doesn't install the packages in question (but unsupervised - i.e. '--noconfirm' updating - is a bad idea too). If you now run 'pacman -S foo' without performing a proper full system update first, it can lead to breakage: https://bbs.archlinux.org/viewtopic.php?id=89328
Offline
I replaced pacman -Sy with checkupdates. I assume it is save to update just the package cache without alternating the database, isn't it?
Offline
Yes, checkupdates uses a temporary database.
Offline
Tip, look into pacaur philosophy.
Shell helpers seem strange to mix with automation. My habit at shell is to enter pacaur -Syu and say no to the updates unless/until I want what I see, or the update list gets big. In that case I plan a restaurant break to coincide with my manual update.
Autoupdates can run at a particular time like early AM before working hours, when nightowls finally sleep but before morning office rush.
Offline