On 04/27, Florian Obser wrote:
> On Sat, Apr 27, 2019 at 01:23:20PM +0100, Marco Bonetti wrote:
> > Hello folks,
> > 
> > First of all congratulations on a new OpenBSD release and thanks for
> > introducing sysupgrade in -current.
> > 
> > Before sysupgrade, I was using a custom script for achieving the same
> > result with only difference that I was checking if a new snapshot (or
> > release) is available by looking at BUILDINFO before starting the
> > upgrade process.
> > 
> > Patch below introduce the same behaviour using SHA256.sig as control
> > file. If you believe there is a valid use case for reinstalling already
> > applied sets to the running system please let me know and I can add a
> > -f force option.
> 
> I see a need for the feature and also for the -f flag. One idea was if
> you messed up your shared libs you just type sysupgrade to
> unbreak things. (Doesn't quite work since not all the tools are
> statically linked).

Added

> 
> I'm not happy with comparing the sha256 file, could you please use
> what(1) to compare the downloaded kernel with the running kernel?
> 
> $ sysctl -n kern.version | head -1
> OpenBSD 6.5-current (GENERIC.MP) #32: Fri Apr 26 10:37:48 MDT 2019
> $ what /home/_sysupgrade/bsd.mp | tail -1
>       OpenBSD 6.5-current (GENERIC.MP) #32: Fri Apr 26 10:37:48 MDT 2019
> 
> You need to check if you are running MP or SP though.
> 
> I have also suggested this to Mischa, added to Cc.

This has already been mentioned in the rest of the thread and doesn't
feel too right for me: the kernel can be modified and as a rule of thumb
a package manager or similar doesn't upgrade something if you changed
the content of a file locally. On the other hand if you applied local
modifications and run sysupgrade you robably want to overwrite the disk
contents :)

Maybe the -f option is enough for this?

Anyway, following patches also incorporate suggestions from the rest of
the thread.

Index: usr.sbin/sysupgrade/sysupgrade.8
===================================================================
RCS file: /cvs/src/usr.sbin/sysupgrade/sysupgrade.8,v
retrieving revision 1.2
diff -u -p -u -r1.2 sysupgrade.8
--- usr.sbin/sysupgrade/sysupgrade.8    26 Apr 2019 05:54:49 -0000      1.2
+++ usr.sbin/sysupgrade/sysupgrade.8    28 Apr 2019 22:59:52 -0000
@@ -23,12 +23,13 @@
 .Sh SYNOPSIS
 .Nm
 .Op Fl c
+.Op Fl f
 .Op Ar installurl
 .Sh DESCRIPTION
 .Nm
 is a utility to upgrade
 .Ox
-to the next release or a new snapshot.
+to the next release or a new snapshot if available.
 .Pp
 .Nm
 downloads the necessary files to
@@ -52,6 +53,10 @@ The default is to find out if the system
 In case of release
 .Nm
 downloads the next release.
+.It Fl f
+force an already applied upgrade.
+The default is to upgrade to latest snapshot only if available.
+This option has no effect on releases.
 .El
 .Sh FILES
 .Bl -tag -width "/home/_sysupgrade" -compact

Index: usr.sbin/sysupgrade/sysupgrade.sh
===================================================================
RCS file: /cvs/src/usr.sbin/sysupgrade/sysupgrade.sh,v
retrieving revision 1.7
diff -u -p -u -r1.7 sysupgrade.sh
--- usr.sbin/sysupgrade/sysupgrade.sh   28 Apr 2019 07:21:28 -0000      1.7
+++ usr.sbin/sysupgrade/sysupgrade.sh   28 Apr 2019 22:59:45 -0000
@@ -63,10 +63,12 @@ rmel() {
 }
 
 CURRENT=false
+FORCE=false
 
-while getopts c arg; do
+while getopts cf arg; do
         case ${arg} in
         c)      CURRENT=true;;
