Re: sysupgrade -c

Manuel Giraud <[email protected]>
Newsgroups gmane.os.openbsd.tech
Message-ID <[email protected]>
Stuart Henderson <[email protected]> writes:

>> > I'd recommend no new version -> no output (like syspatch -c does),
>> > so it can be used in cron without an extra | grep -v.
>> 
>> Ok but then I think I should also tame the verbosity of ftp when using
>> this flag, no?
>
> yes.

What about this?

Index: sysupgrade.8
===================================================================
RCS file: /cvs/src/usr.sbin/sysupgrade/sysupgrade.8,v
diff -u -p -r1.23 sysupgrade.8
--- sysupgrade.8	11 Nov 2025 15:18:30 -0000	1.23
+++ sysupgrade.8	3 Jul 2026 16:01:21 -0000
@@ -22,7 +22,7 @@
 .Nd upgrade system to the next release or a new snapshot
 .Sh SYNOPSIS
 .Nm
-.Op Fl fkns
+.Op Fl cfkns
 .Op Fl b Ar base-directory
 .Op Fl R Ar version
 .Op Ar installurl | path
@@ -54,6 +54,9 @@ Download files to
 .Ar base-directory Ns / Ns Pa _sysupgrade
 instead of
 .Pa /home/_sysupgrade .
+.It Fl c
+Print availability of a new version.
+The sets are not downloaded.
 .It Fl f
 For snapshots, force an already applied upgrade.
 This option has no effect on releases.
Index: sysupgrade.sh
===================================================================
RCS file: /cvs/src/usr.sbin/sysupgrade/sysupgrade.sh,v
diff -u -p -r1.62 sysupgrade.sh
--- sysupgrade.sh	21 Mar 2026 01:34:25 -0000	1.62
+++ sysupgrade.sh	3 Jul 2026 16:01:21 -0000
@@ -74,6 +74,7 @@ rmel() {
 
 SNAP=false
 FILE=false
+CHECK=false
 FORCE=false
 FORCE_VERSION=false
 KEEP=false
@@ -83,9 +84,10 @@ WHAT='release'
 VERSION=$(uname -r)
 NEXT_VERSION=$(echo ${VERSION} + 0.1 | bc)
 
-while getopts b:fknrR:s arg; do
+while getopts b:cfknrR:s arg; do
 	case ${arg} in
 	b)	SETSDIR=${OPTARG}/_sysupgrade;;
+	c)	CHECK=true;;
 	f)	FORCE=true;;
 	k)	KEEP=true;;
 	n)	REBOOT=false;;
@@ -140,11 +142,18 @@ fi
 install -d -o 0 -g 0 -m 0755 ${SETSDIR}
 cd ${SETSDIR}
 
-echo "Fetching from ${URL}"
-if ! unpriv -f SHA256.sig ftp -N sysupgrade -Vmo SHA256.sig ${URL}SHA256.sig; then
+# Reduce verbosity when we're just checking for a new version.
+if $CHECK; then
+    ftpflags="-N sysupgrade -V"
+else
+    ftpflags="-N sysupgrade -Vm"
+fi
+
+$CHECK || echo "Fetching from ${URL}"
+if ! unpriv -f SHA256.sig ftp $ftpflags -o SHA256.sig ${URL}SHA256.sig; then
 	if [[ -n ${ALT_URL} ]]; then
-		echo "Fetching from ${ALT_URL}"
-		unpriv -f SHA256.sig ftp -N sysupgrade -Vmo SHA256.sig ${ALT_URL}SHA256.sig
+		$CHECK || echo "Fetching from ${ALT_URL}"
+		unpriv -f SHA256.sig ftp $ftpflags -o SHA256.sig ${ALT_URL}SHA256.sig
 		URL=${ALT_URL}
 		NEXT_VERSION=${VERSION}
 	else
@@ -166,30 +175,38 @@ if ! [[ -r /etc/signify/$KEY ]]; then
 	    tail -2 | head -1 | cut -d- -f2)
 	BUNDLE=sigbundle-${HAVEKEY}.tgz
 	FWKEY=$(echo $KEY | sed -e 's/base/fw/')
-	echo "Adding missing keys from bundle $BUNDLE"
-	unpriv -f ${BUNDLE} ftp -N sysupgrade -Vmo $BUNDLE https://ftp.openbsd.org/pub/OpenBSD/signify/$BUNDLE
+	$CHECK || echo "Adding missing keys from bundle $BUNDLE"
+	unpriv -f ${BUNDLE} ftp $ftpflags -o $BUNDLE https://ftp.openbsd.org/pub/OpenBSD/signify/$BUNDLE
 	signify -Vzq -m - -x $BUNDLE | (cd /etc/signify && tar xfz - $KEY $FWKEY)
 	rm $BUNDLE
 fi
 
-unpriv -f SHA256 signify -Ve -x SHA256.sig -m SHA256
+unpriv -f SHA256 signify -Ve ${CHECK:+-q} -x SHA256.sig -m SHA256
 rm SHA256.sig
 
-if cmp -s /var/db/installed.SHA256 SHA256 && ! $FORCE; then
+if cmp -s /var/db/installed.SHA256 SHA256 && ! $FORCE && ! $CHECK; then
 	echo "Already on latest ${WHAT}."
 	exit 0
 fi
 
-unpriv -f BUILDINFO ftp -N sysupgrade -Vmo BUILDINFO ${URL}BUILDINFO
+unpriv -f BUILDINFO ftp $ftpflags -o BUILDINFO ${URL}BUILDINFO
 unpriv cksum -qC SHA256 BUILDINFO
 
 if [[ -e /var/db/installed.BUILDINFO ]]; then
 	installed_build_ts=$(cut -f3 -d' ' /var/db/installed.BUILDINFO)
 	build_ts=$(cut -f3 -d' ' BUILDINFO)
-	if (( $build_ts <= $installed_build_ts )) && ! $FORCE; then
+	if $CHECK; then
+	    build_human_ts=$(cut -f5- -d' ' BUILDINFO)
+	    if (( $build_ts > $installed_build_ts )); then
+		echo "A new version ($build_human_ts) is available."
+	    fi
+	    exit 0
+	elif (( $build_ts <= $installed_build_ts )) && ! $FORCE; then
 		echo "Downloaded ${WHAT} is older than installed system. Use -f to force downgrade."
 		exit 1
 	fi
+elif $CHECK; then
+    err "Cannot find installed version."
 fi
 
 # INSTALL.*, bsd*, *.tgz
@@ -210,7 +227,7 @@ done
 
 [[ -n ${OLD_FILES} ]] && rm ${OLD_FILES}
 for f in ${DL}; do
-	unpriv -f $f ftp -N sysupgrade -Vmo ${f} ${URL}${f}
+	unpriv -f $f ftp $ftpflags -o ${f} ${URL}${f}
 done
 
 if [[ -n ${DL} ]]; then

-- 
Manuel Giraud
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.