diff options
author | jmmv <jmmv@pkgsrc.org> | 2013-07-28 23:37:14 +0000 |
---|---|---|
committer | jmmv <jmmv@pkgsrc.org> | 2013-07-28 23:37:14 +0000 |
commit | 1e05d3fe9b56bc6c753a585976f704c6fd42c164 (patch) | |
tree | ef3ac150c8421ecdfce2ee6d800987ef222b4c0b /sysutils/sysupgrade | |
parent | 06451ac2a67cac6561933bd49ae1ae9a80e0d449 (diff) | |
download | pkgsrc-1e05d3fe9b56bc6c753a585976f704c6fd42c164.tar.gz |
Update to 1.5:
Released on 2013-07-28.
* Sources migrated to a GitHub project from the previous copy in
the pkgsrc repository. sysupgrade is now a first-class package and
includes a traditional build system based on automake and autoconf.
* Moved the sysupgrade script from bin to sbin.
Diffstat (limited to 'sysutils/sysupgrade')
-rw-r--r-- | sysutils/sysupgrade/Makefile | 66 | ||||
-rw-r--r-- | sysutils/sysupgrade/PLIST | 8 | ||||
-rw-r--r-- | sysutils/sysupgrade/TODO | 44 | ||||
-rw-r--r-- | sysutils/sysupgrade/distinfo | 5 | ||||
-rw-r--r-- | sysutils/sysupgrade/files/Kyuafile | 5 | ||||
-rw-r--r-- | sysutils/sysupgrade/files/default.conf | 36 | ||||
-rw-r--r-- | sysutils/sysupgrade/files/sysupgrade.8 | 390 | ||||
-rw-r--r-- | sysutils/sysupgrade/files/sysupgrade.conf.5 | 167 | ||||
-rw-r--r-- | sysutils/sysupgrade/files/sysupgrade.sh | 505 | ||||
-rw-r--r-- | sysutils/sysupgrade/files/sysupgrade_test.sh | 1194 |
10 files changed, 26 insertions, 2394 deletions
diff --git a/sysutils/sysupgrade/Makefile b/sysutils/sysupgrade/Makefile index 85b29ad1b8f..fbecbc73eae 100644 --- a/sysutils/sysupgrade/Makefile +++ b/sysutils/sysupgrade/Makefile @@ -1,9 +1,8 @@ -# $NetBSD: Makefile,v 1.6 2012/10/23 19:51:26 asau Exp $ +# $NetBSD: Makefile,v 1.7 2013/07/28 23:37:14 jmmv Exp $ -DISTNAME= sysupgrade-1.4 +DISTNAME= sysupgrade-1.5 CATEGORIES= sysutils -MASTER_SITES= # empty -DISTFILES= # empty +MASTER_SITES= https://github.com/jmmv/sysupgrade/releases/download/sysupgrade-1.5/ MAINTAINER= jmmv@NetBSD.org COMMENT= Automate upgrades of NetBSD @@ -11,16 +10,18 @@ LICENSE= modified-bsd PKG_INSTALLATION_TYPES= overwrite pkgviews -WRKSRC= ${WRKDIR} -NO_CONFIGURE= YES - -BUILD_SUBST+= -e 's,@SYSUPGRADE_CACHEDIR@,${CACHEDIR},g' -BUILD_SUBST+= -e 's,@SYSUPGRADE_ETCDIR@,${PKG_SYSCONFDIR},g' +GNU_CONFIGURE= yes +TEST_TARGET= check +USE_LANGUAGES= # empty +USE_TOOLS= pkg-config BUILD_DEFS+= VARBASE -CACHEDIR= ${VARBASE}/cache/sysupgrade -OWN_DIRS= ${CACHEDIR} root wheel +SYSUPGRADE_CACHEDIR= ${VARBASE}/cache/sysupgrade +OWN_DIRS= ${SYSUPGRADE_CACHEDIR} root wheel +CONFIGURE_ARGS+= SYSUPGRADE_CACHEDIR=${SYSUPGRADE_CACHEDIR} +CONFIGURE_ARGS+= --sysconfdir=${PKG_SYSCONFDIR} +INSTALL_MAKE_FLAGS+= sysconfdir=${EGDIR} EGDIR= ${PREFIX}/share/examples/sysupgrade CONF_FILES+= ${EGDIR}/default.conf ${PKG_SYSCONFDIR}/sysupgrade.conf @@ -31,50 +32,13 @@ PKG_SUGGESTED_OPTIONS= tests .include "../../mk/bsd.options.mk" .if $(PKG_OPTIONS:Mtests) -PLIST_SUBST+= TESTS= +BUILDLINK_API_DEPENDS.atf-libs+= atf-libs>=0.17 . include "../../devel/atf-libs/buildlink3.mk" - -BUILD_SUBST+= -e 's,@ATF_SH@,${BUILDLINK_PREFIX.atf-libs}/bin/atf-sh,g' - -do-build: build-tests -build-tests: - cp ${FILESDIR}/Kyuafile ${WRKSRC} - sed ${BUILD_SUBST} ${FILESDIR}/sysupgrade_test.sh \ - >${WRKSRC}/sysupgrade_test - chmod +x ${WRKSRC}/sysupgrade_test - -INSTALLATION_DIRS+= tests/sysupgrade - -do-install: install-tests -install-tests: - ${INSTALL_DATA} ${WRKSRC}/Kyuafile ${DESTDIR}${PREFIX}/tests/sysupgrade - ${INSTALL_SCRIPT} ${WRKSRC}/sysupgrade_test \ - ${DESTDIR}${PREFIX}/tests/sysupgrade/ - -do-test: - cd ${WRKSRC} && PATH="${WRKSRC}:${PATH}" kyua test +PLIST_SUBST+= TESTS= .else PLIST_SUBST+= TESTS=@comment .endif -do-build: - sed ${BUILD_SUBST} ${FILESDIR}/sysupgrade.sh \ - | ${BUILDLINK_PREFIX.shtk}/bin/shtk build \ - -s ${SH} -m sysupgrade_main -o ${WRKSRC}/sysupgrade - -.for file in sysupgrade.8 sysupgrade.conf.5 default.conf - sed ${BUILD_SUBST} <${FILESDIR}/${file} >${WRKSRC}/${file} -.endfor - -INSTALLATION_DIRS+= bin ${PKGMANDIR}/man5 ${PKGMANDIR}/man8 \ - share/examples/sysupgrade - -do-install: - ${INSTALL_SCRIPT} ${WRKSRC}/sysupgrade ${DESTDIR}${PREFIX}/bin/ - ${INSTALL_MAN} ${WRKSRC}/sysupgrade.8 \ - ${DESTDIR}${PREFIX}/${PKGMANDIR}/man8/ - ${INSTALL_MAN} ${WRKSRC}/sysupgrade.conf.5 \ - ${DESTDIR}${PREFIX}/${PKGMANDIR}/man5/ - ${INSTALL_DATA} ${WRKSRC}/default.conf ${DESTDIR}${EGDIR} - +BUILDLINK_API_DEPENDS.shtk+= shtk>=1.3 .include "../../devel/shtk/buildlink3.mk" .include "../../mk/bsd.pkg.mk" diff --git a/sysutils/sysupgrade/PLIST b/sysutils/sysupgrade/PLIST index 7f08f68c0b3..d7c37698ecf 100644 --- a/sysutils/sysupgrade/PLIST +++ b/sysutils/sysupgrade/PLIST @@ -1,7 +1,11 @@ -@comment $NetBSD: PLIST,v 1.2 2012/08/15 21:21:15 jmmv Exp $ -bin/sysupgrade +@comment $NetBSD: PLIST,v 1.3 2013/07/28 23:37:14 jmmv Exp $ man/man5/sysupgrade.conf.5 man/man8/sysupgrade.8 +sbin/sysupgrade +share/doc/sysupgrade/AUTHORS +share/doc/sysupgrade/COPYING +share/doc/sysupgrade/NEWS +share/doc/sysupgrade/README share/examples/sysupgrade/default.conf ${TESTS}tests/sysupgrade/Kyuafile ${TESTS}tests/sysupgrade/sysupgrade_test diff --git a/sysutils/sysupgrade/TODO b/sysutils/sysupgrade/TODO deleted file mode 100644 index f7d9a78e898..00000000000 --- a/sysutils/sysupgrade/TODO +++ /dev/null @@ -1,44 +0,0 @@ -Things that sysupgrade could do -=============================== - -- Deduce the current NetBSD release from /etc/release and the target - release from etc.tgz and inform the user about the changes. This will be - necessary if the upgrade process needs to apply specific tweaks depending - on the affected NetBSD releases (which is not the case at the moment). - -- Ability to automatically deduce the next upgrade target from a collection - of directories (e.g. from FTP). We should be able to tell sysupgrade to - follow along 6.0.x, or 6.x, or the daily builds and get it to pick the - most recent available build. Having to manually scan FTP directories to - select the correct build is... inconvenient. - -- Ensure that the fetched sets belong to the current architecture. I have - bitten once by mistakenly pointing my custom update scripts to the wrong - platform directory, rendering the machine unusable as soon as base.tgz - was unpacked. - -- Download release checksums and validate files against them. The 'fetch' - command should unconditionally download the checksums every time it is - run and then deduce whether it needs to redownload (possibly-newer) sets - or do nothing. - -- Add destdir support to etcupdate(8) and allow the 'etcupdate' command to - run when destdir is enabled. - -- Maybe sysupgrade should be more interactive by default, letting the user - know what exactly is going to happen before doing so (e.g. what will be - the new version, where things are being downloaded from, etc.), and - providing a "quiet mode" flag instead. etcupdate is interactive anyway, - so adding more interactive steps (as long as they can be disabled) does - not seem a big deal. - - -Things that sysupgrade will NOT do -================================== - -- Non-trivial rollbacks. If rollbacks are ever implemented, they should - be in the form of file system snapshots OR in the form of syspkgs. - Getting sysupgrade to magically store files aside to allow a later - rollback is just too fragile and hard to get right: rollbacks will - rarely will be necessary, but when they are it's very likely that a - tool like this is broken. diff --git a/sysutils/sysupgrade/distinfo b/sysutils/sysupgrade/distinfo new file mode 100644 index 00000000000..f09300195f8 --- /dev/null +++ b/sysutils/sysupgrade/distinfo @@ -0,0 +1,5 @@ +$NetBSD: distinfo,v 1.1 2013/07/28 23:37:14 jmmv Exp $ + +SHA1 (sysupgrade-1.5.tar.gz) = 3141ee4728d6d3b680ed04f552369031bb3b3b09 +RMD160 (sysupgrade-1.5.tar.gz) = 5b1d7c6d45643f2f03bff1df16739a6751d0ceda +Size (sysupgrade-1.5.tar.gz) = 75833 bytes diff --git a/sysutils/sysupgrade/files/Kyuafile b/sysutils/sysupgrade/files/Kyuafile deleted file mode 100644 index bd7f14095f4..00000000000 --- a/sysutils/sysupgrade/files/Kyuafile +++ /dev/null @@ -1,5 +0,0 @@ -syntax("kyuafile", 1) - -test_suite("sysupgrade") - -atf_test_program{name="sysupgrade_test"} diff --git a/sysutils/sysupgrade/files/default.conf b/sysutils/sysupgrade/files/default.conf deleted file mode 100644 index 33441a37c59..00000000000 --- a/sysutils/sysupgrade/files/default.conf +++ /dev/null @@ -1,36 +0,0 @@ -# $NetBSD: default.conf,v 1.2 2012/10/11 00:16:46 jmmv Exp $ - -# Configuration of automatic system upgrades by sysupgrade(8). -# -# See sysupgrade.conf(5) for details on the syntax of this file and the -# meaning of the configuration variables. Note that not all the supported -# configuration variables are listed in this sample configuration file. - -# Path to the release files (local path or remote URL). -#RELEASEDIR="ftp://ftp.NetBSD.org/pub/NetBSD/NetBSD-6.0/$(uname -m)" -#RELEASEDIR="ssh://me@builder.example.net/home/sysbuild/release/$(uname -m)" -RELEASEDIR="/home/sysbuild/release/$(uname -m)" - -# Name of the kernel to be installed. -KERNEL=AUTO # Guess from /netbsd (requires config(1)). - -# Whitespace-separated list of sets to install. -SETS=AUTO # Guess from /etc/mtree/set.* files. - -# Whitespace-separated list of postinstall(8) checks to automatically fix. -POSTINSTALL_AUTOFIX="obsolete" - -# Whether to run etcupdate or not as part of an upgrade. -# -# Running etcupdate is the only interactive step in the upgrade process, so -# setting this variable to 'no' effectively makes upgrades unattended. You -# can later run etcupdate at a later step by hand. -#ETCUPDATE=no - -# Whether to delete the downloaded files after an upgrade or not. -# -# If you set ETCUPDATE=no, you will most likely want to disable -# auto-cleaning as well. The reason for this is that, if you want to later -# do "sysupgrade etcupdate" using the same etc.tgz file downloaded during -# the upgrade, you will need the same etc.tgz file to be present. -#AUTOCLEAN=no diff --git a/sysutils/sysupgrade/files/sysupgrade.8 b/sysutils/sysupgrade/files/sysupgrade.8 deleted file mode 100644 index a2d009f85e2..00000000000 --- a/sysutils/sysupgrade/files/sysupgrade.8 +++ /dev/null @@ -1,390 +0,0 @@ -.\" $NetBSD: sysupgrade.8,v 1.5 2013/02/16 11:17:19 jmmv Exp $ -.\" Copyright 2012 Google Inc. -.\" All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions are -.\" met: -.\" -.\" * Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" * 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. -.\" * Neither the name of Google Inc. nor the names of its contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT -.\" OWNER 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 October 10, 2012 -.Dt SYSUPGRADE 8 -.Os -.Sh NAME -.Nm sysupgrade -.Nd upgrades a NetBSD system to a newer version -.Sh SYNOPSIS -common_flags ::= -.Op Fl c Ar config_name -.Op Fl d Ar destdir -.Op Fl o Ar variable=value -.Pp -.Em Major commands : -.Pp -.Nm -.Op common_flags -.Ar auto -.Op Ar releasedir -.Nm -.Op common_flags -.Ar config -.Op Fl a -.Pp -.Em Standalone upgrade steps : -.Pp -.Nm -.Op common_flags -.Ar clean -.Nm -.Op common_flags -.Ar etcupdate -.Nm -.Op common_flags -.Ar fetch -.Op Ar releasedir -.Nm -.Op common_flags -.Ar kernel -.Op Ar kernel_name -.Nm -.Op common_flags -.Ar modules -.Nm -.Op common_flags -.Ar sets -.Op Ar set1 .. setN -.Nm -.Op common_flags -.Ar postinstall -.Op Ar arg1 .. argN -.Sh DESCRIPTION -.Nm -is a utility that automates the process of upgrading a possibly-running -.Nx -system to a newer release. -.Pp -.Nm -works by first fetching the release sets from a remote site or from a local -directory, then by upgrading the system using such release sets and finally by -taking care of bringing the system configuration up to date. -In other words, -.Nm -does nothing special on its own: it is just a utility that automates a highly -manual process and relies on other tools within the system to perform its job. -.Pp -.Nm -has a subcommand-based interface: every command performs a single step of the -upgrade procedure, and the -.Sq auto -command orchestrates a complete upgrade by invoking the rest of the commands in -a specific order. -There are a set of options that apply to all commands (those stated before the -command name), and every particular command may accept its own options and -arguments as shown in the synopsis. -.Pp -The behavior of -.Nm -is defined by a configuration file that specifies how to apply an update to the -system (see -.Xr sysupgrade.conf 5 ) . -For example, the configuration states which distribution sets ought to be -installed, where they need to be downloaded from, and whether the system -configuration files should be upgraded. -.Pp -The following options apply to all commands: -.Bl -tag -width XoXvariableXvalueXX -.It Fl c Ar config_file -Specifies the configuration file to use. -.Pp -Default: -.Pa @SYSUPGRADE_ETCDIR@/sysupgrade.conf -.It Fl d Ar destdir -Path to the -.Nx -system to upgrade. -.Pp -This optional flag can be used to upgrade a non-live system or for -testing/development purposes. -Note that some steps (particularly -.Sq etcupdate ) -do not support this feature and thus will never be run if set. -.Pp -Default: not set (which means -.Pa / -is affected). -.It Fl o Ar variable=value -Applies an override to the loaded configuration. -.Pp -The -.Ar variable -part of the argument must be any of the recognized configuration variables -described in -.Xr sysupgrade.conf 5 . -The -.Ar value , -if not empty, specifies the value to set the configuration variable to. -If -.Ar value -is empty, then the configuration variable is unset. -.El -.Ss The auto command -The auto command is the most important command in -.Nm , -and is probably the one you will find yourself using most frequently. -This is the command that takes care of upgrading a full -.Nx -installation, and it does so by invoking the other commands in the tool in the -specific order in which they are needed. -.Pp -The optional argument -.Ar releasedir -points to the release directory or URL to use, overriding the value of -.Va RELEASEDIR -in the configuration file (if any). -If you are tracking daily builds from an FTP site, for example, you will -probably want to avoid setting -.Va RELEASEDIR -in the configuration file and instead pass an URL each time you run this -command. -.Pp -The standard upgrade procedure performed by this command is as follows: -.Bl -enum -.It -.Sq fetch : -Retrieve distribution sets into the local cache directory. -.It -.Sq modules : -Unpack new kernel modules. -.It -.Sq kernel : -Upgrade kernel. -.It -.Sq sets : -Upgrade system sets, except configuration files. -.It -.Sq etcupdate : -Merge new changes to configuration files. -This is the only interactive step in the process and can be disabled for this -reason by setting -.Va ETCUPDATE -to false. -.It -.Sq postinstall : -Perform sanity checks and optionally apply unconditional fixes to the upgraded -system. -.It -.Sq clean : -Remove contents of the cache directory. -This can be disabled by setting -.Va AUTOCLEAN -to false in case you want to keep the downloaded distribution files around. -.El -.Ss The clean command -The clean command removes any distribution sets from the local cache directory. -.Ss The config command -The config command dumps the loaded configuration to the standard output. -The format of the output is not a script, so it cannot be fed back into -.Nm . -The purpose of this command is to aid in debugging the configuration of the -tool before performing any builds, particularly when the configuration -files use shell logic to determine the value of any variables. -.Pp -The following options are accepted: -.Bl -tag -width XaXX -.It Fl a -Process automatic variables such as -.Va KERNEL -and -.Va SETS -and display their deduced values instead of only showing the literal -.Sq AUTO . -.El -.Ss The etcupdate command -The etcupdate command invokes -.Xr etcupdate 8 -to perform an interactive upgrade of the system configuration files in -.Pa /etc . -This is the only interactive process in a full system upgrade. -.Pp -In order for this command to do anything useful, the list of sets to install as -specified by the -.Va SETS -configuration variable -.Em must include -.Sq etc , -and may optionally include -.Sq xetc . -.Pp -Note that, due to defficiencies in the -.Xr etcupdate 8 -utility, this command does not work when -.Va DESTDIR -is set. -.Ss The fetch command -The fetch command gets a copy of the release sets as pointed to by the -.Va RELEASEDIR -variable into a local cache directory, or from the directory indicated by the -optional argument -.Ar releasedir . -.Pp -If -.Va RELEASEDIR -points to a local directory, the utility just creates symlinks within the cache -directory pointing to the original files. -Otherwise, if -.Va RELEASEDIR -points to a remote FTP, HTTP or SSH site, the fetch command will retrieve the -contents of the release directory into the local cache directory. -.Pp -Please note that all the commands that access distribution sets do so by looking -for such files in the cache directory -.Em even when the release directory is in a local path . -This means that, for such commands to work, you must run fetch beforehand. -.Ss The kernel command -The kernel command upgrades the kernel to a newer version. -The kernel to install is determined by the optional argument -.Ar kernel_name -if present, or otherwise from the -.Va KERNEL -variable. -The kernel is expected to be found in a -.Sq netbsd-<NAME>.gz -file in the release directory. -.Pp -The previous kernel is backed up as -.Pa <destdir>/onetbsd . -.Ss The modules command -The modules command upgrades the kernel modules to a newer version. -This operation only takes place if the sets to be installed, as specified by the -.Va SETS -variable, contains the -.Sq modules -set. -.Ss The sets command -The sets command upgrades all non-kernel, non-modules and non-configuration sets -of the system to a newer version. -In other words, this command installs sets like -.Sq base -or -.Sq tests -but explicitly skips sets of the forms -.Sq *etc -and -.Sq modules . -The presence of any -.Sq kern-* -sets in the list will cause this command to fail. -.Pp -The list of sets to be installed is determined by the optional arguments passed -to the command or, if none, from the value of the -.Va SETS -configuration variable. -.Ss The postinstall command -The postinstall command invokes the -.Xr postinstall 8 -utility to perform checks and fixes on the system after all new files have been -put in place. -.Pp -The -.Va POSTINSTALL_AUTOFIX -variable can optionally include a list of -.Xr postinstall 8 -fixes to be applied to a system unconditionally. -For example, listing -.Sq obsolete -in this variable is usually useful as this check fails often during upgrades and -is safe to auto-fix. -.Pp -Any arguments supplied to the command are passed directly to -.Xr postinstall 8 , -which comes handy in those cases where you have to manually fix a broken test. -.Sh FILES -.Bl -tag -width XXXX -.It Pa @SYSUPGRADE_ETCDIR@/sysupgrade.conf -Default configuration file. -.It Pa @SYSUPGRADE_CACHEDIR@ -Location where distribution sets are temporarily stored. -The -.Sq fetch -command writes files into this directory and the -.Sq clean -command clears its contents. -.It Pa /home/sysbuild/release/<machine> -Standard location of the releases built by the -.Xr sysbuild 1 -utility. -.El -.Sh EXAMPLES AND TROUBLESHOOTING -The most common way of executing -.Nm -is by using the -.Sq auto -command and relying in the default configuration file: -.Bd -literal -offset indent -$ sysupgrade auto -.Ed -.Pp -If you wish to track minor stable releases, you may want to do something like -this every time a new release is published: -.Bd -literal -offset indent -$ sysupgrade auto \\ - ftp://ftp.NetBSD.org/pub/NetBSD/NetBSD-6.<minor>/$(uname -m) -.Ed -.Pp -If the upgrade process fails due to an aborted FTP or HTTP connection, simply -rerun -.Nm -in -.Sq auto -mode and it will resume the download where it left off. -.Pp -If the -.Sq postinstall -step fails due to broken checks, you can manually resume that stage and complete -the upgrade by doing: -.Bd -literal -offset indent -$ sysupgrade postinstall fix <names of the failed checks> -$ sysupgrade clean -.Ed -.Pp -If you have decided to run -.Xr etcupdate 8 -by hand separately from -.Nm , -you could do: -.Bd -literal -offset indent -$ sysupgrade -o AUTOCLEAN=no -o ETCUPDATE=no auto -\&... and later, at your earliest convenience ... -$ sysupgrade etcupdate -$ sysupgrade clean -.Ed -.Sh SEE ALSO -.Xr sysbuild 1 , -.Xr sysupgrade.conf 5 , -.Xr etcupdate 8 , -.Xr postinstall 8 -.Sh AUTHORS -The -.Nm -utility was developed by -.An Julio Merino -.Aq jmmv@NetBSD.org . diff --git a/sysutils/sysupgrade/files/sysupgrade.conf.5 b/sysutils/sysupgrade/files/sysupgrade.conf.5 deleted file mode 100644 index f316d6c1a1f..00000000000 --- a/sysutils/sysupgrade/files/sysupgrade.conf.5 +++ /dev/null @@ -1,167 +0,0 @@ -.\" $NetBSD: sysupgrade.conf.5,v 1.4 2012/10/11 07:56:13 wiz Exp $ -.\" Copyright 2012 Google Inc. -.\" All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions are -.\" met: -.\" -.\" * Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" * 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. -.\" * Neither the name of Google Inc. nor the names of its contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT -.\" OWNER 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 October 10, 2012 -.Dt SYSUPGRADE.CONF 5 -.Os -.Sh NAME -.Nm sysupgrade.conf -.Nd configuration file to control NetBSD system upgrades -.Sh DESCRIPTION -Configuration files for -.Xr sysupgrade 8 -are simple shell scripts that set, or explicitly clear, a collection of known -configuration variables. -.Pp -The following configuration variables are recognized: -.Bl -tag -.It Va AUTOCLEAN -Whether to automatically delete the downloaded files or not as part of the -.Sq auto -command. -.Pp -If you set -.Va ETCUPDATE -to false, you will probably want to disable autocleaning. -This will let you run the -.Sq etcupdate -command on your own at a later stage reusing the same distribution sets used to -upgrade the system. -.Pp -Default: yes. -.It Va CACHEDIR -Path to the local directory into which distribution sets are temporarily fetched -while applying a system upgrade. -Note that all -.Nm -commands that need access to the distribution sets (pretty much all of them) -will read from this directory. -If you plan on issuing different upgrade steps at different times, this -directory should persist across the different executions. -.Pp -Default: -.Pa @SYSUPGRADE_CACHEDIR@ -.It Va DESTDIR -Path to the root of the system to be upgraded. -This is prepended to all other paths affected by -.Xr sysupgrade 8 -and can be used to perform upgrades of non-live systems or for testing -purposes. -.Pp -Default: not set (which means -.Pa / -is affected). -.It Va ETCUPDATE -Whether to run -.Xr etcupdate 8 -as part of an automated upgrade. -You may want to disable this because this is the only interactive step in the -upgrade process. -.Pp -If set to false, the -.Sq auto -subcommand will skip this step. -In this case, you are also recommended to set -.Va AUTOCLEAN -to -.Sq no -so that you are not required to redownload the distribution files just to run -.Xr etcupdate 8 -later. -.Pp -Default: yes. -.It Va KERNEL -Name of the kernel to install. -There must be a -.Sq netbsd-<KERNEL>.gz -file in the release directory matching this name. -.Pp -If this is set to the magic value -.Sq AUTO , -.Xr sysupgrade 8 -will attempt to automatically determine the name of the current kernel by using -.Xr config 1 -on -.Pa <DESTDIR>/netbsd . -If the guessing fails, an error is raised to prevent installing a mismatching -kernel. -.Pp -Default: AUTO. -.It Va POSTINSTALL_AUTOFIX -Whitespace-separated list of -.Xr postinstall 8 -checks that will be unconditionally fixed as part of an upgrade. -.Pp -It is recommended that you include -.Sq obsolete -in this list at the very least: this check often fails because it is common for -newer releases to drop existing files, and fixing it should be harmless. -Note that old shared libraries are never cleaned by this check, so existing -third-party binaries should not stop working even after auto-fixing this check. -.Pp -Default: empty. -.It Va RELEASEDIR -Location of the release directory (which must hold a -.Pa binary/sets/ -subdirectory). -This can be either a local path or a URL. -.Pp -If the location is a URL, any of the HTTP, FTP or SSH protocols are supported. -In the case of SSH, the URL takes the form: -.Sq ssh://[user[:password]@]<host>/<absolute_path> , -which is different to the syntax accepted by -.Xr scp 1 . -.Pp -Default: not set. -.It Va SETS -Whitespace-separated list of distribution sets to install. -If this is set to the magic value -.Sq AUTO , -the list of sets is determined from the files in -.Pa <DESTDIR>/etc/mtree . -.Pp -This list cannot include any -.Sq kern-* -sets; the kernel to be installed is determined by the -.Va KERNEL -variable. -.Pp -The presence of any configuration sets (such as -.Sq etc -or -.Sq xetc ) -in this list enables the etcupdate and postinstall steps in the automated -upgrade procedure. -.Pp -The presence of a modules set enables the modules step in the automated upgrade -procedure. -.Pp -Default: AUTO. -.El -.Sh SEE ALSO -.Xr sysupgrade 8 diff --git a/sysutils/sysupgrade/files/sysupgrade.sh b/sysutils/sysupgrade/files/sysupgrade.sh deleted file mode 100644 index fece40653f8..00000000000 --- a/sysutils/sysupgrade/files/sysupgrade.sh +++ /dev/null @@ -1,505 +0,0 @@ -# Copyright 2012 Google Inc. -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are -# met: -# -# * Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# * 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. -# * Neither the name of Google Inc. nor the names of its contributors -# may be used to endorse or promote products derived from this software -# without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT -# OWNER 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. - -# \file sysupgrade.sh -# Entry point and main program logic. - -shtk_import cli -shtk_import config -shtk_import list -shtk_import process - - -# List of valid configuration variables. -# -# Please remember to update sysbuild(1) if you change this list. -SYSUPGRADE_CONFIG_VARS="AUTOCLEAN CACHEDIR DESTDIR ETCUPDATE KERNEL - POSTINSTALL_AUTOFIX RELEASEDIR SETS" - - -# Directory in which to keep downloaded release files. -# -# Can be overriden for test purposes only. -: ${SYSUPGRADE_CACHEDIR:="@SYSUPGRADE_CACHEDIR@"} - - -# Paths to installed files. -# -# Can be overriden for test purposes only. -: ${SYSUPGRADE_ETCDIR:="@SYSUPGRADE_ETCDIR@"} - - -# Sets defaults for configuration variables that need a value. -# -# This function should be called before the configuration file has been loaded. -# This means that the user can undefine a required configuration variable, but -# we let him shoot himself in the foot if he so desires. -sysupgrade_set_defaults() { - # Please remember to update sysupgrade(8) if you change any default values. - shtk_config_set AUTOCLEAN "yes" - shtk_config_set CACHEDIR "${SYSUPGRADE_CACHEDIR}" - shtk_config_set ETCUPDATE "yes" - shtk_config_set KERNEL "AUTO" - shtk_config_set SETS "AUTO" -} - - -# Interprets magic configuration values. -# -# This function should be called after the configuration file has been loaded. -# It takes care of performing any required post-processing on the configuration -# variables, such as expanding the magic AUTO keyword to the actual value. -sysupgrade_auto_config() { - if [ "$(shtk_config_get_default KERNEL "")" = "AUTO" ]; then - local kernel="$(shtk_config_get_default DESTDIR "")/netbsd" - if [ -e "${kernel}" ]; then - local kernel_path="$(config -x "${kernel}" | head -n 1 \ - | cut -d \" -f 2)" - local kernel_name="${kernel_path##*/}" - [ -n "${kernel_name}" ] || shtk_cli_error "Failed to determine" \ - "kernel name; please set KERNEL explicitly" - shtk_config_set KERNEL "${kernel_name}" - else - shtk_config_unset KERNEL - fi - fi - - if [ "$(shtk_config_get_default SETS "")" = "AUTO" ]; then - local mtree="$(shtk_config_get_default DESTDIR "")/etc/mtree/" - if [ -d "${mtree}" ]; then - local all_sets="$(cd "${mtree}" && echo set.* \ - | sed -e 's,set\.,,g')" - shtk_config_set SETS "${all_sets}" - else - shtk_config_unset SETS - fi - fi -} - - -# Dumps the loaded configuration. -# -# \params ... The options and arguments to the command. -sysupgrade_config() { - local eval_auto=no - while getopts ':a' arg "${@}"; do - case "${arg}" in - a) # Evaluate automatic settings. - eval_auto=yes - ;; - - \?) - shtk_cli_usage_error "Unknown option -${OPTARG}" - ;; - esac - done - shift $((${OPTIND} - 1)) - - [ ${#} -eq 0 ] || shtk_cli_usage_error "config does not take any arguments" - - [ "${eval_auto}" = no ] || sysupgrade_auto_config - - for var in ${SYSUPGRADE_CONFIG_VARS}; do - if shtk_config_has "${var}"; then - echo "${var} = $(shtk_config_get "${var}")" - else - echo "${var} is undefined" - fi - done -} - - -# Gets the path to a file in the cache. -# -# \post The path to the file in the cache is printed on stdout. -# -# \param file The name of the file to query. -get_cached_file() { - local file="${1}"; shift - - echo "$(shtk_config_get CACHEDIR)/${file}" -} - - -# Ensures that a given distribution file exists in the cache. -# -# \param file The name of the file to query. -require_cached_file() { - local file="${1}"; shift - - local path="$(get_cached_file "${file}")" - [ -f "${path}" ] || shtk_cli_error "Cannot find ${file}; did you run" \ - "'$(shtk_cli_progname) fetch' first?" -} - - -# Extracts a set into the destdir. -# -# The set to be extracted must have been previously fetched into the cache -# directory by sysupgrade_fetch command. -# -# \param set_name Name of the set to extract, without the .tgz extension. -extract_set() { - local set_name="${1}"; shift - - require_cached_file "${set_name}.tgz" - - local destdir="$(shtk_config_get_default DESTDIR "")" - local set_tgz="$(get_cached_file "${set_name}.tgz")" - - shtk_cli_info "Extracting ${set_name} into ${destdir}/" - [ -z "${destdir}" ] || shtk_process_run mkdir -p "${destdir}" - progress -zf "${set_tgz}" tar -xp -C "${destdir}/" -f - -} - - -# Fetches the release sets into the cache directory. -# -# \param releasedir Optional override of the release directory to use. -sysupgrade_fetch() { - [ ${#} -lt 2 ] \ - || shtk_cli_usage_error "fetch takes zero or one arguments" - - [ -z "${1}" ] || shtk_config_set "RELEASEDIR" "${1}" - - local releasedir="$(shtk_config_get RELEASEDIR)" - local cachedir="$(shtk_config_get CACHEDIR)" - local fetch_files= - for set_name in $(shtk_config_get SETS); do - fetch_files="${fetch_files} binary/sets/${set_name}.tgz" - done - if shtk_config_has KERNEL; then - local kernel_name="$(shtk_config_get KERNEL)" - fetch_files="${fetch_files} binary/kernel/netbsd-${kernel_name}.gz" - fi - - case "${releasedir}" in - ftp://*|http://*) - mkdir -p "${cachedir}" - - for relative_file in ${fetch_files}; do - local local_file="${cachedir}/${relative_file##*/}" - if [ -f "${local_file}" ]; then - shtk_cli_warning "Reusing existing ${local_file}" - else - local url="${releasedir}/${relative_file}" - shtk_cli_info "Downloading ${url} into ${cachedir}" - rm -f "${local_file}" - local rflag= - [ ! -f "${local_file}.tmp" ] || rflag=-R - ftp ${rflag} -o"${local_file}.tmp" "${url}" \ - || shtk_cli_error "Failed to fetch ${url}" - mv "${local_file}.tmp" "${local_file}" - fi - done - ;; - - ssh://*) - mkdir -p "${cachedir}" - - local relative_srcs="" - for relative_file in ${fetch_files}; do - local local_file="${cachedir}/${relative_file##*/}" - if [ -f "${local_file}" ]; then - shtk_cli_warning "Reusing existing ${local_file}" - else - if [ -z "${relative_srcs}" ]; then - relative_srcs="${relative_file}" - else - relative_srcs="${relative_srcs},${relative_file}" - fi - fi - done - if [ -n "${relative_srcs}" ]; then - local host="$(echo ${releasedir} | cut -d / -f 3)" - local dir="$(echo ${releasedir} | cut -d / -f 4-)" - scp "${host}:/${dir}/{${relative_srcs}}" "${cachedir}/" - fi - ;; - - /*) - mkdir -p "${cachedir}" - - for relative_file in ${fetch_files}; do - local src="${releasedir}/${relative_file}" - shtk_cli_info "Linking local ${src} into ${cachedir}" - [ -f "${src}" ] || shtk_cli_error "Cannot open ${src}" - ln -s -f "${src}" "${cachedir}/${relative_file##*/}" \ - || shtk_cli_error "Failed to link ${src} into ${cachedir}" - done - ;; - - *) - shtk_cli_error "Don't know how to fetch from ${releasedir}; must" \ - "be an absolute path or an FTP/HTTP site" - ;; - esac -} - - -# Installs a new kernel from a set. -# -# \param kernel_name Name of the kernel set to use; optional. -sysupgrade_kernel() { - [ ${#} -lt 2 ] \ - || shtk_cli_usage_error "kernel takes zero or one arguments" - - local kernel_name - if [ -n "${1}" ]; then - kernel_name="${1}" - elif shtk_config_has KERNEL; then - kernel_name="$(shtk_config_get KERNEL)" - else - shtk_cli_info "Skipping kernel installation (KERNEL not set)" - return 0 - fi - - require_cached_file "netbsd-${kernel_name}.gz" - - local destdir="$(shtk_config_get_default DESTDIR "")" - shtk_cli_info "Upgrading kernel using ${kernel_name} in ${destdir}/" - - if gunzip -c "$(get_cached_file "netbsd-${kernel_name}.gz")" \ - >"${destdir}/nnetbsd" - then - if [ -f "${destdir}/netbsd" ]; then - shtk_cli_info "Backing up 'netbsd' kernel as 'onetbsd'" - ln -f "${destdir}/netbsd" "${destdir}/onetbsd" - fi - - mv "${destdir}/nnetbsd" "${destdir}/netbsd" - else - rm -f "${destdir}/nnetbsd" - shtk_cli_error "Failed to uncompress new kernel" - fi -} - - -# Installs new kernel modules. -sysupgrade_modules() { - [ ${#} -eq 0 ] \ - || shtk_cli_usage_error "modules does not take any arguments" - - if ! shtk_list_contains modules $(shtk_config_get SETS); then - shtk_cli_info "Skipping modules installation (modules not in SETS)" - return 0 - fi - - shtk_cli_info "Upgrading kernel modules" - - extract_set modules -} - - -# Installs new sets. -# -# \param ... Names of the sets to extract, to override SETS. -sysupgrade_sets() { - local sets= - for set_name in "${@:-$(shtk_config_get SETS)}"; do - case "${set_name}" in - *etc) ;; # Handled by etcupdate. - kern-*) - shtk_cli_error "SETS should not contain any kernel sets;" \ - "found ${set_name}" - ;; - modules) ;; # Handled by modules. - *) sets="${sets} ${set_name}" ;; - esac - done - - for set_name in ${sets}; do - require_cached_file "${set_name}.tgz" - done - - shtk_cli_info "Upgrading base system" - for set_name in ${sets}; do - extract_set "${set_name}" - done -} - - -# Runs etcupdate to install new configuration files. -sysupgrade_etcupdate() { - [ ${#} -eq 0 ] || shtk_cli_usage_error "etcupdate does not take any" \ - "arguments" - - if shtk_config_has DESTDIR; then - shtk_cli_info "Skipping etcupdate (DESTDIR upgrades not supported)" - return 0 - fi - - local sets="$(shtk_list_filter '*etc' $(shtk_config_get SETS))" - if [ -z "${sets}" ]; then - shtk_cli_info "Skipping etcupdate (no etc sets in SETS)" - return 0 - fi - if ! shtk_list_contains etc ${sets}; then - shtk_cli_info "Skipping etcupdate (required etc not in SETS)" - return 0 - fi - - local sflags= - for set_name in ${sets}; do - require_cached_file "${set_name}.tgz" - sflags="${sflags} -s$(get_cached_file "${set_name}.tgz")" - done - - shtk_cli_info "Upgrading /etc interactively" - etcupdate -a -l ${sflags} -} - - -# Runs postinstall to validate the updated system. -# -# \param ... Arguments to pass to postinstall(8). -sysupgrade_postinstall() { - local sets= - local sets="$(shtk_list_filter '*etc' $(shtk_config_get SETS))" - if [ -z "${sets}" ]; then - shtk_cli_info "Skipping postinstall (no etc sets in SETS)" - return 0 - fi - if ! shtk_list_contains etc ${sets}; then - shtk_cli_info "Skipping postinstall (required etc not in SETS)" - return 0 - fi - - local sflags= - for set_name in ${sets}; do - require_cached_file "${set_name}.tgz" - sflags="${sflags} -s$(get_cached_file "${set_name}.tgz")" - done - - shtk_cli_info "Performing postinstall checks" - local destdir="$(shtk_config_get_default DESTDIR "")" - if shtk_config_has POSTINSTALL_AUTOFIX; then - postinstall "-d${destdir}/" ${sflags} fix \ - $(shtk_config_get POSTINSTALL_AUTOFIX) - fi - postinstall "-d${destdir}/" ${sflags} "${@:-check}" \ - || shtk_cli_error "Some postinstall(8) checks have failed" -} - - -# Cleans up the cache directory. -sysupgrade_clean() { - [ ${#} -eq 0 ] || shtk_cli_usage_error "clean does not take any arguments" - - shtk_cli_info "Cleaning downloaded files" - rm -f "$(shtk_config_get CACHEDIR)"/*.*gz* -} - - -# Automated upgrade procedure. -# -# This is just a convenience mechanism to execute all the different steps of the -# upgrade. -# -# \param releasedir Optional override of the release directory to use. -sysupgrade_auto() { - [ ${#} -lt 2 ] \ - || shtk_cli_usage_error "auto takes zero or one arguments" - - [ -z "${1}" ] || shtk_config_set "RELEASEDIR" "${1}" - - local stages= - stages="fetch modules kernel sets" - shtk_config_get_bool "ETCUPDATE" && stages="${stages} etcupdate" - stages="${stages} postinstall" - shtk_config_get_bool "AUTOCLEAN" && stages="${stages} clean" - - shtk_cli_info "Starting auto-update with stages: ${stages}" - for stage in ${stages}; do - sysupgrade_${stage} - done - - shtk_config_get_bool "AUTOCLEAN" || shtk_cli_info "Distribution sets not" \ - "deleted; further $(shtk_cli_progname) commands will reuse them" -} - - -# Entry point to the program. -# -# \param ... Command-line arguments to be processed. -# -# \return An exit code to be returned to the user. -sysupgrade_main() { - local config_file="${SYSUPGRADE_ETCDIR}/sysupgrade.conf" - - shtk_config_init ${SYSUPGRADE_CONFIG_VARS} - - while getopts ':c:d:o:' arg "${@}"; do - case "${arg}" in - c) # Path to the configuration file. - config_file="${OPTARG}" - ;; - - d) # Path to the destdir. - shtk_config_set DESTDIR "${OPTARG}" - ;; - - o) # Override for a particular configuration variable. - shtk_config_override "${OPTARG}" - ;; - - \?) - shtk_cli_usage_error "Unknown option -${OPTARG}" - ;; - esac - done - shift $((${OPTIND} - 1)) - - [ ${#} -ge 1 ] || shtk_cli_usage_error "No command specified" - - local exit_code=0 - - local command="${1}"; shift - case "${command}" in - auto|clean|etcupdate|fetch|kernel|modules|sets|postinstall) - sysupgrade_set_defaults - shtk_config_load "${config_file}" - sysupgrade_auto_config - "sysupgrade_$(echo "${command}" | tr - _)" "${@}" \ - || exit_code="${?}" - ;; - - config) - sysupgrade_set_defaults - shtk_config_load "${config_file}" - "sysupgrade_$(echo "${command}" | tr - _)" "${@}" \ - || exit_code="${?}" - ;; - - *) - shtk_cli_usage_error "Unknown command ${command}" - ;; - esac - - return "${exit_code}" -} diff --git a/sysutils/sysupgrade/files/sysupgrade_test.sh b/sysutils/sysupgrade/files/sysupgrade_test.sh deleted file mode 100644 index e87f315abcc..00000000000 --- a/sysutils/sysupgrade/files/sysupgrade_test.sh +++ /dev/null @@ -1,1194 +0,0 @@ -#! @ATF_SH@ -# Copyright 2012 Google Inc. -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are -# met: -# -# * Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# * 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. -# * Neither the name of Google Inc. nor the names of its contributors -# may be used to endorse or promote products derived from this software -# without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT -# OWNER 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. - - -# Creates a fake program that records its invocations for later processing. -# -# The fake program, when invoked, will append its arguments to a commands.log -# file in the test case's work directory. -# -# \param binary The path to the program to create. -# \param delegate If set to 'yes', execute the real program afterwards. -create_mock_binary() { - local binary="${1}"; shift - local delegate=no - [ ${#} -eq 0 ] || { delegate="${1}"; shift; } - - cat >"${binary}" <<EOF -#! /bin/sh - -logfile="${HOME}/commands.log" -echo "Command: \${0##*/}" >>"\${logfile}" -echo "Directory: \$(pwd)" >>"\${logfile}" -for arg in "\${@}"; do - echo "Arg: \${arg}" >>"\${logfile}" -done - echo >>"\${logfile}" -EOF - - if [ "${delegate}" = yes ]; then - cat >>"${binary}" <<EOF -PATH="${PATH}" -exec "\${0##*/}" "\${@}" -EOF - fi - - chmod +x "${binary}" -} - - -# Generates a NetBSD release dir with fake sets and kernels. -# -# Each generated set contains a single file named '<set>.cookie'. The kernels -# contain just an hardcoded string within them that can later be validated to -# ensure the right set was unpacked. -# -# \param releasedir Path to the release directory. -# \param ... Names of the sets to create under releasedir/binary/sets/ and the -# kernels to create under releasedir/binary/kernel/. No extensions should -# be given. -create_mock_release() { - local releasedir="${1}"; shift - - mkdir -p "${releasedir}/binary/kernel" - mkdir -p "${releasedir}/binary/sets" - - for set_name in "${@}"; do - case "${set_name}" in - netbsd-*) - echo "File from ${set_name}" \ - >"${releasedir}/binary/kernel/${set_name}" - gzip "${releasedir}/binary/kernel/${set_name}" - ;; - - *) - echo "File from ${set_name}" >"${set_name}.cookie" - tar czf "${releasedir}/binary/sets/${set_name}.tgz" \ - "${set_name}.cookie" - rm "${set_name}.cookie" - ;; - esac - done -} - - -atf_test_case config__builtins -config__builtins_body() { - cat >expout <<EOF -AUTOCLEAN = yes -CACHEDIR = @SYSUPGRADE_CACHEDIR@ -DESTDIR is undefined -ETCUPDATE = yes -KERNEL = AUTO -POSTINSTALL_AUTOFIX is undefined -RELEASEDIR is undefined -SETS = AUTO -EOF - atf_check -o file:expout sysupgrade -c /dev/null config -} - - -atf_test_case config__default_file -config__default_file_body() { - mkdir system - export SYSUPGRADE_ETCDIR="$(pwd)/system" - - echo "KERNEL=abc" >"system/sysupgrade.conf" - atf_check -o match:"KERNEL = abc" sysupgrade config -} - - -atf_test_case config__explicit_file -config__explicit_file_body() { - mkdir system - export SYSUPGRADE_ETCDIR="$(pwd)/system" - - echo "KERNEL=abc" >"system/sysupgrade.conf" - echo "SETS='d e'" >"my-file.conf" - atf_check -o not-match:"KERNEL = abc" -o match:"SETS = d e" \ - sysupgrade -c ./my-file.conf config -} - - -atf_test_case config__auto__kernel__found -config__auto__kernel__found_body() { - cat >config <<EOF -#! /bin/sh -if [ "\${1}" != "-x" ]; then - echo "-x not passed to config" - exit 1 -fi -if [ "\${2}" != "$(pwd)/root/netbsd" ]; then - echo "Invalid path passed to config: \${2}" - exit 1 -fi - -cat "\${2}" -EOF - chmod +x config - PATH="$(pwd):${PATH}" - - mkdir root - cat >root/netbsd <<EOF -### START CONFIG FILE "foo/bar/ABCDE" -these are some contents -### END CONFIG FILE "foo/bar/ABCDE" -EOF - atf_check -o match:"KERNEL = ABCDE" \ - sysupgrade -c /dev/null \ - -o DESTDIR="$(pwd)/root" -o KERNEL="AUTO" config -a -} - - -atf_test_case config__auto__kernel__not_found -config__auto__kernel__not_found_body() { - - atf_check -o match:"KERNEL is undefined" \ - sysupgrade -c /dev/null \ - -o DESTDIR="$(pwd)/root" -o KERNEL="AUTO" config -a -} - - -atf_test_case config__auto__kernel__fail -config__auto__kernel__fail_body() { - cat >config <<EOF -#! /bin/sh -exit 1 -EOF - chmod +x config - PATH="$(pwd):${PATH}" - - mkdir root - touch root/netbsd - - cat >experr <<EOF -sysupgrade: E: Failed to determine kernel name; please set KERNEL explicitly -EOF - atf_check -s exit:1 -e file:experr sysupgrade -c /dev/null \ - -o DESTDIR="$(pwd)/root" -o KERNEL="AUTO" config -a -} - - -atf_test_case config__auto__sets__found -config__auto__sets__found_body() { - mkdir -p root/etc/mtree - touch root/etc/mtree/set.first - touch root/etc/mtree/set.second - touch root/etc/mtree/set.third - atf_check -o match:"SETS = first second third" \ - sysupgrade -c /dev/null \ - -o DESTDIR="$(pwd)/root" -o SETS="AUTO" config -a -} - - -atf_test_case config__auto__sets__not_found -config__auto__sets__not_found_body() { - - atf_check -o match:"SETS is undefined" \ - sysupgrade -c /dev/null \ - -o DESTDIR="$(pwd)/root" -o SETS="AUTO" config -a -} - - -atf_test_case config__not_found -config__not_found_body() { - mkdir .sysupgrade - mkdir system - export SYSUPGRADE_ETCDIR="$(pwd)/system" - - cat >experr <<EOF -sysupgrade: E: Configuration file foobar does not exist -EOF - atf_check -s exit:1 -o empty -e file:experr sysupgrade -c foobar config -} - - -atf_test_case config__overrides -config__overrides_body() { - cat >custom.conf <<EOF -CACHEDIR=/tmp/cache -KERNEL=foo -EOF - - cat >expout <<EOF -AUTOCLEAN = yes -CACHEDIR = /tmp/cache2 -DESTDIR = /tmp/destdir -ETCUPDATE = yes -KERNEL is undefined -POSTINSTALL_AUTOFIX is undefined -RELEASEDIR is undefined -SETS = AUTO -EOF - atf_check -o file:expout sysupgrade -c custom.conf -o KERNEL= \ - -o CACHEDIR=/tmp/cache2 -o DESTDIR=/tmp/destdir config -} - - -atf_test_case config__too_many_args -config__too_many_args_body() { - cat >experr <<EOF -sysupgrade: E: config does not take any arguments -Type 'man sysupgrade' for help -EOF - atf_check -s exit:1 -e file:experr sysupgrade -c /dev/null config foo -} - - -atf_test_case fetch__ftp -fetch__ftp_body() { - # TODO(jmmv): It would be nice if this test used an actual FTP server, just - # like the http test below. Unfortunately, the ftpd shipped by NetBSD does - # not provide an easy mechanism to run it as non-root (e.g. no easy way to - # select on which port to serve). - create_mock_binary ftp -cat >>ftp <<EOF -for arg in "\${@}"; do - case "\${arg}" in - -o*) touch \$(echo "\${arg}" | sed -e s,^-o,,) ;; - esac -done -EOF - PATH="$(pwd):${PATH}" - - SYSUPGRADE_CACHEDIR="$(pwd)/a/b/c"; export SYSUPGRADE_CACHEDIR - mkdir -p a/b/c - touch a/b/c/foo.tgz.tmp - atf_check -o ignore -e ignore sysupgrade -c /dev/null \ - -o RELEASEDIR="ftp://example.net/pub/NetBSD/X.Y/a-machine" \ - -o KERNEL=GENERIC -o SETS="a foo" fetch - - cat >expout <<EOF -Command: ftp -Directory: $(pwd) -Arg: -o$(pwd)/a/b/c/a.tgz.tmp -Arg: ftp://example.net/pub/NetBSD/X.Y/a-machine/binary/sets/a.tgz - -Command: ftp -Directory: $(pwd) -Arg: -R -Arg: -o$(pwd)/a/b/c/foo.tgz.tmp -Arg: ftp://example.net/pub/NetBSD/X.Y/a-machine/binary/sets/foo.tgz - -Command: ftp -Directory: $(pwd) -Arg: -o$(pwd)/a/b/c/netbsd-GENERIC.gz.tmp -Arg: ftp://example.net/pub/NetBSD/X.Y/a-machine/binary/kernel/netbsd-GENERIC.gz - -EOF - atf_check -o file:expout cat commands.log -} - - -atf_test_case fetch__http cleanup -fetch__http_head() { - atf_set "require.progs" "/usr/libexec/httpd" -} -fetch__http_body() { - create_mock_release www/a-machine base comp etc netbsd-GENERIC tests text - - if ! /usr/libexec/httpd -b -s -d -I 30401 -P "$(pwd)/httpd.pid" \ - "$(pwd)/www" >httpd.out 2>httpd.err; then - if grep 'unknown option -- P' httpd.err >/dev/null; then - atf_skip "httpd does not support -P" - else - sed 's,^,httpd.out:,' httpd.out - sed 's,^,httpd.err:,' httpd.err - atf_fail "Failed to start test HTTP server" - fi - fi - - SYSUPGRADE_CACHEDIR="$(pwd)/cache"; export SYSUPGRADE_CACHEDIR - atf_check -o ignore -e ignore sysupgrade -c /dev/null \ - -o RELEASEDIR="http://localhost:30401/a-machine" \ - -o KERNEL=GENERIC -o SETS="base etc text" fetch - - for set_name in base.tgz etc.tgz netbsd-GENERIC.gz text.tgz; do - [ -e "cache/${set_name}" ] || atf_fail "${set_name} not fetched" - done - for set_name in comp.tgz tests.tgz; do - [ ! -e "cache/${set_name}" ] || atf_fail "${set_name} fetched" - done - - kill -9 "$(cat httpd.pid)" - rm -f httpd.pid -} -fetch__http_cleanup() { - if [ -f httpd.pid ]; then - echo "Killing stale HTTP server" - kill -9 "$(cat httpd.pid)" - fi -} - - -atf_test_case fetch__ssh__one_set -fetch__ssh__one_set_body() { - create_mock_binary scp - PATH="$(pwd):${PATH}" - - SYSUPGRADE_CACHEDIR="$(pwd)/a/b/c"; export SYSUPGRADE_CACHEDIR - mkdir -p a/b/c - atf_check -o ignore -e ignore sysupgrade -c /dev/null \ - -o RELEASEDIR="ssh://example.net/home/sysbuild/release/machine" \ - -o KERNEL="" -o SETS="one" fetch - - cat >expout <<EOF -Command: scp -Directory: $(pwd) -Arg: example.net:/home/sysbuild/release/machine/{binary/sets/one.tgz} -Arg: $(pwd)/a/b/c/ - -EOF - atf_check -o file:expout cat commands.log -} - - -atf_test_case fetch__ssh__many_sets -fetch__ssh__many_sets_body() { - create_mock_binary scp - PATH="$(pwd):${PATH}" - - SYSUPGRADE_CACHEDIR="$(pwd)/a/b/c"; export SYSUPGRADE_CACHEDIR - mkdir -p a/b/c - atf_check -o ignore -e ignore sysupgrade -c /dev/null \ - -o RELEASEDIR="ssh://example.net/home/sysbuild/release/machine" \ - -o KERNEL=GENERIC -o SETS="one two" fetch - - cat >expout <<EOF -Command: scp -Directory: $(pwd) -Arg: example.net:/home/sysbuild/release/machine/{binary/sets/one.tgz,binary/sets/two.tgz,binary/kernel/netbsd-GENERIC.gz} -Arg: $(pwd)/a/b/c/ - -EOF - atf_check -o file:expout cat commands.log -} - - -atf_test_case fetch__ssh__already_exist -fetch__ssh__already_exist_body() { - create_mock_binary scp - PATH="$(pwd):${PATH}" - - SYSUPGRADE_CACHEDIR="$(pwd)/a/b/c"; export SYSUPGRADE_CACHEDIR - mkdir -p a/b/c - touch a/b/c/netbsd-GENERIC.gz - touch a/b/c/one.tgz - atf_check -o ignore -e ignore sysupgrade -c /dev/null \ - -o RELEASEDIR="ssh://example.net/home/sysbuild/release/machine" \ - -o KERNEL=GENERIC -o SETS="one" fetch - - [ ! -f commands.log ] || atf_fail "scp was invoked" -} - - -atf_test_case fetch__local -fetch__local_body() { - create_mock_release release base comp etc netbsd-GENERIC tests text - - SYSUPGRADE_CACHEDIR="$(pwd)/cache"; export SYSUPGRADE_CACHEDIR - atf_check -o ignore -e ignore sysupgrade -c /dev/null \ - -o KERNEL=GENERIC -o RELEASEDIR="$(pwd)/release" \ - -o SETS="base etc text" fetch - - for set_name in base.tgz etc.tgz netbsd-GENERIC.gz text.tgz; do - [ -e "cache/${set_name}" ] || atf_fail "${set_name} not fetched" - done - for set_name in comp.tgz tests.tgz; do - [ ! -e "cache/${set_name}" ] || atf_fail "${set_name} fetched" - done -} - - -atf_test_case fetch__no_kernel -fetch__no_kernel_body() { - create_mock_release release base comp netbsd-GENERIC - - SYSUPGRADE_CACHEDIR="$(pwd)/cache"; export SYSUPGRADE_CACHEDIR - atf_check -o ignore -e ignore sysupgrade -c /dev/null \ - -o KERNEL= -o RELEASEDIR="$(pwd)/release" -o SETS="base comp" fetch - - for set_name in base comp; do - [ -e "cache/${set_name}.tgz" ] || atf_fail "${set_name} not fetched" - done - [ ! -e "cache/netbsd-GENERIC.gz" ] || atf_fail "netbsd-GENERIC fetched" -} - - -atf_test_case fetch__unknown -fetch__unknown_body() { - cat >experr <<EOF -sysupgrade: E: Don't know how to fetch from ./release; must be an absolute path or an FTP/HTTP site -EOF - - SYSUPGRADE_CACHEDIR="$(pwd)/cache"; export SYSUPGRADE_CACHEDIR - atf_check -s exit:1 -e file:experr sysupgrade -c /dev/null \ - -o RELEASEDIR="./release" -o SETS="base etc text" fetch - [ ! -d cache ] || atf_fail "cache directory created even during errors" -} - - -atf_test_case fetch__explicit -fetch__explicit_body() { - create_mock_release release base - - SYSUPGRADE_CACHEDIR="$(pwd)/cache"; export SYSUPGRADE_CACHEDIR - atf_check -o ignore -e ignore sysupgrade -c /dev/null \ - -o RELEASEDIR="$(pwd)/foo" -o KERNEL= -o SETS=base \ - fetch "$(pwd)/release" - - [ -e "cache/base.tgz" ] || atf_fail "base not fetched" -} - - -atf_test_case fetch__too_many_args -fetch__too_many_args_body() { - cat >experr <<EOF -sysupgrade: E: fetch takes zero or one arguments -Type 'man sysupgrade' for help -EOF - atf_check -s exit:1 -e file:experr sysupgrade -c /dev/null fetch foo bar -} - - -atf_test_case kernel__skip -kernel__skip_body() { - cat >experr <<EOF -sysupgrade: I: Skipping kernel installation (KERNEL not set) -EOF - atf_check -s exit:0 -e file:experr sysupgrade -c /dev/null -o KERNEL= kernel -} - - -atf_test_case kernel__from_config -kernel__from_config_body() { - mkdir root - echo "my old kernel" >root/netbsd - - create_mock_release release netbsd-FOOBAR - SYSUPGRADE_CACHEDIR="$(pwd)/release/binary/kernel" - export SYSUPGRADE_CACHEDIR - - atf_check -s exit:0 \ - -e match:"Upgrading kernel using FOOBAR in $(pwd)/root/" \ - -e match:"Backing up" \ - sysupgrade -c /dev/null \ - -o DESTDIR="$(pwd)/root" -o KERNEL=FOOBAR kernel - - atf_check -o match:"File from netbsd-FOOBAR" cat root/netbsd - atf_check -o match:"my old kernel" cat root/onetbsd -} - - -atf_test_case kernel__from_arg -kernel__from_arg_body() { - mkdir root - echo "my old kernel" >root/netbsd - - create_mock_release release netbsd-FOOBAR netbsd-OTHER - SYSUPGRADE_CACHEDIR="$(pwd)/release/binary/kernel" - export SYSUPGRADE_CACHEDIR - - atf_check -s exit:0 \ - -e match:"Upgrading kernel using OTHER in $(pwd)/root/" \ - -e match:"Backing up" \ - sysupgrade -c /dev/null \ - -o DESTDIR="$(pwd)/root" -o KERNEL=FOOBAR kernel OTHER - - atf_check -o match:"File from netbsd-OTHER" cat root/netbsd - atf_check -o match:"my old kernel" cat root/onetbsd -} - - -atf_test_case kernel__override_backup -kernel__override_backup_body() { - mkdir root - echo "my old kernel" >root/netbsd - echo "my older kernel" >root/onetbsd - - create_mock_release release netbsd-FOOBAR - SYSUPGRADE_CACHEDIR="$(pwd)/release/binary/kernel" - export SYSUPGRADE_CACHEDIR - - atf_check -s exit:0 \ - -e match:"Upgrading kernel using FOOBAR in $(pwd)/root/" \ - -e match:"Backing up" \ - sysupgrade -c /dev/null \ - -o DESTDIR="$(pwd)/root" -o KERNEL=FOOBAR kernel - - atf_check -o match:"File from netbsd-FOOBAR" cat root/netbsd - atf_check -o match:"my old kernel" cat root/onetbsd -} - - -atf_test_case kernel__no_backup -kernel__no_backup_body() { - mkdir root - - create_mock_release release netbsd-FOOBAR - SYSUPGRADE_CACHEDIR="$(pwd)/release/binary/kernel" - export SYSUPGRADE_CACHEDIR - - atf_check -s exit:0 -e not-match:"Backing up" sysupgrade -c /dev/null \ - -o DESTDIR="$(pwd)/root" -o KERNEL=FOOBAR kernel - - atf_check -o match:"File from netbsd-FOOBAR" cat root/netbsd - [ ! -f root/onetbsd ] || atf_fail "onetbsd backup created, but not expected" -} - - -atf_test_case kernel__missing_set -kernel__missing_set_body() { - mkdir root - echo "my old kernel" >root/netbsd - - SYSUPGRADE_CACHEDIR="$(pwd)"; export SYSUPGRADE_CACHEDIR - - cat >experr <<EOF -sysupgrade: E: Cannot find netbsd-GENERIC.gz; did you run 'sysupgrade fetch' first? -EOF - atf_check -s exit:1 -e file:experr sysupgrade -c /dev/null \ - -o DESTDIR="$(pwd)/root" -o KERNEL=GENERIC kernel - - atf_check -o match:"my old kernel" cat root/netbsd -} - - -atf_test_case kernel__bad_file -kernel__bad_file_body() { - mkdir root - echo "my old kernel" >root/netbsd - - echo "invalid gzip file" >netbsd-FOOBAR.gz - SYSUPGRADE_CACHEDIR="$(pwd)"; export SYSUPGRADE_CACHEDIR - - atf_check -s exit:1 \ - -e match:"Upgrading kernel using FOOBAR in $(pwd)/root/" \ - -e match:"Failed to uncompress new kernel" \ - sysupgrade -c /dev/null \ - -o DESTDIR="$(pwd)/root" -o KERNEL=FOOBAR kernel - - atf_check -o match:"my old kernel" cat root/netbsd - [ ! -f root/onetbsd ] || atf_fail "onetbsd backup created, but not expected" -} - - -atf_test_case kernel__too_many_args -kernel__too_many_args_body() { - cat >experr <<EOF -sysupgrade: E: kernel takes zero or one arguments -Type 'man sysupgrade' for help -EOF - atf_check -s exit:1 -e file:experr sysupgrade -c /dev/null kernel A B -} - - -atf_test_case modules__skip -modules__skip_body() { - cat >experr <<EOF -sysupgrade: I: Skipping modules installation (modules not in SETS) -EOF - atf_check -s exit:0 -e file:experr sysupgrade -c /dev/null \ - -o SETS="base comp modules2" modules -} - - -atf_test_case modules__install -modules__install_body() { - create_mock_release release base modules - SYSUPGRADE_CACHEDIR="$(pwd)/release/binary/sets"; export SYSUPGRADE_CACHEDIR - - atf_check -s exit:0 -e match:"Upgrading kernel modules" \ - sysupgrade -c /dev/null -o DESTDIR="$(pwd)/root" \ - -o SETS="base modules tests" modules - - [ -f root/modules.cookie ] || atf_fail "modules not extracted" - [ ! -f root/base.cookie ] || atf_fail "base should not have been extracted" -} - - -atf_test_case modules__too_many_args -modules__too_many_args_body() { - cat >experr <<EOF -sysupgrade: E: modules does not take any arguments -Type 'man sysupgrade' for help -EOF - atf_check -s exit:1 -e file:experr sysupgrade -c /dev/null modules A -} - - -atf_test_case sets__from_config -sets__from_config_body() { - create_mock_release release base etc comp - SYSUPGRADE_CACHEDIR="$(pwd)/release/binary/sets"; export SYSUPGRADE_CACHEDIR - - expected_sets="base comp" - unexpected_sets="etc modules xetc" - - atf_check -s exit:0 -e ignore sysupgrade -c /dev/null \ - -o DESTDIR="$(pwd)/root" \ - -o SETS="${expected_sets} ${unexpected_sets}" \ - sets - - for set_name in ${expected_sets}; do - [ -f "root/${set_name}.cookie" ] \ - || atf_fail "Expected set ${set_name} not extracted" - done - - for set_name in ${unexpected_sets}; do - [ ! -f "root/${set_name}.cookie" ] \ - || atf_fail "Unexpected set ${set_name} extracted" - done -} - - -atf_test_case sets__from_args -sets__from_args_body() { - create_mock_release release base etc comp - SYSUPGRADE_CACHEDIR="$(pwd)/release/binary/sets"; export SYSUPGRADE_CACHEDIR - - expected_sets="base comp" - unexpected_sets="etc modules xetc" - - atf_check -s exit:0 -e ignore sysupgrade -c /dev/null \ - -o DESTDIR="$(pwd)/root" -o SETS="foo bar baz" \ - sets ${expected_sets} ${unexpected_sets} - - for set_name in ${expected_sets}; do - [ -f "root/${set_name}.cookie" ] \ - || atf_fail "Expected set ${set_name} not extracted" - done - - for set_name in ${unexpected_sets}; do - [ ! -f "root/${set_name}.cookie" ] \ - || atf_fail "Unexpected set ${set_name} extracted" - done -} - - -atf_test_case sets__invalid_kern -sets__invalid_kern_body() { - cat >experr <<EOF -sysupgrade: E: SETS should not contain any kernel sets; found kern-FOO -EOF - atf_check -s exit:1 -e file:experr sysupgrade -c /dev/null \ - -o DESTDIR="$(pwd)/root" -o SETS="foo kern-FOO baz" sets -} - - -atf_test_case etcupdate__skip__none -etcupdate__skip__none_body() { - cat >experr <<EOF -sysupgrade: I: Skipping etcupdate (no etc sets in SETS) -EOF - atf_check -s exit:0 -e file:experr sysupgrade -c /dev/null \ - -o SETS="base comp etcfoo" etcupdate -} - - -atf_test_case etcupdate__skip__no_etc -etcupdate__skip__no_etc_body() { - cat >experr <<EOF -sysupgrade: I: Skipping etcupdate (required etc not in SETS) -EOF - atf_check -s exit:0 -e file:experr sysupgrade -c /dev/null \ - -o SETS="base xetc xfonts" etcupdate -} - - -atf_test_case etcupdate__skip__destdir -etcupdate__skip__destdir_body() { - cat >experr <<EOF -sysupgrade: I: Skipping etcupdate (DESTDIR upgrades not supported) -EOF - atf_check -s exit:0 -e file:experr sysupgrade -c /dev/null \ - -o DESTDIR="$(pwd)" -o SETS="etc" etcupdate -} - - -atf_test_case etcupdate__some_etcs -etcupdate__some_etcs_body() { - create_mock_binary etcupdate - PATH="$(pwd):${PATH}" - - create_mock_release release base etc comp xbase xetc - SYSUPGRADE_CACHEDIR="$(pwd)/release/binary/sets"; export SYSUPGRADE_CACHEDIR - - atf_check -s exit:0 -o ignore -e ignore sysupgrade -c /dev/null \ - -o RELEASEDIR="$(pwd)/release" \ - -o SETS="base etc comp xbase xetc" etcupdate - - cat >expout <<EOF -Command: etcupdate -Directory: $(pwd) -Arg: -a -Arg: -l -Arg: -s$(pwd)/release/binary/sets/etc.tgz -Arg: -s$(pwd)/release/binary/sets/xetc.tgz - -EOF - atf_check -o file:expout cat commands.log -} - - -atf_test_case etcupdate__missing_etc -etcupdate__missing_etc_body() { - SYSUPGRADE_CACHEDIR="$(pwd)"; export SYSUPGRADE_CACHEDIR - - cat >experr <<EOF -sysupgrade: E: Cannot find etc.tgz; did you run 'sysupgrade fetch' first? -EOF - atf_check -s exit:1 -e file:experr sysupgrade -c /dev/null \ - -o RELEASEDIR="$(pwd)/missing" -o SETS="etc" etcupdate -} - - -atf_test_case etcupdate__too_many_args -etcupdate__too_many_args_body() { - cat >experr <<EOF -sysupgrade: E: etcupdate does not take any arguments -Type 'man sysupgrade' for help -EOF - atf_check -s exit:1 -e file:experr sysupgrade -c /dev/null etcupdate foo -} - - -atf_test_case postinstall__skip__none -postinstall__skip__none_body() { - cat >experr <<EOF -sysupgrade: I: Skipping postinstall (no etc sets in SETS) -EOF - atf_check -s exit:0 -e file:experr sysupgrade -c /dev/null \ - -o SETS="base comp etcfoo" postinstall -} - - -atf_test_case postinstall__skip__no_etc -postinstall__skip__no_etc_body() { - cat >experr <<EOF -sysupgrade: I: Skipping postinstall (required etc not in SETS) -EOF - atf_check -s exit:0 -e file:experr sysupgrade -c /dev/null \ - -o SETS="base xetc xfonts" postinstall -} - - -atf_test_case postinstall__some_etcs -postinstall__some_etcs_body() { - create_mock_binary postinstall - PATH="$(pwd):${PATH}" - - create_mock_release release base etc comp xbase xetc - SYSUPGRADE_CACHEDIR="$(pwd)/release/binary/sets"; export SYSUPGRADE_CACHEDIR - - atf_check -s exit:0 -o ignore -e ignore sysupgrade -c /dev/null \ - -o RELEASEDIR="$(pwd)/release" \ - -o SETS="base etc comp xbase xetc" postinstall - - cat >expout <<EOF -Command: postinstall -Directory: $(pwd) -Arg: -d/ -Arg: -s$(pwd)/release/binary/sets/etc.tgz -Arg: -s$(pwd)/release/binary/sets/xetc.tgz -Arg: check - -EOF - atf_check -o file:expout cat commands.log -} - - -atf_test_case postinstall__destdir -postinstall__destdir_body() { - create_mock_binary postinstall - PATH="$(pwd):${PATH}" - - create_mock_release release base etc - SYSUPGRADE_CACHEDIR="$(pwd)/release/binary/sets"; export SYSUPGRADE_CACHEDIR - - atf_check -s exit:0 -o ignore -e ignore sysupgrade -c /dev/null \ - -o DESTDIR="$(pwd)/root" \ - -o RELEASEDIR="$(pwd)/release" \ - -o SETS="base etc" postinstall - - cat >expout <<EOF -Command: postinstall -Directory: $(pwd) -Arg: -d$(pwd)/root/ -Arg: -s$(pwd)/release/binary/sets/etc.tgz -Arg: check - -EOF - atf_check -o file:expout cat commands.log -} - - -atf_test_case postinstall__autofix -postinstall__autofix_body() { - create_mock_binary postinstall - PATH="$(pwd):${PATH}" - - create_mock_release release etc - SYSUPGRADE_CACHEDIR="$(pwd)/release/binary/sets"; export SYSUPGRADE_CACHEDIR - - atf_check -s exit:0 -o ignore -e ignore sysupgrade -c /dev/null \ - -o POSTINSTALL_AUTOFIX="first second" \ - -o RELEASEDIR="$(pwd)/release" \ - -o SETS="etc" postinstall - - cat >expout <<EOF -Command: postinstall -Directory: $(pwd) -Arg: -d/ -Arg: -s$(pwd)/release/binary/sets/etc.tgz -Arg: fix -Arg: first -Arg: second - -Command: postinstall -Directory: $(pwd) -Arg: -d/ -Arg: -s$(pwd)/release/binary/sets/etc.tgz -Arg: check - -EOF - atf_check -o file:expout cat commands.log -} - - -atf_test_case postinstall__missing_etc -postinstall__missing_etc_body() { - SYSUPGRADE_CACHEDIR="$(pwd)"; export SYSUPGRADE_CACHEDIR - - cat >experr <<EOF -sysupgrade: E: Cannot find etc.tgz; did you run 'sysupgrade fetch' first? -EOF - atf_check -s exit:1 -e file:experr sysupgrade -c /dev/null \ - -o RELEASEDIR="$(pwd)/missing" -o SETS="etc" postinstall -} - - -atf_test_case postinstall__explicit_args -postinstall__explicit_args_body() { - create_mock_binary postinstall - PATH="$(pwd):${PATH}" - - create_mock_release release base etc - SYSUPGRADE_CACHEDIR="$(pwd)/release/binary/sets"; export SYSUPGRADE_CACHEDIR - - atf_check -s exit:0 -o ignore -e ignore sysupgrade -c /dev/null \ - -o RELEASEDIR="$(pwd)/release" -o SETS="base etc" postinstall fix a b c - - cat >expout <<EOF -Command: postinstall -Directory: $(pwd) -Arg: -d/ -Arg: -s$(pwd)/release/binary/sets/etc.tgz -Arg: fix -Arg: a -Arg: b -Arg: c - -EOF - atf_check -o file:expout cat commands.log -} - - -atf_test_case clean__nothing -clean__nothing_body() { - SYSUPGRADE_CACHEDIR="$(pwd)/cache"; export SYSUPGRADE_CACHEDIR - mkdir "${SYSUPGRADE_CACHEDIR}" - atf_check -e match:"Cleaning downloaded files" sysupgrade -c /dev/null clean - [ -d cache ] || atf_fail "Cache directory should not have been deleted" -} - - -atf_test_case clean__only_zipped -clean__only_zipped_body() { - SYSUPGRADE_CACHEDIR="$(pwd)/cache"; export SYSUPGRADE_CACHEDIR - mkdir "${SYSUPGRADE_CACHEDIR}" - touch cache/foo.tgz - touch cache/foo.tgz.tmp - touch cache/bar.gz - touch cache/bar.gz.tmp - atf_check -e match:"Cleaning downloaded files" sysupgrade -c /dev/null clean - [ ! -f cache/foo.tgz ] || atf_fail "tgz not deleted" - [ ! -f cache/foo.tgz.tmp ] || atf_fail "Temporary tgz not deleted" - [ ! -f cache/bar.gz ] || atf_fail "gz not deleted" - [ ! -f cache/bar.gz.tmp ] || atf_fail "Temporary gz not deleted" - [ -d cache ] || atf_fail "Cache directory should not have been deleted" -} - - -atf_test_case clean__too_many_args -clean__too_many_args_body() { - cat >experr <<EOF -sysupgrade: E: clean does not take any arguments -Type 'man sysupgrade' for help -EOF - atf_check -s exit:1 -e file:experr sysupgrade -c /dev/null clean foo -} - - -atf_test_case auto__simple -auto__simple_body() { - create_mock_binary postinstall - create_mock_binary etcupdate - PATH="$(pwd):${PATH}" - - create_mock_release release base comp etc netbsd-CUSTOM modules - - mkdir root - echo "old kernel" >root/netbsd - - cat >sysupgrade.conf <<EOF -CACHEDIR="$(pwd)/cache" -KERNEL="CUSTOM" -RELEASEDIR="$(pwd)/release" -SETS="base comp etc modules" -EOF - - atf_check \ - -e match:"Linking local" \ - -e match:"Upgrading kernel using" \ - -e match:"Upgrading kernel modules" \ - -e match:"Upgrading base system" \ - -e match:"Skipping etcupdate.*DESTDIR" \ - -e match:"Performing postinstall checks" \ - -e match:"Cleaning downloaded files" \ - sysupgrade -c sysupgrade.conf -d "$(pwd)/root" auto - - atf_check -o inline:"File from base\n" cat root/base.cookie - atf_check -o inline:"File from comp\n" cat root/comp.cookie - atf_check -o inline:"File from modules\n" cat root/modules.cookie - atf_check -o inline:"File from netbsd-CUSTOM\n" cat root/netbsd - atf_check -o inline:"old kernel\n" cat root/onetbsd - - [ ! -f root/etc.cookie ] || atf_fail "etc extracted by mistake" - - [ ! -f cache/base.tgz ] || atf_fail "Cache should have been cleaned" -} - - -atf_test_case auto__custom_releasedir -auto__custom_releasedir_body() { - create_mock_binary postinstall - create_mock_binary etcupdate - PATH="$(pwd):${PATH}" - - create_mock_release release2 base etc - - cat >sysupgrade.conf <<EOF -CACHEDIR="$(pwd)/cache" -KERNEL= -RELEASEDIR="$(pwd)/release" -SETS="base etc" -EOF - - atf_check \ - -e match:"Linking local" \ - -e not-match:"Upgrading kernel using" \ - -e not-match:"Upgrading kernel modules" \ - -e match:"Upgrading base system" \ - -e match:"Skipping etcupdate.*DESTDIR" \ - -e match:"Performing postinstall checks" \ - -e match:"Cleaning downloaded files" \ - sysupgrade -c sysupgrade.conf -d "$(pwd)/root" \ - auto "$(pwd)/release2" - - atf_check -o inline:"File from base\n" cat root/base.cookie - - [ ! -f root/etc.cookie ] || atf_fail "etc extracted by mistake" - [ ! -f root/onetbsd ] || atf_fail "Spurious kernel backup created" -} - - -atf_test_case auto__skip_etcupdate -auto__skip_etcupdate_body() { - create_mock_binary postinstall - PATH="$(pwd):${PATH}" - - create_mock_release release base etc - - cat >sysupgrade.conf <<EOF -CACHEDIR="$(pwd)/cache" -ETCUPDATE=no -RELEASEDIR="$(pwd)/release" -SETS="base etc" -EOF - - atf_check -e not-match:"etcupdate" \ - sysupgrade -c sysupgrade.conf -d "$(pwd)/root" auto -} - - -atf_test_case auto__skip_clean -auto__skip_clean_body() { - PATH="$(pwd):${PATH}" - - create_mock_release release2 base - - cat >sysupgrade.conf <<EOF -AUTOCLEAN=no -CACHEDIR="$(pwd)/cache" -KERNEL= -RELEASEDIR="$(pwd)/release" -SETS="base" -EOF - - atf_check \ - -e match:"Linking local" \ - -e not-match:"Upgrading kernel using" \ - -e not-match:"Upgrading kernel modules" \ - -e match:"Upgrading base system" \ - -e match:"Skipping etcupdate" \ - -e match:"Skipping postinstall" \ - -e not-match:"Cleaning downloaded files" \ - sysupgrade -c sysupgrade.conf -d "$(pwd)/root" \ - auto "$(pwd)/release2" - - atf_check -o inline:"File from base\n" cat root/base.cookie - - [ ! -f root/etc.cookie ] || atf_fail "etc extracted by mistake" - [ ! -f root/onetbsd ] || atf_fail "Spurious kernel backup created" - - [ -f cache/base.tgz ] || atf_fail "Cache should not have been cleaned" -} - - -atf_test_case auto__too_many_args -auto__too_many_args_body() { - cat >experr <<EOF -sysupgrade: E: auto takes zero or one arguments -Type 'man sysupgrade' for help -EOF - atf_check -s exit:1 -e file:experr sysupgrade -c /dev/null auto a b -} - - -atf_test_case no_command -no_command_body() { - cat >experr <<EOF -sysupgrade: E: No command specified -Type 'man sysupgrade' for help -EOF - atf_check -s exit:1 -e file:experr sysupgrade -} - - -atf_test_case unknown_command -unknown_command_body() { - cat >experr <<EOF -sysupgrade: E: Unknown command foo -Type 'man sysupgrade' for help -EOF - atf_check -s exit:1 -e file:experr sysupgrade foo -} - - -atf_test_case unknown_flag -unknown_flag_body() { - cat >experr <<EOF -sysupgrade: E: Unknown option -Z -Type 'man sysupgrade' for help -EOF - atf_check -s exit:1 -e file:experr sysupgrade -Z -} - - -atf_init_test_cases() { - atf_add_test_case config__builtins - atf_add_test_case config__default_file - atf_add_test_case config__explicit_file - atf_add_test_case config__auto__kernel__found - atf_add_test_case config__auto__kernel__not_found - atf_add_test_case config__auto__kernel__fail - atf_add_test_case config__auto__sets__found - atf_add_test_case config__auto__sets__not_found - atf_add_test_case config__not_found - atf_add_test_case config__overrides - atf_add_test_case config__too_many_args - - atf_add_test_case fetch__ftp - atf_add_test_case fetch__http - atf_add_test_case fetch__ssh__one_set - atf_add_test_case fetch__ssh__many_sets - atf_add_test_case fetch__ssh__already_exist - atf_add_test_case fetch__local - atf_add_test_case fetch__no_kernel - atf_add_test_case fetch__unknown - atf_add_test_case fetch__explicit - atf_add_test_case fetch__too_many_args - - atf_add_test_case kernel__skip - atf_add_test_case kernel__from_config - atf_add_test_case kernel__from_arg - atf_add_test_case kernel__override_backup - atf_add_test_case kernel__no_backup - atf_add_test_case kernel__missing_set - atf_add_test_case kernel__bad_file - atf_add_test_case kernel__too_many_args - - atf_add_test_case modules__skip - atf_add_test_case modules__install - atf_add_test_case modules__too_many_args - - atf_add_test_case sets__from_config - atf_add_test_case sets__from_args - atf_add_test_case sets__invalid_kern - - atf_add_test_case etcupdate__skip__none - atf_add_test_case etcupdate__skip__no_etc - atf_add_test_case etcupdate__skip__destdir - atf_add_test_case etcupdate__some_etcs - atf_add_test_case etcupdate__missing_etc - atf_add_test_case etcupdate__too_many_args - - atf_add_test_case postinstall__skip__none - atf_add_test_case postinstall__skip__no_etc - atf_add_test_case postinstall__some_etcs - atf_add_test_case postinstall__destdir - atf_add_test_case postinstall__autofix - atf_add_test_case postinstall__missing_etc - atf_add_test_case postinstall__explicit_args - - atf_add_test_case clean__nothing - atf_add_test_case clean__only_zipped - atf_add_test_case clean__too_many_args - - atf_add_test_case auto__simple - atf_add_test_case auto__custom_releasedir - atf_add_test_case auto__skip_etcupdate - atf_add_test_case auto__skip_clean - atf_add_test_case auto__too_many_args - - atf_add_test_case no_command - atf_add_test_case unknown_command - atf_add_test_case unknown_flag -} |