+        f)      FORCE=true;;
         *)      usage;;
         esac
 done
@@ -110,7 +112,21 @@ fi
 
 cd ${SETSDIR}
 
-unpriv -f SHA256.sig ftp -Vmo SHA256.sig ${URL}SHA256.sig
+unpriv -f SHA256.sig.tmp ftp -Vmo SHA256.sig.tmp ${URL}SHA256.sig
+TMP_SHA=$(sha256 -q SHA256.sig.tmp)
+
+if [[ ! -f SHA256.sig ]]; then
+       unpriv -f SHA256.sig touch SHA256.sig
+fi
+CUR_SHA=$(sha256 -q SHA256.sig)
+
+if [[ "${TMP_SHA}" = "${CUR_SHA}"  && ${FORCE} != "true" ]]; then
+       rm SHA256.sig.tmp
+       return 0
+fi
+
+cat SHA256.sig.tmp >SHA256.sig
+rm SHA256.sig.tmp
 
 _KEY=openbsd-${_KERNV[0]%.*}${_KERNV[0]#*.}-base.pub
 _NEXTKEY=openbsd-${NEXT_VERSION%.*}${NEXT_VERSION#*.}-base.pub

Enjoy,
Marco

> 
> > 
> > Cheers,
> > Marco
> > 
> > Index: usr.sbin/sysupgrade/sysupgrade.8
> > ===================================================================
> > RCS file: /cvs/src/usr.sbin/sysupgrade/sysupgrade.8,v
> > retrieving revision 1.2
> > diff -u -p -u -r1.2 sysupgrade.8
> > --- usr.sbin/sysupgrade/sysupgrade.8        26 Apr 2019 05:54:49 -0000      
> > 1.2
> > +++ usr.sbin/sysupgrade/sysupgrade.8        27 Apr 2019 11:54:40 -0000
> > @@ -28,7 +28,7 @@
> >  .Nm
> >  is a utility to upgrade
> >  .Ox
> > -to the next release or a new snapshot.
> > +to the next release or a new snapshot if available.
> >  .Pp
> >  .Nm
> >  downloads the necessary files to
> > 
> > Index: usr.sbin/sysupgrade/sysupgrade.sh
> > ===================================================================
> > RCS file: /cvs/src/usr.sbin/sysupgrade/sysupgrade.sh,v
> > retrieving revision 1.6
> > diff -u -p -u -r1.6 sysupgrade.sh
> > --- usr.sbin/sysupgrade/sysupgrade.sh       26 Apr 2019 21:52:39 -0000      
> > 1.6
> > +++ usr.sbin/sysupgrade/sysupgrade.sh       27 Apr 2019 11:54:48 -0000
> > @@ -110,7 +110,19 @@ fi
> >  
> >  cd ${SETSDIR}
> >  
> > -unpriv -f SHA256.sig ftp -Vmo SHA256.sig ${URL}SHA256.sig
> > +unpriv -f SHA256.sig.tmp ftp -Vmo SHA256.sig.tmp ${URL}SHA256.sig
> > +TMP_SHA=$(sha256 -q SHA256.sig.tmp)
> > +
> > +unpriv touch SHA256.sig
> > +CUR_SHA=$(sha256 -q SHA256.sig)
> > +
> > +if [[ "${TMP_SHA}" = "${CUR_SHA}" ]]; then
> > +   rm SHA256.sig.tmp
> > +   return 0
> > +fi
> > +
> > +unpriv cat SHA256.sig.tmp >SHA256.sig
> > +rm SHA256.sig.tmp
> >  
> >  _KEY=openbsd-${_KERNV[0]%.*}${_KERNV[0]#*.}-base.pub
> >  _NEXTKEY=openbsd-${NEXT_VERSION%.*}${NEXT_VERSION#*.}-base.pub
> > 
> 
> -- 
> I'm not entirely sure you are real.

Reply via email to