tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Two improvements to etcupdate(8)



> So I added a ``bootstrap'' mode (-A) that only builds the checksums from its 
> -s arguments and doesn't do anything else.
Ouch, I checksummed the wrong files (the installed ones, not the one in 
temproot). Unfortunately, the files in /var/etcupdate contain the full 
output of the ma5d command (including the filename) and are compared verbatim, 
so one needs to massage the md5 output to fake the filename.
Corrected patch included.
--- etcupdate	2016-01-27 11:26:42.000000000 +0100
+++ etcupdate-A	2016-02-15 14:25:14.000000000 +0100
@@ -63,6 +63,7 @@
 SRC_ARGLIST=		# quoted list of one or more "-s" args
 N_SRC_ARGS=0		# number of "-s" args
 AUTOMATIC=false
+BOOT_AUTOMATIC=false
 LOCALSKIP=false
 MACHINE="${MACHINE:="$(uname -m)"}"
 export MACHINE
@@ -96,6 +97,8 @@
   -t temproot  Where to store temporary files  (default: /tmp/temproot)
   -w width     Screen width                    (default: 80)
   -a           Automatically update unmodified files
+  -A           Bootstrap automatic mode: Initialize reference checksums
+               from -s arguments
   -l           Automatically skip files with strictly local changes
                (this option has no effect on files lacking RCS Ids)
   -h           This help text
@@ -412,12 +415,15 @@
 [ -r ${USERRC} ] && . ${USERRC}
 
 # Read command line arguments
-while getopts ahlp:s:t:vw: i
+while getopts aAhlp:s:t:vw: i
 do
 	case "${i}" in
 	a)
 		AUTOMATIC=true
 		;;
+	A)
+		BOOT_AUTOMATIC=true
+		;;
 	h)
 		usage
 		;;
@@ -520,6 +526,13 @@
 	exit 1
 fi
 if [ -r "${TEMPROOT}" ]; then
+	if ${BOOT_AUTOMATIC}; then
+		echo ""
+		echo "*** ERROR: ${TEMPROOT} already exists"
+		echo ""
+		exit 1
+	else
+	#>indent
 	echo ""
 	echo "*** WARNING: ${TEMPROOT} already exists"
 	echo ""
@@ -529,6 +542,8 @@
 		echo "*** Removing ${TEMPROOT}"
 		rm -rf "${TEMPROOT}"
 	fi
+	#<indent
+	fi
 fi
 
 if ! ${CONTINUE}; then
@@ -599,6 +614,25 @@
 		done
 	fi
 
+	if ${BOOT_AUTOMATIC}; then
+		echo "*** Initializing checksums"
+		find "${TEMPROOT}" -type f  -a ! -name \*.etcupdate.\* | \
+		while read i; do
+			F="${i#"${TEMPROOT}"}"
+			D="$(dirname "${F}")"
+			mkdir -p "/var/etcupdate/${D}"
+			verbose "Saving original MD5 checksum for ${F} to /var/etcupdate/${F}"
+			# unfortunately, the files in /var/etcupdate contain the plain output of the md5 command, including the filename
+			SUM1="$(md5 "${i}")"
+			SUM1="${SUM1##*= }"
+			printf "MD5 (%s) = %s\n" "$F" "$SUM1" > "/var/etcupdate/${F}"
+		done
+		echo "*** Removing ${TEMPROOT}"
+		rm -rf "${TEMPROOT}"
+		echo "*** Done"
+		exit 0
+	fi
+
 	# Are there any new directories?
 	echo "*** Checking for new directories"
 	exec 3<&0


Home | Main Index | Thread Index | Old Index