Wed Aug 15 21:21:15 2012 UTC ()
Update to 1.1:

- Use shtk for the common utilities and configuration file parsing
  functionality.  The local copies of the "config" and "utils" modules
  are gone.


(jmmv)
diff -r1.1 -r1.2 pkgsrc/sysutils/sysupgrade/Makefile
diff -r1.1 -r1.2 pkgsrc/sysutils/sysupgrade/PLIST
diff -r1.1 -r1.2 pkgsrc/sysutils/sysupgrade/TODO
diff -r1.1 -r1.2 pkgsrc/sysutils/sysupgrade/files/Kyuafile
diff -r1.1 -r1.2 pkgsrc/sysutils/sysupgrade/files/sysupgrade.sh
diff -r1.1 -r1.2 pkgsrc/sysutils/sysupgrade/files/sysupgrade_test.sh
diff -r1.1 -r0 pkgsrc/sysutils/sysupgrade/files/config.subr
diff -r1.1 -r0 pkgsrc/sysutils/sysupgrade/files/config_test.sh
diff -r1.1 -r0 pkgsrc/sysutils/sysupgrade/files/utils.subr
diff -r1.1 -r0 pkgsrc/sysutils/sysupgrade/files/utils_test.sh

cvs diff -r1.1 -r1.2 pkgsrc/sysutils/sysupgrade/Makefile (expand / switch to unified diff)

--- pkgsrc/sysutils/sysupgrade/Makefile 2012/08/06 17:06:17 1.1
+++ pkgsrc/sysutils/sysupgrade/Makefile 2012/08/15 21:21:15 1.2
@@ -1,89 +1,81 @@ @@ -1,89 +1,81 @@
1# $NetBSD: Makefile,v 1.1 2012/08/06 17:06:17 jmmv Exp $ 1# $NetBSD: Makefile,v 1.2 2012/08/15 21:21:15 jmmv Exp $
2 2
3DISTNAME= sysupgrade-1.0 3DISTNAME= sysupgrade-1.1
4CATEGORIES= sysutils 4CATEGORIES= sysutils
5MASTER_SITES= # empty 5MASTER_SITES= # empty
6DISTFILES= # empty 6DISTFILES= # empty
7 7
8MAINTAINER= jmmv@NetBSD.org 8MAINTAINER= jmmv@NetBSD.org
9COMMENT= Automate upgrades of NetBSD 9COMMENT= Automate upgrades of NetBSD
10LICENSE= modified-bsd 10LICENSE= modified-bsd
11 11
12PKG_INSTALLATION_TYPES= overwrite pkgviews 12PKG_INSTALLATION_TYPES= overwrite pkgviews
13PKG_DESTDIR_SUPPORT= user-destdir 13PKG_DESTDIR_SUPPORT= user-destdir
14 14
15WRKSRC= ${WRKDIR} 15WRKSRC= ${WRKDIR}
16NO_CONFIGURE= YES 16NO_CONFIGURE= YES
17 17
18UPGRADE_SUBST+= -e 's,@SYSUPGRADE_CACHEDIR@,${CACHEDIR},g' 18BUILD_SUBST+= -e 's,@SYSUPGRADE_CACHEDIR@,${CACHEDIR},g'
19UPGRADE_SUBST+= -e 's,@SYSUPGRADE_ETCDIR@,${PKG_SYSCONFDIR},g' 19BUILD_SUBST+= -e 's,@SYSUPGRADE_ETCDIR@,${PKG_SYSCONFDIR},g'
20 20
21BUILD_DEFS+= VARBASE 21BUILD_DEFS+= VARBASE
22CACHEDIR= ${VARBASE}/cache/sysupgrade 22CACHEDIR= ${VARBASE}/cache/sysupgrade
23OWN_DIRS= ${CACHEDIR} root wheel 23OWN_DIRS= ${CACHEDIR} root wheel
24 24
25EGDIR= ${PREFIX}/share/examples/sysupgrade 25EGDIR= ${PREFIX}/share/examples/sysupgrade
26CONF_FILES+= ${EGDIR}/default.conf ${PKG_SYSCONFDIR}/sysupgrade.conf 26CONF_FILES+= ${EGDIR}/default.conf ${PKG_SYSCONFDIR}/sysupgrade.conf
27 27
28PKG_OPTIONS_VAR= PKG_OPTIONS.sysupgrade 28PKG_OPTIONS_VAR= PKG_OPTIONS.sysupgrade
29PKG_SUPPORTED_OPTIONS= tests 29PKG_SUPPORTED_OPTIONS= tests
30PKG_SUGGESTED_OPTIONS= tests 30PKG_SUGGESTED_OPTIONS= tests
31 31
32.include "../../mk/bsd.options.mk" 32.include "../../mk/bsd.options.mk"
33 33
34.if $(PKG_OPTIONS:Mtests) 34.if $(PKG_OPTIONS:Mtests)
35TEST_PROGS= config_test sysupgrade_test utils_test 
36 
37PLIST_SUBST+= TESTS= 35PLIST_SUBST+= TESTS=
38. include "../../devel/atf-libs/buildlink3.mk" 36. include "../../devel/atf-libs/buildlink3.mk"
39 37
 38BUILD_SUBST+= -e 's,@ATF_SH@,${BUILDLINK_PREFIX.atf-libs}/bin/atf-sh,g'
 39
