On Thu, Aug 29, 2019 at 09:50:48AM +0200, Andre Stoebe wrote:
> On 29.08.2019 01:59, Steven Shockley wrote:
> > So, many thanks to everyone who put together the new -stable updates for
> > packages.  Is there a command I can put in the crontab that will only
> > output if there are updates?  Similar to what syspatch or openup does.
> > I tried pkg_add -unx, but that still tells me to delete old files and
> > prints the quirks line even if there are no updates.
> 
> Hi Steven,
> 
> here's what I came up with in my /etc/daily.local file...
> 
> (pkg_add -suv | sed -En 's/^Adding (.+)\(pretending\)/\1/p') 2>&1 \
>     | grep -v ': Requesting'
> 
> Initially I didn't use the verbose option and a simpler sed expression,
> but I eventually found that pkg_add's output differs whether a terminal
> is attached or not. So that's what works for me.
> 
> Regards
> Andre

You could also do as sysupgrade(8) does and download the SHA256 file,
compare it to a locally stored copy of it. If it is different, there
are new packages and you can try running "pkg_add -u" when you have
the inclination to do so (or immediately from the same script). Then
update the locally stored copy of the SHA256 file with the version just
downloaded.

This is my script (note: I'm following snapshots rather than -stable, so
some slight tweaking will be neccesary).  I'm running it with my
unprivilegied user from the command line to upgrade everything (the
first "doas sysupgrade" is not commented out in my version):

#!/bin/sh -eux

# doas sysupgrade  # to also make sure that the system is up-to-date

tmpfile=$(mktemp)
stamp=$HOME/.sha256.ports

trap 'rm -f "$tmpfile"' EXIT

read installurl </etc/installurl

curl -s -o "$tmpfile" "$installurl/snapshots/packages/$(arch -s)/SHA256"

if [ ! -f "$stamp" ] || ! cmp -s "$stamp" "$tmpfile"
then
    doas pkg_add -u -D snap
    cp "$tmpfile" "$stamp"
fi

Reply via email to