Please ignore my last patch, since I had mixed up the -l and -c flags from syspatch. This new patch will work for both releases and snapshots as well.

When running on a snapshot, it still outputs the SHA256.sig transfer and "Signature Verified" to stdout, which isn't ideal, but it's a start.

Output:
--------------------
# sysupgrade.sh -c -r

# sysupgrade.sh -c -r
New release available: 6.6

# sysupgrade.sh -c -s
SHA256.sig 100% |*************************************************************************************************| 2141 00:00
Signature Verified
New snapshot available.

# sysupgrade.sh -c -s
SHA256.sig 100% |*************************************************************************************************| 2141 00:00
Signature Verified



Andrew


Index: sysupgrade.8
===================================================================
RCS file: /cvs/src/usr.sbin/sysupgrade/sysupgrade.8,v
retrieving revision 1.8
diff -u -p -u -p -r1.8 sysupgrade.8
--- sysupgrade.8        9 May 2019 21:09:37 -0000       1.8
+++ sysupgrade.8        1 Jun 2019 21:04:50 -0000
@@ -14,7 +14,7 @@
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 .\"
-.Dd $Mdocdate: May 9 2019 $
+.Dd $Mdocdate: June 1 2019 $
 .Dt SYSUPGRADE 8
 .Os
 .Sh NAME
@@ -22,7 +22,7 @@
 .Nd upgrade system to the next release or a new snapshot
 .Sh SYNOPSIS
 .Nm
-.Op Fl fkn
+.Op Fl cfkn
 .Op Fl r | s
 .Op Ar installurl
 .Sh DESCRIPTION
@@ -48,6 +48,8 @@ triggering a one-shot upgrade using the
 .Pp
 The options are as follows:
 .Bl -tag -width Ds
+.It Fl c
+Show if there's an available upgrade; suitable for cron(8).
 .It Fl f
 Force an already applied upgrade.
 The default is to upgrade to latest snapshot only if available.
Index: sysupgrade.sh
===================================================================
RCS file: /cvs/src/usr.sbin/sysupgrade/sysupgrade.sh,v
retrieving revision 1.21
diff -u -p -u -p -r1.21 sysupgrade.sh
--- sysupgrade.sh       14 May 2019 14:27:49 -0000      1.21
+++ sysupgrade.sh       1 Jun 2019 21:04:50 -0000
@@ -33,7 +33,7 @@ ug_err()

 usage()
 {
-       ug_err "usage: ${0##*/} [-fkn] [-r | -s] [installurl]"
+       ug_err "usage: ${0##*/} [-cfkn] [-r | -s] [installurl]"
 }

 unpriv()
@@ -73,10 +73,12 @@ RELEASE=false
 SNAP=false
 FORCE=false
 KEEP=false
+CRON=false
 REBOOT=true

-while getopts fknrs arg; do
+while getopts cfknrs arg; do
        case ${arg} in
+       c)      CRON=true;;
        f)      FORCE=true;;
        k)      KEEP=true;;
        n)      REBOOT=false;;
@@ -118,6 +120,14 @@ else
        URL=${MIRROR}/${NEXT_VERSION}/${ARCH}/
 fi

+if $CRON && $RELEASE; then
+       set +e
+ if unpriv -f SHA256.sig ftp -Vmo /dev/null ${URL}SHA256.sig 2>/dev/null; then
+               echo "New release available: ${NEXT_VERSION}"
+       fi
+       exit 0
+fi
+
 if [[ -e ${SETSDIR} ]]; then
        eval $(stat -s ${SETSDIR})
        [[ $st_uid -eq 0 ]] ||
@@ -150,8 +160,13 @@ unpriv -f SHA256 signify -Ve -p "${SIGNI
 rm SHA256.sig

 if cmp -s /var/db/installed.SHA256 SHA256 && ! $FORCE; then
-       echo "Already on latest snapshot."
+       if ! $CRON; then
+               echo "Already on latest snapshot."
+       fi
        exit 0
+elif $CRON; then
+       echo "New snapshot available."
+        exit 0
 fi

 # INSTALL.*, bsd*, *.tgz



On 2019-06-01 1:47 a.m., Andrew Klaus wrote:
This adds the ability to check if you're running the latest release, without actually upgrading. I'd like to use this functionality when writing an Ansible module for sysupgrade soon. I already have one for syspatch that's been accepted today.

This follows the same usage (-l) as syspatch(8) to list if an update is available.

Andrew

Index: sysupgrade.sh
===================================================================
RCS file: /cvs/src/usr.sbin/sysupgrade/sysupgrade.sh,v
retrieving revision 1.21
diff -u -p -u -r1.21 sysupgrade.sh
--- sysupgrade.sh    14 May 2019 14:27:49 -0000    1.21
+++ sysupgrade.sh    1 Jun 2019 07:28:10 -0000
@@ -33,7 +33,7 @@ ug_err()

  usage()
  {
-    ug_err "usage: ${0##*/} [-fkn] [-r | -s] [installurl]"
+    ug_err "usage: ${0##*/} [-fkln] [-r | -s] [installurl]"
  }

  unpriv()
@@ -73,12 +73,14 @@ RELEASE=false
  SNAP=false
  FORCE=false
  KEEP=false
+LIST=false
  REBOOT=true

-while getopts fknrs arg; do
+while getopts fklnrs arg; do
      case ${arg} in
      f)    FORCE=true;;
      k)    KEEP=true;;
+    l)      LIST=true;;
      n)    REBOOT=false;;
      r)    RELEASE=true;;
      s)    SNAP=true;;
@@ -116,6 +118,16 @@ if $SNAP; then
      URL=${MIRROR}/snapshots/${ARCH}/
  else
      URL=${MIRROR}/${NEXT_VERSION}/${ARCH}/
+fi
+
+if ${LIST} && ${RELEASE}; then
+    set +e
+    if unpriv -f SHA256.sig ftp -Vmo /dev/null ${URL}SHA256.sig 2>/dev/null; then
+        echo "Release available: ${NEXT_VERSION}."
+    else
+        echo "Already on latest release."
+    fi
+    exit
  fi

  if [[ -e ${SETSDIR} ]]; then

Reply via email to