diff options
author | Antoine Jacoutot <ajacoutot@cvs.openbsd.org> | 2010-07-05 08:30:29 +0000 |
---|---|---|
committer | Antoine Jacoutot <ajacoutot@cvs.openbsd.org> | 2010-07-05 08:30:29 +0000 |
commit | 777fc166cdfa04286109c8b8a32ab7e979bfb65b (patch) | |
tree | f0a9f6bb5f4d6d230fe7c66d5514c2548fb4be19 /usr.sbin/sysmerge | |
parent | bec5f3b3bb1a8472c016dc94caea26f44c8390bf (diff) |
Automatically install missing users and groups.
(does *NOT* touch existing users/groups)
"I like it" from several...
inputs from sthen@ and halex@
ok krw@ halex@ sthen@
Diffstat (limited to 'usr.sbin/sysmerge')
-rw-r--r-- | usr.sbin/sysmerge/sysmerge.8 | 12 | ||||
-rw-r--r-- | usr.sbin/sysmerge/sysmerge.sh | 67 |
2 files changed, 74 insertions, 5 deletions
diff --git a/usr.sbin/sysmerge/sysmerge.8 b/usr.sbin/sysmerge/sysmerge.8 index 76e4b5a26c0..5bd1c645ef1 100644 --- a/usr.sbin/sysmerge/sysmerge.8 +++ b/usr.sbin/sysmerge/sysmerge.8 @@ -1,4 +1,4 @@ -.\" $OpenBSD: sysmerge.8,v 1.31 2010/03/20 09:45:11 ajacoutot Exp $ +.\" $OpenBSD: sysmerge.8,v 1.32 2010/07/05 08:30:28 ajacoutot Exp $ .\" .\" Copyright (c) 2008 Antoine Jacoutot <ajacoutot@openbsd.org> .\" @@ -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: March 20 2010 $ +.Dd $Mdocdate: July 5 2010 $ .Dt SYSMERGE 8 .Os .Sh NAME @@ -108,6 +108,12 @@ and are created using helper scripts and are .Sy always compared. +Users and groups that are missing from the current installation but +present in the new +.Xr master.passwd 5 +and +.Xr group 5 +files will be automatically created. .Pp .Nm will finish by running @@ -240,10 +246,12 @@ Files and directories to ignore from comparison. .El .Sh SEE ALSO .Xr cap_mkdb 1 , +.Xr chpass 1 , .Xr diff 1 , .Xr mktemp 1 , .Xr more 1 , .Xr sdiff 1 , +.Xr groupadd 8 , .Xr MAKEDEV 8 , .Xr makemap 8 , .Xr mtree 8 , diff --git a/usr.sbin/sysmerge/sysmerge.sh b/usr.sbin/sysmerge/sysmerge.sh index 9c404bd62e9..2d94dc0c9cd 100644 --- a/usr.sbin/sysmerge/sysmerge.sh +++ b/usr.sbin/sysmerge/sysmerge.sh @@ -1,6 +1,6 @@ #!/bin/ksh - # -# $OpenBSD: sysmerge.sh,v 1.58 2010/06/27 00:07:22 ajacoutot Exp $ +# $OpenBSD: sysmerge.sh,v 1.59 2010/07/05 08:30:28 ajacoutot Exp $ # # Copyright (c) 1998-2003 Douglas Barton <DougB@FreeBSD.org> # Copyright (c) 2008, 2009, 2010 Antoine Jacoutot <ajacoutot@openbsd.org> @@ -21,8 +21,8 @@ umask 0022 unset AUTO_INSTALLED_FILES BATCHMODE DIFFMODE ETCSUM NEED_NEWALIASES -unset NEED_REBOOT OBSOLETE_FILES SRCDIR SRCSUM TGZ TGZURL XETCSUM XTGZ -unset XTGZURL +unset NEWGRP NEWUSR NEED_REBOOT OBSOLETE_FILES SRCDIR SRCSUM TGZ TGZURL +unset XETCSUM XTGZ XTGZURL WRKDIR=`mktemp -d -p ${TMPDIR:=/var/tmp} sysmerge.XXXXX` || exit 1 SWIDTH=`stty size | awk '{w=$2} END {if (w==0) {w=80} print w}'` @@ -412,6 +412,57 @@ diff_loop() { fi return fi + # automatically install missing users + if [ "${COMPFILE}" = "./etc/master.passwd" ]; then + local _merge_pwd + while read l; do + _u=`echo ${l} | awk -F ':' '{ print $1 }'` + if [ "${_u}" != "root" ]; then + if [ -z "`grep -E "^${_u}:" ${DESTDIR}${COMPFILE#.}`" ]; then + echo "===> Adding the ${_u} user" + if [ "${DESTDIR}" ]; then + chroot ${DESTDIR} chpass -la "${l}" + else + chpass -la "${l}" + fi + if [ $? -eq 0 ]; then + set -A NEWUSR -- ${NEWUSR[@]} ${_u} + else + _merge_pwd=1 + fi + fi + fi + done < ${COMPFILE} + if [ -z ${_merge_pwd} ]; then + rm "${TEMPROOT}${COMPFILE#.}" + return + fi + fi + # automatically install missing groups + if [ "${COMPFILE}" = "./etc/group" ]; then + local _merge_grp + while read l; do + _g=`echo ${l} | awk -F ':' '{ print $1 }'` + _gid=`echo ${l} | awk -F ':' '{ print $3 }'` + if [ -z "`grep -E "^${_g}:" ${DESTDIR}${COMPFILE#.}`" ]; then + echo "===> Adding the ${_g} group" + if [ "${DESTDIR}" ]; then + chroot ${DESTDIR} groupadd -g "${_gid}" "${_g}" + else + groupadd -g "${_gid}" "${_g}" + fi + if [ $? -eq 0 ]; then + set -A NEWGRP -- ${NEWGRP[@]} ${_g} + else + _merge_grp=1 + fi + fi + done < ${COMPFILE} + if [ -z ${_merge_grp} ]; then + rm "${TEMPROOT}${COMPFILE#.}" + return + fi + fi fi if [ "${HANDLE_COMPFILE}" = "v" ]; then ( @@ -606,6 +657,16 @@ do_post() { echo "===> File(s) removed from previous source (maybe obsolete)" >> ${REPORT} echo "${OBSOLETE_FILES}" >> ${REPORT} fi + if [ "${NEWUSR}" -o "${NEWGRP}" ]; then + echo "===> The following user(s)/group(s) have been added" >> ${REPORT} + if [ "${NEWUSR}" ]; then + echo -n "user(s): ${NEWUSR[@]}\n" >> ${REPORT} + fi + if [ "${NEWGRP}" ]; then + echo -n "group(s): ${NEWGRP[@]}\n" >> ${REPORT} + fi + echo "" >> ${REPORT} + fi if [ "${FILES_IN_TEMPROOT}" ]; then echo "===> File(s) remaining for you to merge by hand" >> ${REPORT} echo "${FILES_IN_TEMPROOT}" >> ${REPORT} |