From: ajacoutot Date: Sat, 12 Jul 2014 15:31:54 +0000 (+0000) Subject: Initial support for /etc/examples. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=a5463bcbaa6eca4a1f81e7d8838a6c306857018b;p=openbsd Initial support for /etc/examples. --- diff --git a/usr.sbin/sysmerge/sysmerge.8 b/usr.sbin/sysmerge/sysmerge.8 index ac8d3cd9170..51345cf0d1c 100644 --- a/usr.sbin/sysmerge/sysmerge.8 +++ b/usr.sbin/sysmerge/sysmerge.8 @@ -1,4 +1,4 @@ -.\" $OpenBSD: sysmerge.8,v 1.46 2014/07/10 11:00:03 ajacoutot Exp $ +.\" $OpenBSD: sysmerge.8,v 1.47 2014/07/12 15:31:54 ajacoutot Exp $ .\" .\" Copyright (c) 2008 Antoine Jacoutot .\" @@ -14,7 +14,7 @@ .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd $Mdocdate: July 10 2014 $ +.Dd $Mdocdate: July 12 2014 $ .Dt SYSMERGE 8 .Os .Sh NAME @@ -121,6 +121,12 @@ files will .Sy always be automatically (re)created. .Pp +Each time +.Nm +is run, it will compare the checksum of the files stored under +.Pa /etc/examples +against the previous run and warn if they do not match. +.Pp .Nm will finish by running .Xr mtree 8 diff --git a/usr.sbin/sysmerge/sysmerge.sh b/usr.sbin/sysmerge/sysmerge.sh index 83c237c7da7..3ed9e6ccfe3 100644 --- a/usr.sbin/sysmerge/sysmerge.sh +++ b/usr.sbin/sysmerge/sysmerge.sh @@ -1,6 +1,6 @@ #!/bin/ksh - # -# $OpenBSD: sysmerge.sh,v 1.134 2014/07/10 11:00:03 ajacoutot Exp $ +# $OpenBSD: sysmerge.sh,v 1.135 2014/07/12 15:31:54 ajacoutot Exp $ # # Copyright (c) 2008-2014 Antoine Jacoutot # Copyright (c) 1998-2003 Douglas Barton @@ -20,8 +20,8 @@ umask 0022 -unset AUTO_INSTALLED_FILES BATCHMODE DIFFMODE ETCSUM NEED_NEWALIASES NEWGRP -unset NEWUSR NEED_REBOOT NOSIGCHECK SRCDIR SRCSUM TGZ XETCSUM XTGZ +unset AUTO_INSTALLED_FILES BATCHMODE DIFFMODE EGSUM ETCSUM NEED_NEWALIASES +unset NEWGRP NEWUSR NEED_REBOOT NOSIGCHECK SRCDIR SRCSUM TGZ XETCSUM XTGZ # forced variables WRKDIR=$(mktemp -d -p ${TMPDIR:=/var/tmp} sysmerge.XXXXXXXXXX) || exit 1 @@ -51,7 +51,7 @@ clean_src() { # they did not exist restore_sum() { local i _i - for i in ${DESTDIR}/${DBDIR}/.{${SRCSUM},${ETCSUM},${XETCSUM}}.bak; do + for i in ${DESTDIR}/${DBDIR}/.{${SRCSUM},${ETCSUM},${XETCSUM},${EGSUM}}.bak; do _i=$(basename ${i} .bak) if [ -f "${i}" ]; then mv ${i} ${DESTDIR}/${DBDIR}/${_i#.} @@ -77,6 +77,8 @@ report() { # remove newly created work directory and exit with status 1 error_rm_wrkdir() { (($#)) && echo "**** ERROR: $@" + restore_sum + clean_src # do not remove the entire WRKDIR in case sysmerge stopped half # way since it contains our backup files rm -rf ${TEMPROOT} @@ -86,7 +88,7 @@ error_rm_wrkdir() { exit 1 } -trap "restore_sum; clean_src; error_rm_wrkdir; exit 1" 1 2 3 13 15 +trap "error_rm_wrkdir; exit 1" 1 2 3 13 15 if (($(id -u) != 0)); then usage @@ -549,7 +551,7 @@ diff_loop() { fi ;; '') - echo "\n===> ${COMPFILE} will remain for your consideration" + echo "===> ${COMPFILE} will remain for your consideration" ;; *) echo "invalid choice: ${HANDLE_COMPFILE}\n" @@ -627,6 +629,33 @@ sm_compare() { done } +sm_check_an_eg() { + EGSUM=egsum + local _egmods _i _managed + if [ -f "${DESTDIR}/${DBDIR}/${EGSUM}" ]; then + EGMODS="$(sha256 -c ${DESTDIR}/${DBDIR}/${EGSUM} 2>/dev/null | grep 'FAILED$' | awk '{ print $2 }' | sed -e "s,:,,")" + mv ${DESTDIR}/${DBDIR}/${EGSUM} ${DESTDIR}/${DBDIR}/.${EGSUM}.bak + fi + for _i in ${EGMODS}; do + _managed=$(echo ${_i} | sed -e "s,etc/examples,etc,") + if [ -f "${DESTDIR}/${_managed}" ]; then + _egmods="${_egmods} ${_managed##*/}" + fi + done + if [ -n "${_egmods}" ]; then + warn "example file(s) changed for:${_egmods}" + else + # example changed but we have no corresponding file under /etc + unset EGMODS + fi + cd ${DESTDIR:=/} && \ + find ./etc/examples -type f | xargs sha256 -h ${DESTDIR}/${DBDIR}/${EGSUM} || \ + error_rm_wrkdir "failed to create ${EGSUM} checksum file" + if [ -f "${DESTDIR}/${DBDIR}/.${EGSUM}.bak" ]; then + rm ${DESTDIR}/${DBDIR}/.${EGSUM}.bak + fi +} + sm_post() { local FILES_IN_TEMPROOT FILES_IN_BKPDIR @@ -657,6 +686,11 @@ sm_post() { [[ -n ${NEWGRP} ]] && report "group(s): ${NEWGRP[@]}" report "" fi + if [ -n "${EGMODS}" ]; then + report "===> Example(s) modified since last run" + report "${EGMODS}" + report "" + fi if [ -n "${FILES_IN_TEMPROOT}" ]; then report "===> File(s) remaining for you to merge by hand" report "${FILES_IN_TEMPROOT}" @@ -748,4 +782,5 @@ BKPDIR="${WRKDIR}/backups" sm_fetch_and_verify sm_populate sm_compare +sm_check_an_eg sm_post