Skip to content

Commit

Permalink
opnsense/os-update: work on the tool's usability
Browse files Browse the repository at this point in the history
Introduce command line switches and a manual page.  It has already
been requested so let's make it happen for 15.1.8.  I do think some
other projects are also interested in having this polished following
current trends and blog posts...  :)
  • Loading branch information
fichtner committed Mar 1, 2015
1 parent 09b46f9 commit fc3b221
Show file tree
Hide file tree
Showing 5 changed files with 127 additions and 20 deletions.
2 changes: 1 addition & 1 deletion opnsense/os-update/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

PORTNAME= os-update
PORTVERSION= 15.1.7
#PORTREVISION= 1
PORTREVISION= 1
CATEGORIES= sysutils
DISTFILES= # none

Expand Down
3 changes: 2 additions & 1 deletion opnsense/os-update/files/Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
SCRIPTS=opnsense-update.sh
MAN= #opnsense-update.8
MAN= opnsense-update.8

PREFIX?=/usr/local
BINDIR= ${PREFIX}/sbin
MANDIR= ${PREFIX}/man/man

.include <bsd.prog.mk>
70 changes: 70 additions & 0 deletions opnsense/os-update/files/opnsense-update.8
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
.\"
.\" Copyright (c) 2015 Franco Fichtner <franco@opnsense.org>
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\"
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\"
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.Dd March 1, 2015
.Dt OPNSENSE-UPDATE 8
.Os
.Sh NAME
.Nm opnsense-update
.Nd OPNsense system update utility
.Sh SYNOPSIS
.Nm
.Op Fl cfv
.Op Fl m Ar mirror
.Op Fl r Ar release
.Sh DESCRIPTION
The
.Nm
utility offers combined kernel and base file upgrades based on binary
sets fetched from a remote mirror.
If no options are given, it updates to the embedded version using
checksum verification fetched from the standard mirror.
.Pp
The options are as follows:
.Bl -tag -width ".Fl r Ar release" -offset indent
.It Fl c
Check wether an update can be performed, but don't install it.
.It Fl f
Force an update even when the latest one is already installed.
.It Fl m Ar mirror
Change the set fetch location to
.Ar mirror .
.It Fl r Ar release
Select the release to be installed and switch of checksumming.
This is intended for development or custom builds only.
.It Fl v
Print the embedded version info.
.El
.Sh FILES
.Bl -tag -width ".Pa /usr/local/opnsense/version/os-update" -compact
.It Pa /usr/local/opnsense/version/os-update
The file is used to check if an upgrade is necessary.
After a successful update, the file is rewritten.
.El
.Sh EXIT STATUS
.Ex -std
.Sh AUTHORS
.An Franco Fichtner Aq Mt franco@opnsense.org
71 changes: 53 additions & 18 deletions opnsense/os-update/files/opnsense-update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@

set -e

# Usage: opnsense-update [version] [mirror]

if [ "$(id -u)" != "0" ]; then
echo "Must be root."
exit 1
Expand All @@ -37,43 +35,77 @@ fi
# clean up old stale working directories
rm -rf /tmp/opnsense-update.*

SETSURL="http://pkg.opnsense.org/sets"
VERSION="15.1.7"
MARKER="/usr/local/opnsense/version/os-update"
MIRROR="http://pkg.opnsense.org/sets"
RELEASE="15.1.7"
ARCH=$(uname -m)

OBSOLETESHA=""
KERNELSHA=""
BASESHA=""

if [ -n "${1}" ]; then
# switches off checksumming!!
VERSION="${1}"
elif [ ${ARCH} = "amd64" ]; then
if [ ${ARCH} = "amd64" ]; then
OBSOLETESHA="053d1d0fcc6b7cb135f512f438f00119a7c073a2d9e97372972d782ae4c0e820"
KERNELSHA="5d1c24196ee05c927e084b3188d1b49663083c550148da561ee82886dd414318"
BASESHA="982f838e375287f1df64945c2c1e6d5ffd96cd53e64b765224f2e9e89797e7f0"
elif [ ${ARCH} = "i386" ]; then
OBSOLETESHA="7e6044cfcdb4ac03309974e08a6f6a83bda0359944e78e4d09b10a5849986d3c"
KERNELSHA="bffbf3485eb69817ea2001767cc400775cd000d5d059276f0e2ae26224ae3556"
BASESHA="e7cee8909d946af804afa428e4640af65d61f9394cdd27ae864d3a2ff5a0f5dc"
else
echo "Unknown architecture ${ARCH}" >&2
exit 1
fi

if [ -n "${2}" ]; then
SETSURL="${2}"
if [ -f ${MARKER} ]; then
INSTALLED=$(cat ${MARKER})
fi

while getopts cfm:r:v OPT; do
case ${OPT} in
c)
if [ ${RELEASE} = "${INSTALLED}" ]; then
exit 1
fi
exit 0
;;
f)
FORCE=1
;;
m)
MIRROR=${OPTARG}
;;
r)
RELEASE=${OPTARG}
# switches off checksumming!!
OBSOLETESHA=""
KERNELSHA=""
BASESHA=""
;;
v)
echo ${RELEASE}-${ARCH}
exit 0
;;
*)
echo "Usage: opnsense-update [-cfv] [-m mirror] [-r release]" >&2
exit 1
;;
esac
done

if [ ${RELEASE} = "${INSTALLED}" -a -z "${FORCE}" ]; then
echo "You are up to date."
exit 0
fi

WORKDIR=/tmp/opnsense-update.${$}
KERNELSET=kernel-${VERSION}-${ARCH}.txz
BASESET=base-${VERSION}-${ARCH}.txz
OBSOLETESET=base-${VERSION}-${ARCH}.obsolete
KERNELSET=kernel-${RELEASE}-${ARCH}.txz
BASESET=base-${RELEASE}-${ARCH}.txz
OBSOLETESET=base-${RELEASE}-${ARCH}.obsolete
KERNELDIR=/boot/kernel

fetch_set()
{
echo -n "Fetching ${1}... "

mkdir -p ${WORKDIR} && \
fetch -q ${SETSURL}/${1} -o ${WORKDIR}/${1} && \
fetch -q ${MIRROR}/${1} -o ${WORKDIR}/${1} && \
[ -z "${2}" -o "`sha256 -q ${WORKDIR}/${1}`" = "${2}" ] && \
echo "ok" && return

Expand Down Expand Up @@ -138,6 +170,9 @@ apply_kernel
apply_base
apply_obsolete

mkdir -p $(dirname ${MARKER})
echo ${RELEASE}-${ARCH} > ${MARKER}

rm -r ${WORKDIR}

echo "Please reboot."
1 change: 1 addition & 0 deletions opnsense/os-update/pkg-plist
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
man/man8/opnsense-update.8.gz
sbin/opnsense-update

0 comments on commit fc3b221

Please sign in to comment.