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.
]]>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?
Pierre, what command line(s) did you mean by "checkupdates"?
Run "checkupdates"... It is a script provided by pacman.
]]>Pierre, what command line(s) did you mean by "checkupdates"?
]]>#!/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.