40do-build: build-tests 40do-build: build-tests
41build-tests: 41build-tests:
42 cp ${FILESDIR}/Kyuafile ${WRKSRC} 42 cp ${FILESDIR}/Kyuafile ${WRKSRC}
43.for file in ${TEST_PROGS} 43 sed ${BUILD_SUBST} ${FILESDIR}/sysupgrade_test.sh \
44 ${ECHO} '#! ${BUILDLINK_PREFIX.atf-libs}/bin/atf-sh' \ 44 >${WRKSRC}/sysupgrade_test
45 >${WRKSRC}/${file} 45 chmod +x ${WRKSRC}/sysupgrade_test
46 ${CAT} ${FILESDIR}/*.subr ${FILESDIR}/${file}.sh \ 
47 | ${SED} ${UPGRADE_SUBST} >>${WRKSRC}/${file} 
48 ${CHMOD} +x ${WRKSRC}/${file} 
49.endfor 
50 46
51INSTALLATION_DIRS+= tests/sysupgrade 47INSTALLATION_DIRS+= tests/sysupgrade
52 48
53do-install: install-tests 49do-install: install-tests
54install-tests: 50install-tests:
55 ${INSTALL_DATA} ${WRKSRC}/Kyuafile ${DESTDIR}${PREFIX}/tests/sysupgrade 51 ${INSTALL_DATA} ${WRKSRC}/Kyuafile ${DESTDIR}${PREFIX}/tests/sysupgrade
56.for file in ${TEST_PROGS} 52 ${INSTALL_SCRIPT} ${WRKSRC}/sysupgrade_test \
57 ${INSTALL_SCRIPT} ${WRKSRC}/${file} \ 
58 ${DESTDIR}${PREFIX}/tests/sysupgrade/ 53 ${DESTDIR}${PREFIX}/tests/sysupgrade/
59.endfor 
60 54
61do-test: 55do-test:
62 cd ${WRKSRC} && PATH="${WRKSRC}:${PATH}" kyua test 56 cd ${WRKSRC} && PATH="${WRKSRC}:${PATH}" kyua test
63.else 57.else
64PLIST_SUBST+= TESTS=@comment 58PLIST_SUBST+= TESTS=@comment
65.endif 59.endif
66 60
67do-build: 61do-build:
68 ${ECHO} '#! ${SH}' >${WRKSRC}/sysupgrade 62 sed ${BUILD_SUBST} ${FILESDIR}/sysupgrade.sh \
69 ${ECHO} 'set -e' >>${WRKSRC}/sysupgrade 63 | ${BUILDLINK_PREFIX.shtk}/bin/shtk build \
70 ${CAT} ${FILESDIR}/*.subr ${FILESDIR}/sysupgrade.sh \ 64 -s ${SH} -m sysupgrade_main -o ${WRKSRC}/sysupgrade -
71 | ${SED} ${UPGRADE_SUBST} >>${WRKSRC}/sysupgrade 
72 ${ECHO} 'sysupgrade_main "$${@}"' >>${WRKSRC}/sysupgrade 
73 ${CHMOD} +x ${WRKSRC}/sysupgrade 
74.for file in sysupgrade.8 sysupgrade.conf.5 default.conf 65.for file in sysupgrade.8 sysupgrade.conf.5 default.conf
75 sed ${UPGRADE_SUBST} <${FILESDIR}/${file} >${WRKSRC}/${file} 66 sed ${BUILD_SUBST} <${FILESDIR}/${file} >${WRKSRC}/${file}
76.endfor 67.endfor
77 68
78INSTALLATION_DIRS+= bin ${PKGMANDIR}/man5 ${PKGMANDIR}/man8 \ 69INSTALLATION_DIRS+= bin ${PKGMANDIR}/man5 ${PKGMANDIR}/man8 \
79 share/examples/sysupgrade 70 share/examples/sysupgrade
80 71
81do-install: 72do-install:
82 ${INSTALL_SCRIPT} ${WRKSRC}/sysupgrade ${DESTDIR}${PREFIX}/bin/ 73 ${INSTALL_SCRIPT} ${WRKSRC}/sysupgrade ${DESTDIR}${PREFIX}/bin/
83 ${INSTALL_MAN} ${WRKSRC}/sysupgrade.8 \ 74 ${INSTALL_MAN} ${WRKSRC}/sysupgrade.8 \
84 ${DESTDIR}${PREFIX}/${PKGMANDIR}/man8/ 75 ${DESTDIR}${PREFIX}/${PKGMANDIR}/man8/
85 ${INSTALL_MAN} ${WRKSRC}/sysupgrade.conf.5 \ 76 ${INSTALL_MAN} ${WRKSRC}/sysupgrade.conf.5 \
86 ${DESTDIR}${PREFIX}/${PKGMANDIR}/man5/ 77 ${DESTDIR}${PREFIX}/${PKGMANDIR}/man5/
87 ${INSTALL_DATA} ${WRKSRC}/default.conf ${DESTDIR}${EGDIR} 78 ${INSTALL_DATA} ${WRKSRC}/default.conf ${DESTDIR}${EGDIR}
88 79
 80.include "../../devel/shtk/buildlink3.mk"
89.include "../../mk/bsd.pkg.mk" 81.include "../../mk/bsd.pkg.mk"

cvs diff -r1.1 -r1.2 pkgsrc/sysutils/sysupgrade/PLIST (expand / switch to unified diff)

--- pkgsrc/sysutils/sysupgrade/PLIST 2012/08/06 17:06:17 1.1
+++ pkgsrc/sysutils/sysupgrade/PLIST 2012/08/15 21:21:15 1.2
@@ -1,9 +1,7 @@ @@ -1,9 +1,7 @@
1@comment $NetBSD: PLIST,v 1.1 2012/08/06 17:06:17 jmmv Exp $ 1@comment $NetBSD: PLIST,v 1.2 2012/08/15 21:21:15 jmmv Exp $
2bin/sysupgrade 2bin/sysupgrade
3man/man5/sysupgrade.conf.5 3man/man5/sysupgrade.conf.5
4man/man8/sysupgrade.8 4man/man8/sysupgrade.8
5share/examples/sysupgrade/default.conf 5share/examples/sysupgrade/default.conf
6${TESTS}tests/sysupgrade/Kyuafile 6${TESTS}tests/sysupgrade/Kyuafile
7${TESTS}tests/sysupgrade/config_test 
8${TESTS}tests/sysupgrade/sysupgrade_test 7${TESTS}tests/sysupgrade/sysupgrade_test
9${TESTS}tests/sysupgrade/utils_test 

cvs diff -r1.1 -r1.2 pkgsrc/sysutils/sysupgrade/Attic/TODO (expand / switch to unified diff)

--- pkgsrc/sysutils/sysupgrade/Attic/TODO 2012/08/06 17:06:17 1.1
+++ pkgsrc/sysutils/sysupgrade/Attic/TODO 2012/08/15 21:21:15 1.2
@@ -1,13 +1,16 @@ @@ -1,13 +1,16 @@
 1Things that sysupgrade could do
 2===============================
 3
1- Deduce the current NetBSD release from /etc/release and the target 4- Deduce the current NetBSD release from /etc/release and the target
2 release from etc.tgz and inform the user about the changes. This will be 5 release from etc.tgz and inform the user about the changes. This will be
3 necessary if the upgrade process needs to apply specific tweaks depending 6 necessary if the upgrade process needs to apply specific tweaks depending
4 on the affected NetBSD releases (which is not the case at the moment). 7 on the affected NetBSD releases (which is not the case at the moment).
5 8
6- Ability to automatically deduce the next upgrade target from a collection 9- Ability to automatically deduce the next upgrade target from a collection
7 of directories (e.g. from FTP). We should be able to tell sysupgrade to 10 of directories (e.g. from FTP). We should be able to tell sysupgrade to
8 follow along 6.0.x, or 6.x, or the daily builds and get it to pick the 11 follow along 6.0.x, or 6.x, or the daily builds and get it to pick the
9 most recent available build. Having to manually scan FTP directories to 12 most recent available build. Having to manually scan FTP directories to
10 select the correct build is... inconvenient. 13 select the correct build is... inconvenient.
11 14
12- Ensure that the fetched sets belong to the current architecture. I have 15- Ensure that the fetched sets belong to the current architecture. I have
13 bitten once by mistakenly pointing my custom update scripts to the wrong 16 bitten once by mistakenly pointing my custom update scripts to the wrong
@@ -18,13 +21,24 @@ @@ -18,13 +21,24 @@
18 command should unconditionally download the checksums every time it is 21 command should unconditionally download the checksums every time it is
19 run and then deduce whether it needs to redownload (possibly-newer) sets 22 run and then deduce whether it needs to redownload (possibly-newer) sets
20 or do nothing. 23 or do nothing.
21 24
22- Add destdir support to etcupdate(8) and allow the 'etcupdate' command to 25- Add destdir support to etcupdate(8) and allow the 'etcupdate' command to
23 run when destdir is enabled. 26 run when destdir is enabled.
24 27
25- Maybe sysupgrade should be more interactive by default, letting the user 28- Maybe sysupgrade should be more interactive by default, letting the user
26 know what exactly is going to happen before doing so (e.g. what will be 29 know what exactly is going to happen before doing so (e.g. what will be
27 the new version, where things are being downloaded from, etc.), and 30 the new version, where things are being downloaded from, etc.), and
28 providing a "quiet mode" flag instead. etcupdate is interactive anyway, 31 providing a "quiet mode" flag instead. etcupdate is interactive anyway,
29 so adding more interactive steps (as long as they can be disabled) does 32 so adding more interactive steps (as long as they can be disabled) does
30 not seem a big deal. 33 not seem a big deal.
 34
 35
 36Things that sysupgrade will NOT do
 37==================================
 38
 39- Non-trivial rollbacks. If rollbacks are ever implemented, they should
 40 be in the form of file system snapshots OR in the form of syspkgs.
 41 Getting sysupgrade to magically store files aside to allow a later
 42 rollback is just too fragile and hard to get right: rollbacks will
 43 rarely will be necessary, but when they are it's very likely that a
 44 tool like this is broken.

cvs diff -r1.1 -r1.2 pkgsrc/sysutils/sysupgrade/files/Attic/Kyuafile (expand / switch to unified diff)

--- pkgsrc/sysutils/sysupgrade/files/Attic/Kyuafile 2012/08/06 17:06:17 1.1
+++ pkgsrc/sysutils/sysupgrade/files/Attic/Kyuafile 2012/08/15 21:21:15 1.2
@@ -1,7 +1,5 @@ @@ -1,7 +1,5 @@
1syntax("kyuafile", 1) 1syntax("kyuafile", 1)
2 2
3test_suite("sysupgrade") 3test_suite("sysupgrade")
4 4
5atf_test_program{name="config_test"} 
6atf_test_program{name="sysupgrade_test"} 5atf_test_program{name="sysupgrade_test"}
7atf_test_program{name="utils_test"} 

cvs diff -r1.1 -r1.2 pkgsrc/sysutils/sysupgrade/files/Attic/sysupgrade.sh (expand / switch to unified diff)

--- pkgsrc/sysutils/sysupgrade/files/Attic/sysupgrade.sh 2012/08/06 17:06:17 1.1
+++ pkgsrc/sysutils/sysupgrade/files/Attic/sysupgrade.sh 2012/08/15 21:21:15 1.2
@@ -19,26 +19,31 @@ @@ -19,26 +19,31 @@
19# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 28
29# \file sysupgrade.sh 29# \file sysupgrade.sh
30# Entry point and main program logic. 30# Entry point and main program logic.
31 31
 32shtk_import cli
 33shtk_import config
 34shtk_import list
 35shtk_import process
 36
32 37
33# List of valid configuration variables. 38# List of valid configuration variables.
34# 39#
35# Please remember to update sysbuild(1) if you change this list. 40# Please remember to update sysbuild(1) if you change this list.
36SYSUPGRADE_CONFIG_VARS="AUTOCLEAN CACHEDIR DESTDIR ETCUPDATE KERNEL 41SYSUPGRADE_CONFIG_VARS="AUTOCLEAN CACHEDIR DESTDIR ETCUPDATE KERNEL
37 POSTINSTALL_AUTOFIX RELEASEDIR SETS" 42 POSTINSTALL_AUTOFIX RELEASEDIR SETS"
38 43
39 44
40# Directory in which to keep downloaded release files. 45# Directory in which to keep downloaded release files.
41# 46#
42# Can be overriden for test purposes only. 47# Can be overriden for test purposes only.
43: ${SYSUPGRADE_CACHEDIR:="@SYSUPGRADE_CACHEDIR@"} 48: ${SYSUPGRADE_CACHEDIR:="@SYSUPGRADE_CACHEDIR@"}
44 49
@@ -46,414 +51,414 @@ SYSUPGRADE_CONFIG_VARS="AUTOCLEAN CACHED @@ -46,414 +51,414 @@ SYSUPGRADE_CONFIG_VARS="AUTOCLEAN CACHED
46# Paths to installed files. 51# Paths to installed files.
47# 52#
48# Can be overriden for test purposes only. 53# Can be overriden for test purposes only.
49: ${SYSUPGRADE_ETCDIR:="@SYSUPGRADE_ETCDIR@"} 54: ${SYSUPGRADE_ETCDIR:="@SYSUPGRADE_ETCDIR@"}
50 55
51 56
52# Sets defaults for configuration variables that need a value. 57# Sets defaults for configuration variables that need a value.
53# 58#
54# This function should be called before the configuration file has been loaded. 59# This function should be called before the configuration file has been loaded.
55# This means that the user can undefine a required configuration variable, but 60# This means that the user can undefine a required configuration variable, but
56# we let him shoot himself in the foot if he so desires. 61# we let him shoot himself in the foot if he so desires.
57sysupgrade_set_defaults() { 62sysupgrade_set_defaults() {
58 # Please remember to update sysupgrade(8) if you change any default values. 63 # Please remember to update sysupgrade(8) if you change any default values.
59 config_set AUTOCLEAN "yes" 64 shtk_config_set AUTOCLEAN "yes"
60 config_set CACHEDIR "${SYSUPGRADE_CACHEDIR}" 65 shtk_config_set CACHEDIR "${SYSUPGRADE_CACHEDIR}"
61 config_set ETCUPDATE "yes" 66 shtk_config_set ETCUPDATE "yes"
62 config_set KERNEL "AUTO" 67 shtk_config_set KERNEL "AUTO"
63 config_set SETS "AUTO" 68 shtk_config_set SETS "AUTO"
64} 69}
65 70
66 71
67# Interprets magic configuration values. 72# Interprets magic configuration values.
68# 73#
69# This function should be called after the configuration file has been loaded. 74# This function should be called after the configuration file has been loaded.
70# It takes care of performing any required post-processing on the configuration 75# It takes care of performing any required post-processing on the configuration
71# variables, such as expanding the magic AUTO keyword to the actual value. 76# variables, such as expanding the magic AUTO keyword to the actual value.
72sysupgrade_auto_config() { 77sysupgrade_auto_config() {
73 if [ "$(config_get_default KERNEL "")" = "AUTO" ]; then 78 if [ "$(shtk_config_get_default KERNEL "")" = "AUTO" ]; then
74 local kernel="$(config_get_default DESTDIR "")/netbsd" 79 local kernel="$(shtk_config_get_default DESTDIR "")/netbsd"
75 if [ -e "${kernel}" ]; then 80 if [ -e "${kernel}" ]; then
76 local kernel_name="$(config -x "${kernel}" | head -n 1 \ 81 local kernel_name="$(config -x "${kernel}" | head -n 1 \
77 | cut -d \" -f 2)" 82 | cut -d \" -f 2)"
78 [ -n "${kernel_name}" ] || utils_error "Failed to determine" \ 83 [ -n "${kernel_name}" ] || shtk_cli_error "Failed to determine" \
79 "kernel name; please set KERNEL explicitly" 84 "kernel name; please set KERNEL explicitly"
80 config_set KERNEL "${kernel_name}" 85 shtk_config_set KERNEL "${kernel_name}"
81 else 86 else
82 config_unset KERNEL 87 shtk_config_unset KERNEL
83 fi 88 fi
84 fi 89 fi
85 90
86 if [ "$(config_get_default SETS "")" = "AUTO" ]; then 91 if [ "$(shtk_config_get_default SETS "")" = "AUTO" ]; then
87 local mtree="$(config_get_default DESTDIR "")/etc/mtree/" 92 local mtree="$(shtk_config_get_default DESTDIR "")/etc/mtree/"
88 if [ -d "${mtree}" ]; then 93 if [ -d "${mtree}" ]; then
89 local all_sets="$(cd "${mtree}" && echo set.* \ 94 local all_sets="$(cd "${mtree}" && echo set.* \
90 | sed -e 's,set\.,,g')" 95 | sed -e 's,set\.,,g')"
91 config_set SETS "${all_sets}" 96 shtk_config_set SETS "${all_sets}"
92 else 97 else
93 config_unset SETS 98 shtk_config_unset SETS
94 fi 99 fi
95 fi 100 fi
96} 101}
97 102
98 103
99# Dumps the loaded configuration. 104# Dumps the loaded configuration.
100# 105#
101# \params ... The options and arguments to the command. 106# \params ... The options and arguments to the command.
102sysupgrade_config() { 107sysupgrade_config() {
103 local eval_auto=no 108 local eval_auto=no
104 while getopts ':a' arg "${@}"; do 109 while getopts ':a' arg "${@}"; do
105 case "${arg}" in 110 case "${arg}" in
106 a) # Evaluate automatic settings. 111 a) # Evaluate automatic settings.
107 eval_auto=yes 112 eval_auto=yes
108 ;; 113 ;;
109 114
110 \?) 115 \?)
111 utils_usage_error "Unknown option -${OPTARG}" 116 shtk_cli_usage_error "Unknown option -${OPTARG}"
112 ;; 117 ;;
113 esac 118 esac
114 done 119 done
115 shift $((${OPTIND} - 1)) 120 shift $((${OPTIND} - 1))
116 121
117 [ ${#} -eq 0 ] || utils_usage_error "config does not take any arguments" 122 [ ${#} -eq 0 ] || shtk_cli_usage_error "config does not take any arguments"
118 123
119 [ "${eval_auto}" = no ] || sysupgrade_auto_config 124 [ "${eval_auto}" = no ] || sysupgrade_auto_config
120 125
121 for var in ${SYSUPGRADE_CONFIG_VARS}; do 126 for var in ${SYSUPGRADE_CONFIG_VARS}; do
122 if config_has "${var}"; then 127 if shtk_config_has "${var}"; then
123 echo "${var} = $(config_get "${var}")" 128 echo "${var} = $(shtk_config_get "${var}")"
124 else 129 else
125 echo "${var} is undefined" 130 echo "${var} is undefined"
126 fi 131 fi
127 done 132 done
128} 133}
129 134
130 135
131# Gets the path to a set, and ensures it exists. 136# Gets the path to a set, and ensures it exists.
132# 137#
133# \post The path to the tgz of the set is printed on stdout. 138# \post The path to the tgz of the set is printed on stdout.
134# 139#
135# \param set_name The name of the set to query. 140# \param set_name The name of the set to query.
136get_set() { 141get_set() {
137 local set_name="${1}"; shift 142 local set_name="${1}"; shift
138 143
139 echo "$(config_get CACHEDIR)/${set_name}.tgz" 144 echo "$(shtk_config_get CACHEDIR)/${set_name}.tgz"
140} 145}
141 146
142 147
143# Ensures that a given set exists. 148# Ensures that a given set exists.
144# 149#
145# \param set_name The name of the set to query. 150# \param set_name The name of the set to query.
146require_set() { 151require_set() {
147 local set_name="${1}"; shift 152 local set_name="${1}"; shift
148 153
149 local set_tgz="$(get_set "${set_name}")" 154 local set_tgz="$(get_set "${set_name}")"
150 [ -f "${set_tgz}" ] || utils_error "Cannot find ${set_name}; did you run" \ 155 [ -f "${set_tgz}" ] || shtk_cli_error "Cannot find ${set_name}; did you run" \
151 "'${Utils_ProgName} fetch' first?" 156 "'$(shtk_cli_progname) fetch' first?"
152} 157}
153 158
154 159
155# Extracts a set into the destdir. 160# Extracts a set into the destdir.
156# 161#
157# The set to be extracted must have been previously fetched into the cache 162# The set to be extracted must have been previously fetched into the cache
158# directory by sysupgrade_fetch command. 163# directory by sysupgrade_fetch command.
159# 164#
160# \param set_name Name of the set to extract, without the .tgz extension. 165# \param set_name Name of the set to extract, without the .tgz extension.
161extract_set() { 166extract_set() {
162 local set_name="${1}"; shift 167 local set_name="${1}"; shift
163 168
164 require_set "${set_name}" 169 require_set "${set_name}"
165 170
166 local destdir="$(config_get_default DESTDIR "")" 171 local destdir="$(shtk_config_get_default DESTDIR "")"
167 local set_tgz="$(get_set "${set_name}")" 172 local set_tgz="$(get_set "${set_name}")"
168 173
169 utils_info "Extracting ${set_name} into ${destdir}/" 174 shtk_cli_info "Extracting ${set_name} into ${destdir}/"
170 [ -z "${destdir}" ] || utils_run mkdir -p "${destdir}" 175 [ -z "${destdir}" ] || shtk_process_run mkdir -p "${destdir}"
171 progress -zf "${set_tgz}" tar -xp -C "${destdir}/" -f - 176 progress -zf "${set_tgz}" tar -xp -C "${destdir}/" -f -
172} 177}
173 178
174 179
175# Fetches the release sets into the cache directory. 180# Fetches the release sets into the cache directory.
176# 181#
177# \param releasedir Optional override of the release directory to use. 182# \param releasedir Optional override of the release directory to use.
178sysupgrade_fetch() { 183sysupgrade_fetch() {
179 [ ${#} -lt 2 ] \ 184 [ ${#} -lt 2 ] \
180 || utils_usage_error "fetch takes zero or one arguments" 185 || shtk_cli_usage_error "fetch takes zero or one arguments"
181 186
182 [ -z "${1}" ] || config_set "RELEASEDIR" "${1}" 187 [ -z "${1}" ] || shtk_config_set "RELEASEDIR" "${1}"
183 188
184 local releasedir="$(config_get RELEASEDIR)" 189 local releasedir="$(shtk_config_get RELEASEDIR)"
185 local cachedir="$(config_get CACHEDIR)" 190 local cachedir="$(shtk_config_get CACHEDIR)"
186 local fetch_sets="$(config_get SETS)" 191 local fetch_sets="$(shtk_config_get SETS)"
187 if config_has KERNEL; then 192 if shtk_config_has KERNEL; then
188 fetch_sets="${fetch_sets} kern-$(config_get KERNEL)" 193 fetch_sets="${fetch_sets} kern-$(shtk_config_get KERNEL)"
189 fi 194 fi
190 195
191 case "${releasedir}" in 196 case "${releasedir}" in
192 ftp://*|http://*) 197 ftp://*|http://*)
193 mkdir -p "${cachedir}" 198 mkdir -p "${cachedir}"
194 199
195 for set_name in ${fetch_sets}; do 200 for set_name in ${fetch_sets}; do
196 local file="${cachedir}/${set_name}.tgz" 201 local file="${cachedir}/${set_name}.tgz"
197 if [ -f "${file}" ]; then 202 if [ -f "${file}" ]; then
198 utils_warning "Reusing existing ${file}" 203 shtk_cli_warning "Reusing existing ${file}"
199 else 204 else
200 local url="${releasedir}/binary/sets/${set_name}.tgz" 205 local url="${releasedir}/binary/sets/${set_name}.tgz"
201 utils_info "Downloading ${url} into ${cachedir}" 206 shtk_cli_info "Downloading ${url} into ${cachedir}"
202 rm -f "${file}" 207 rm -f "${file}"
203 ftp -R -o"${file}.tmp" "${url}" \ 208 ftp -R -o"${file}.tmp" "${url}" \
204 || utils_error "Failed to fetch ${url}" 209 || shtk_cli_error "Failed to fetch ${url}"
205 mv "${file}.tmp" "${file}" 210 mv "${file}.tmp" "${file}"
206 fi 211 fi
207 done 212 done
208 ;; 213 ;;
209 214
210 /*) 215 /*)
211 mkdir -p "${cachedir}" 216 mkdir -p "${cachedir}"
212 217
213 for set_name in ${fetch_sets}; do 218 for set_name in ${fetch_sets}; do
214 local src="${releasedir}/binary/sets/${set_name}.tgz" 219 local src="${releasedir}/binary/sets/${set_name}.tgz"
215 utils_info "Linking local ${src} into ${cachedir}" 220 shtk_cli_info "Linking local ${src} into ${cachedir}"
216 [ -f "${src}" ] || utils_error "Cannot open ${src}" 221 [ -f "${src}" ] || shtk_cli_error "Cannot open ${src}"
217 ln -s -f "${src}" "${cachedir}/${set_name}.tgz" \ 222 ln -s -f "${src}" "${cachedir}/${set_name}.tgz" \
218 || utils_error "Failed to link ${src} into ${cachedir}" 223 || shtk_cli_error "Failed to link ${src} into ${cachedir}"
219 done 224 done
220 ;; 225 ;;
221 226
222 *) 227 *)
223 utils_error "Don't know how to fetch from ${releasedir}; must" \ 228 shtk_cli_error "Don't know how to fetch from ${releasedir}; must" \
224 "be an absolute path or an FTP/HTTP site" 229 "be an absolute path or an FTP/HTTP site"
225 ;; 230 ;;
226 esac 231 esac
227} 232}
228 233
229 234
230# Installs a new kernel from a set. 235# Installs a new kernel from a set.
231# 236#
232# \param kernel_name Name of the kernel set to use; optional. 237# \param kernel_name Name of the kernel set to use; optional.
233sysupgrade_kernel() { 238sysupgrade_kernel() {
234 [ ${#} -lt 2 ] \ 239 [ ${#} -lt 2 ] \
235 || utils_usage_error "kernel takes zero or one arguments" 240 || shtk_cli_usage_error "kernel takes zero or one arguments"
236 241
237 local kernel_name 242 local kernel_name
238 if [ -n "${1}" ]; then 243 if [ -n "${1}" ]; then
239 kernel_name="${1}" 244 kernel_name="${1}"
240 elif config_has KERNEL; then 245 elif shtk_config_has KERNEL; then
241 kernel_name="$(config_get KERNEL)" 246 kernel_name="$(shtk_config_get KERNEL)"
242 else 247 else
243 utils_info "Skipping kernel installation (KERNEL not set)" 248 shtk_cli_info "Skipping kernel installation (KERNEL not set)"
244 return 0 249 return 0
245 fi 250 fi
246 251
247 require_set "kern-${kernel_name}" 252 require_set "kern-${kernel_name}"
248 253
249 local destdir="$(config_get_default DESTDIR "")" 254 local destdir="$(shtk_config_get_default DESTDIR "")"
250 utils_info "Upgrading kernel using ${kernel_name} in ${destdir}/" 255 shtk_cli_info "Upgrading kernel using ${kernel_name} in ${destdir}/"
251 256
252 if [ -f "${destdir}/netbsd" ]; then 257 if [ -f "${destdir}/netbsd" ]; then
253 utils_info "Backing up 'netbsd' kernel as 'onetbsd'" 258 shtk_cli_info "Backing up 'netbsd' kernel as 'onetbsd'"
254 cp "${destdir}/netbsd" "${destdir}/onetbsd" 259 cp "${destdir}/netbsd" "${destdir}/onetbsd"
255 fi 260 fi
256 extract_set "kern-${kernel_name}" 261 extract_set "kern-${kernel_name}"
257} 262}
258 263
259 264
260# Installs new kernel modules. 265# Installs new kernel modules.
261sysupgrade_modules() { 266sysupgrade_modules() {
262 [ ${#} -eq 0 ] \ 267 [ ${#} -eq 0 ] \
263 || utils_usage_error "modules does not take any arguments" 268 || shtk_cli_usage_error "modules does not take any arguments"
264 269
265 if ! utils_contains modules $(config_get SETS); then 270 if ! shtk_list_contains modules $(shtk_config_get SETS); then
266 utils_info "Skipping modules installation (modules not in SETS)" 271 shtk_cli_info "Skipping modules installation (modules not in SETS)"
267 return 0 272 return 0
268 fi 273 fi
269 274
270 utils_info "Upgrading kernel modules" 275 shtk_cli_info "Upgrading kernel modules"
271 276
272 extract_set modules 277 extract_set modules
273} 278}
274 279
275 280
276# Installs new sets. 281# Installs new sets.
277# 282#
278# \param ... Names of the sets to extract, to override SETS. 283# \param ... Names of the sets to extract, to override SETS.
279sysupgrade_sets() { 284sysupgrade_sets() {
280 utils_info "Upgrading base system" 285 shtk_cli_info "Upgrading base system"
281 286
282 local sets= 287 local sets=
283 for set_name in "${@:-$(config_get SETS)}"; do 288 for set_name in "${@:-$(shtk_config_get SETS)}"; do
284 case "${set_name}" in 289 case "${set_name}" in
285 *etc) ;; # Handled by etcupdate. 290 *etc) ;; # Handled by etcupdate.
286 kern-*) ;; # Handled by kernel. 291 kern-*) ;; # Handled by kernel.
287 modules) ;; # Handled by modules. 292 modules) ;; # Handled by modules.
288 *) sets="${sets} ${set_name}" ;; 293 *) sets="${sets} ${set_name}" ;;
289 esac 294 esac
290 done 295 done
291 296
292 for set_name in ${sets}; do 297 for set_name in ${sets}; do
293 require_set "${set_name}" 298 require_set "${set_name}"
294 done 299 done
295 300
296 for set_name in ${sets}; do 301 for set_name in ${sets}; do
297 extract_set "${set_name}" 302 extract_set "${set_name}"
298 done 303 done
299} 304}
300 305
301 306
302# Runs etcupdate to install new configuration files. 307# Runs etcupdate to install new configuration files.
303sysupgrade_etcupdate() { 308sysupgrade_etcupdate() {
304 [ ${#} -eq 0 ] || utils_usage_error "etcupdate does not take any arguments" 309 [ ${#} -eq 0 ] || shtk_cli_usage_error "etcupdate does not take any arguments"
305 310
306 if config_has DESTDIR; then 311 if shtk_config_has DESTDIR; then
307 utils_info "Skipping etcupdate (DESTDIR upgrades not supported)" 312 shtk_cli_info "Skipping etcupdate (DESTDIR upgrades not supported)"
308 return 0 313 return 0
309 fi 314 fi
310 315
311 local sets="$(utils_filter '*etc' $(config_get SETS))" 316 local sets="$(shtk_list_filter '*etc' $(shtk_config_get SETS))"
312 if [ -z "${sets}" ]; then 317 if [ -z "${sets}" ]; then
313 utils_info "Skipping etcupdate (no etc sets in SETS)" 318 shtk_cli_info "Skipping etcupdate (no etc sets in SETS)"
314 return 0 319 return 0
315 fi 320 fi
316 if ! utils_contains etc ${sets}; then 321 if ! shtk_list_contains etc ${sets}; then
317 utils_info "Skipping etcupdate (required etc not in SETS)" 322 shtk_cli_info "Skipping etcupdate (required etc not in SETS)"
318 return 0 323 return 0
319 fi 324 fi
320 325
321 local sflags= 326 local sflags=
322 for set_name in ${sets}; do 327 for set_name in ${sets}; do
323 require_set "${set_name}" 328 require_set "${set_name}"
324 sflags="${sflags} -s$(get_set "${set_name}")" 329 sflags="${sflags} -s$(get_set "${set_name}")"
325 done 330 done
326 331
327 utils_info "Upgrading /etc interactively" 332 shtk_cli_info "Upgrading /etc interactively"
328 etcupdate -a -l ${sflags} 333 etcupdate -a -l ${sflags}
329} 334}
330 335
331 336
332# Runs postinstall to validate the updated system. 337# Runs postinstall to validate the updated system.
333# 338#
334# \param ... Arguments to pass to postinstall(8). 339# \param ... Arguments to pass to postinstall(8).
335sysupgrade_postinstall() { 340sysupgrade_postinstall() {
336 local sets= 341 local sets=
337 local sets="$(utils_filter '*etc' $(config_get SETS))" 342 local sets="$(shtk_list_filter '*etc' $(shtk_config_get SETS))"
338 if [ -z "${sets}" ]; then 343 if [ -z "${sets}" ]; then
339 utils_info "Skipping postinstall (no etc sets in SETS)" 344 shtk_cli_info "Skipping postinstall (no etc sets in SETS)"
340 return 0 345 return 0
341 fi 346 fi
342 if ! utils_contains etc ${sets}; then 347 if ! shtk_list_contains etc ${sets}; then
343 utils_info "Skipping postinstall (required etc not in SETS)" 348 shtk_cli_info "Skipping postinstall (required etc not in SETS)"
344 return 0 349 return 0
345 fi 350 fi
346 351
347 local sflags= 352 local sflags=
348 for set_name in ${sets}; do 353 for set_name in ${sets}; do
349 require_set "${set_name}" 354 require_set "${set_name}"
350 sflags="${sflags} -s$(get_set "${set_name}")" 355 sflags="${sflags} -s$(get_set "${set_name}")"
351 done 356 done
352 357
353 utils_info "Performing postinstall checks" 358 shtk_cli_info "Performing postinstall checks"
354 local destdir="$(config_get_default DESTDIR "")" 359 local destdir="$(shtk_config_get_default DESTDIR "")"
355 if config_has POSTINSTALL_AUTOFIX; then 360 if shtk_config_has POSTINSTALL_AUTOFIX; then
356 postinstall "-d${destdir}/" ${sflags} fix \ 361 postinstall "-d${destdir}/" ${sflags} fix \
357 $(config_get POSTINSTALL_AUTOFIX) 362 $(shtk_config_get POSTINSTALL_AUTOFIX)
358 fi 363 fi
359 postinstall "-d${destdir}/" ${sflags} "${@:-check}" \ 364 postinstall "-d${destdir}/" ${sflags} "${@:-check}" \
360 || utils_error "Some postinstall(8) checks have failed" 365 || shtk_cli_error "Some postinstall(8) checks have failed"
361} 366}
362 367
363 368
364# Cleans up the cache directory. 369# Cleans up the cache directory.
365sysupgrade_clean() { 370sysupgrade_clean() {
366 [ ${#} -eq 0 ] || utils_usage_error "clean does not take any arguments" 371 [ ${#} -eq 0 ] || shtk_cli_usage_error "clean does not take any arguments"
367 372
368 utils_info "Cleaning downloaded files" 373 shtk_cli_info "Cleaning downloaded files"
369 rm -f "$(config_get CACHEDIR)"/*.tgz* 374 rm -f "$(shtk_config_get CACHEDIR)"/*.tgz*
370} 375}
371 376
372 377
373# Automated upgrade procedure. 378# Automated upgrade procedure.
374# 379#
375# This is just a convenience mechanism to execute all the different steps of the 380# This is just a convenience mechanism to execute all the different steps of the
376# upgrade. 381# upgrade.
377# 382#
378# \param releasedir Optional override of the release directory to use. 383# \param releasedir Optional override of the release directory to use.
379sysupgrade_auto() { 384sysupgrade_auto() {
380 [ ${#} -lt 2 ] \ 385 [ ${#} -lt 2 ] \
381 || utils_usage_error "auto takes zero or one arguments" 386 || shtk_cli_usage_error "auto takes zero or one arguments"
382 387
383 [ -z "${1}" ] || config_set "RELEASEDIR" "${1}" 388 [ -z "${1}" ] || shtk_config_set "RELEASEDIR" "${1}"
384 389
385 local stages= 390 local stages=
386 stages="fetch modules kernel sets" 391 stages="fetch modules kernel sets"
387 config_get_bool "ETCUPDATE" && stages="${stages} etcupdate" 392 shtk_config_get_bool "ETCUPDATE" && stages="${stages} etcupdate"
388 stages="${stages} postinstall" 393 stages="${stages} postinstall"
389 config_get_bool "AUTOCLEAN" && stages="${stages} clean" 394 shtk_config_get_bool "AUTOCLEAN" && stages="${stages} clean"
390 395
391 utils_info "Starting auto-update with stages: ${stages}" 396 shtk_cli_info "Starting auto-update with stages: ${stages}"
392 for stage in ${stages}; do 397 for stage in ${stages}; do
393 sysupgrade_${stage} 398 sysupgrade_${stage}
394 done 399 done
395 400
396 config_get_bool "AUTOCLEAN" || utils_info "Distribution sets not deleted;" \ 401 shtk_config_get_bool "AUTOCLEAN" || shtk_cli_info "Distribution sets not deleted;" \
397 "further ${Utils_ProgName} commands will reuse them" 402 "further $(shtk_cli_progname) commands will reuse them"
398} 403}
399 404
400 405
401# Entry point to the program. 406# Entry point to the program.
402# 407#
403# \param ... Command-line arguments to be processed. 408# \param ... Command-line arguments to be processed.
404# 409#
405# \return An exit code to be returned to the user. 410# \return An exit code to be returned to the user.
406sysupgrade_main() { 411sysupgrade_main() {
407 local config_file="${SYSUPGRADE_ETCDIR}/sysupgrade.conf" 412 local config_file="${SYSUPGRADE_ETCDIR}/sysupgrade.conf"
408 413
409 config_init ${SYSUPGRADE_CONFIG_VARS} 414 shtk_config_init ${SYSUPGRADE_CONFIG_VARS}
410 415
411 while getopts ':c:d:o:' arg "${@}"; do 416 while getopts ':c:d:o:' arg "${@}"; do
412 case "${arg}" in 417 case "${arg}" in
413 c) # Path to the configuration file. 418 c) # Path to the configuration file.
414 config_file="${OPTARG}" 419 config_file="${OPTARG}"
415 ;; 420 ;;
416 421
417 d) # Path to the destdir. 422 d) # Path to the destdir.
418 config_set DESTDIR "${OPTARG}" 423 shtk_config_set DESTDIR "${OPTARG}"
419 ;; 424 ;;
420 425
421 o) # Override for a particular configuration variable. 426 o) # Override for a particular configuration variable.
422 config_override "${OPTARG}" 427 shtk_config_override "${OPTARG}"
423 ;; 428 ;;
424 429
425 \?) 430 \?)
426 utils_usage_error "Unknown option -${OPTARG}" 431 shtk_cli_usage_error "Unknown option -${OPTARG}"
427 ;; 432 ;;
428 esac 433 esac
429 done 434 done
430 shift $((${OPTIND} - 1)) 435 shift $((${OPTIND} - 1))
431 436
432 [ ${#} -ge 1 ] || utils_usage_error "No command specified" 437 [ ${#} -ge 1 ] || shtk_cli_usage_error "No command specified"
433 438
434 local exit_code=0 439 local exit_code=0
435 440
436 local command="${1}"; shift 441 local command="${1}"; shift
437 case "${command}" in 442 case "${command}" in
438 auto|clean|etcupdate|fetch|kernel|modules|sets|postinstall) 443 auto|clean|etcupdate|fetch|kernel|modules|sets|postinstall)
439 sysupgrade_set_defaults 444 sysupgrade_set_defaults
440 config_load "${config_file}" 445 shtk_config_load "${config_file}"
441 sysupgrade_auto_config 446 sysupgrade_auto_config
442 "sysupgrade_$(echo "${command}" | tr - _)" "${@}" \ 447 "sysupgrade_$(echo "${command}" | tr - _)" "${@}" \
443 || exit_code="${?}" 448 || exit_code="${?}"
444 ;; 449 ;;
445 450
446 config) 451 config)
447 sysupgrade_set_defaults 452 sysupgrade_set_defaults
448 config_load "${config_file}" 453 shtk_config_load "${config_file}"
449 "sysupgrade_$(echo "${command}" | tr - _)" "${@}" \ 454 "sysupgrade_$(echo "${command}" | tr - _)" "${@}" \
450 || exit_code="${?}" 455 || exit_code="${?}"
451 ;; 456 ;;
452 457
453 *) 458 *)
454 utils_usage_error "Unknown command ${command}" 459 shtk_cli_usage_error "Unknown command ${command}"
455 ;; 460 ;;
456 esac 461 esac
457 462
458 return "${exit_code}" 463 return "${exit_code}"
459} 464}

cvs diff -r1.1 -r1.2 pkgsrc/sysutils/sysupgrade/files/Attic/sysupgrade_test.sh (expand / switch to unified diff)

--- pkgsrc/sysutils/sysupgrade/files/Attic/sysupgrade_test.sh 2012/08/06 17:06:17 1.1
+++ pkgsrc/sysutils/sysupgrade/files/Attic/sysupgrade_test.sh 2012/08/15 21:21:15 1.2
@@ -1,13 +1,14 @@ @@ -1,13 +1,14 @@
 1#! @ATF_SH@
1# Copyright 2012 Google Inc. 2# Copyright 2012 Google Inc.
2# All rights reserved. 3# All rights reserved.
3# 4#
4# Redistribution and use in source and binary forms, with or without 5# Redistribution and use in source and binary forms, with or without
5# modification, are permitted provided that the following conditions are 6# modification, are permitted provided that the following conditions are
6# met: 7# met:
7# 8#
8# * Redistributions of source code must retain the above copyright 9# * Redistributions of source code must retain the above copyright
9# notice, this list of conditions and the following disclaimer. 10# notice, this list of conditions and the following disclaimer.
10# * Redistributions in binary form must reproduce the above copyright 11# * Redistributions in binary form must reproduce the above copyright
11# notice, this list of conditions and the following disclaimer in the 12# notice, this list of conditions and the following disclaimer in the
12# documentation and/or other materials provided with the distribution. 13# documentation and/or other materials provided with the distribution.
13# * Neither the name of Google Inc. nor the names of its contributors 14# * Neither the name of Google Inc. nor the names of its contributors

File Deleted: pkgsrc/sysutils/sysupgrade/files/Attic/config.subr

File Deleted: pkgsrc/sysutils/sysupgrade/files/Attic/config_test.sh

File Deleted: pkgsrc/sysutils/sysupgrade/files/Attic/utils.subr

File Deleted: pkgsrc/sysutils/sysupgrade/files/Attic/utils_test.sh