changeset 389:5b491c71f689

* Move /etc/save_rc to /etc/rc.save_config. * Introduce /etc/rc.restore_config and invoke it in startup scripts, instead of use same code in several places. * Remove try to save /etc on shutdown. (It is undesirable for network boxes) Submitted by: Gordon Shumway
author Aleksandr Rybalko <ray@ddteam.net>
date Sat, 21 Apr 2012 15:09:58 +0300
parents a95f08196f9a
children bd7977a03670
files profiles/SMALL_/files/etc/buttons/WDS.sh profiles/SMALL_/files/etc/defaults/rc.conf profiles/SMALL_/files/etc/rc.d/MAIN profiles/SMALL_/files/etc/rc.d/mountcritlocal profiles/SMALL_/files/etc/rc.restore_config profiles/SMALL_/files/etc/rc.save_config profiles/SMALL_/files/etc/rc.shutdown profiles/SMALL_/files/etc/rc.subr profiles/SMALL_/files/etc/rc.zsubr profiles/SMALL_/files/etc/save_etc profiles/SMALL_/profile.mk
diffstat 11 files changed, 108 insertions(+), 78 deletions(-) [+]
line wrap: on
line diff
--- a/profiles/SMALL_/files/etc/buttons/WDS.sh	Tue Apr 17 17:44:28 2012 +0300
+++ b/profiles/SMALL_/files/etc/buttons/WDS.sh	Sat Apr 21 15:09:58 2012 +0300
@@ -1,13 +1,4 @@
 #!/bin/sh
 
-echo f1 > /dev/led/status
+/etc/rc.save_config
 
-cd /tmp
-echo "Dumping etc to tar.gz"
-/usr/bin/tar cv --exclude '*pwd.db' -zf /tmp/etc.tar.gz etc/* -C /tmp
-echo "Saving /etc"
-/bin/dd if=/tmp/etc.tar.gz of=/dev/map/rgdb bs=64k count=1 conv=sync
-echo '.'
-
-echo f9 > /dev/led/status
-
--- a/profiles/SMALL_/files/etc/defaults/rc.conf	Tue Apr 17 17:44:28 2012 +0300
+++ b/profiles/SMALL_/files/etc/defaults/rc.conf	Sat Apr 21 15:09:58 2012 +0300
@@ -382,3 +382,6 @@
 		done
 	}
 fi
+zconfig_partitions="/dev/map/config /dev/redboot/config"
+zconfig_exclude_files="pwd.db spwd.db login.conf.db"
+zconfig_temp_file="/tmp/etc.tar.gz"
--- a/profiles/SMALL_/files/etc/rc.d/MAIN	Tue Apr 17 17:44:28 2012 +0300
+++ b/profiles/SMALL_/files/etc/rc.d/MAIN	Sat Apr 21 15:09:58 2012 +0300
@@ -33,4 +33,4 @@
 
 load_rc_config $name
 
-run_rc_command $*
\ No newline at end of file
+run_rc_command $*
--- a/profiles/SMALL_/files/etc/rc.d/mountcritlocal	Tue Apr 17 17:44:28 2012 +0300
+++ b/profiles/SMALL_/files/etc/rc.d/mountcritlocal	Sat Apr 21 15:09:58 2012 +0300
@@ -21,22 +21,14 @@
 	mkdir -p /tmp/var/log
 	mkdir -p /tmp/var/run
 	mkdir -p /tmp/var/spool/lock
+	mkdir -p /tmp/var/tmp
 	touch /tmp/var/log/all.log
 
 	mount_unionfs /tmp/etc /etc
 
-	if [ -c /dev/map/config ]; then
-		dd if=/dev/map/config of=/tmp/etc.tar.gz;
-		cd /tmp/ && tar xvzf /tmp/etc.tar.gz
-	else
-		if [ -c /dev/redboot/config ]; then
-			dd if=/dev/redboot/config of=/tmp/etc.tar.gz;
-			cd /tmp/ && tar xvzf /tmp/etc.tar.gz
-		fi
-	fi
-
+	/etc/rc.restore_config
 }
 
 load_rc_config $name
 
-run_rc_command $*
\ No newline at end of file
+run_rc_command $*
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/profiles/SMALL_/files/etc/rc.restore_config	Sat Apr 21 15:09:58 2012 +0300
@@ -0,0 +1,24 @@
+#!/bin/sh
+
+PATH=/bin:/sbin:/usr/bin:/usr/sbin
+
+. /etc/rc.subr
+
+name="restore_config"
+load_rc_config "$name"
+
+CONFIG_PART=$( get_config_part )
+
+if [ "${CONFIG_PART}" ]; then
+	debug "Restoring config from ${CONFIG_PART}"
+
+	dd if=${CONFIG_PART} of=${zconfig_temp_file}
+	tar -C /tmp -xvzf ${zconfig_temp_file}
+	rm -f ${zconfig_temp_file}
+
+	debug "."
+fi
+
+pwd_mkdb /etc/master.passwd
+cap_mkdb /etc/login.conf
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/profiles/SMALL_/files/etc/rc.save_config	Sat Apr 21 15:09:58 2012 +0300
@@ -0,0 +1,55 @@
+#!/bin/sh
+
+PATH=/bin:/sbin:/usr/bin:/usr/sbin
+BLOCK_SIZE=64
+
+. /etc/rc.subr
+
+name="save_config"
+load_rc_config "$name"
+
+CONFIG_PART=$( get_config_part )
+if [ -z "${CONFIG_PART}" ]; then
+	err 1 'No config partition found'
+fi
+
+exclude=
+if [ "${zconfig_exclude_files}" ]; then
+	for i in ${zconfig_exclude_files}; do
+		exclude="${exclude:+$exclude }--exclude=etc/${i}"
+	done
+fi
+
+set -- $( ${SYSCTL_N} kern.geom.conftxt | grep -F "${CONFIG_PART#/dev/}" )
+CONFIG_PART_SIZE=$4
+set --
+
+debug "Saving /etc to etc.tar.gz"
+tar ${exclude} -cvzf ${zconfig_temp_file} -C /tmp etc
+
+set -- $( ls -l ${zconfig_temp_file} )
+size=$5
+set --
+if [ ${size} -gt ${CONFIG_PART_SIZE} ]; then
+	rm -f ${zconfig_temp_file}
+	err 1 "${zconfig_temp_file##*/} too big: ${size}; must be less than ${CONFIG_PART_SIZE}"
+fi
+CONFIG_PART_BLKS=$(( ${CONFIG_PART_SIZE} / ${BLOCK_SIZE} / 1024 ))
+
+debug "Saving /etc to ${CONFIG_PART}"
+
+# echo f1 > /dev/led/status
+
+${SYSCTL_W} hw.cfi.rdonly=0 2>/dev/null
+dd if=${zconfig_temp_file} of=${CONFIG_PART} bs=${BLOCK_SIZE}k \
+	count=${CONFIG_PART_BLKS} conv=sync
+${SYSCTL_W} hw.cfi.rdonly=1 2>/dev/null
+
+if [ -f ${zconfig_temp_file} ]; then
+	rm -f ${zconfig_temp_file}
+fi
+
+# echo f9 > /dev/led/status
+
+debug "."
+
--- a/profiles/SMALL_/files/etc/rc.shutdown	Tue Apr 17 17:44:28 2012 +0300
+++ b/profiles/SMALL_/files/etc/rc.shutdown	Sat Apr 21 15:09:58 2012 +0300
@@ -43,19 +43,6 @@
 	pkill -TERM -P $_rcshutdown_watchdog >/dev/null 2>&1
 fi
 
-/bin/rm -f /etc/pwd.db
-/bin/rm -f /etc/spwd.db
-/usr/bin/tar czf /tmp/etc.tar.gz etc/* -C /tmp
-#dd if=/dev/mtd/rgdb /tmp/rgdb bs=65536 count=1
-#md5etc=`md5 /tmp/etc.tar.gz`
-#md5mtdetc=`md5 /tmp/rgdb`
-#if [ ${md5etc} != ${md5mtdetc}]; then
-echo "Saving /etc"
-/bin/dd if=/tmp/etc.tar.gz of=/dev/mtd/rgdb bs=64k count=1 conv=sync
-echo '.'
-#fi
-
-
 echo '.'
 # Kill unbreakable oinit
 kill -INT 1
--- a/profiles/SMALL_/files/etc/rc.subr	Tue Apr 17 17:44:28 2012 +0300
+++ b/profiles/SMALL_/files/etc/rc.subr	Sat Apr 21 15:09:58 2012 +0300
@@ -1253,6 +1253,8 @@
 	return 0
 }
 
+. /etc/rc.zsubr
+
 fi
 
 _echoonce()
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/profiles/SMALL_/files/etc/rc.zsubr	Sat Apr 21 15:09:58 2012 +0300
@@ -0,0 +1,17 @@
+
+if [ -z "${_rc_zsubr_loaded}" ]; then
+
+_rc_zsubr_loaded="YES"
+
+get_config_part()
+{
+	for p in ${zconfig_partitions}; do
+		if [ -c ${p} ]; then
+			echo ${p}
+			break
+		fi
+	done
+}
+
+fi
+
--- a/profiles/SMALL_/files/etc/save_etc	Tue Apr 17 17:44:28 2012 +0300
+++ b/profiles/SMALL_/files/etc/save_etc	Sat Apr 21 15:09:58 2012 +0300
@@ -1,46 +1,4 @@
 #!/bin/sh
 
-if [ -c /dev/map/config ]; then
-	DEVCONFIG=/dev/map/config
-fi
-if [ -c /dev/redboot/config ]; then
-	DEVCONFIG=/dev/reboot/config
-fi
-if [ "x${DEVCONFIG}" == "x" ]; then
-	echo "No config partiton found";
-	exit 1;
-fi
-
-BLOCK_SIZE=64
-GEOM_PART=`echo ${DEVCONFIG} | sed 's/\/dev\///; s!\/!\\\/!' `
-
-i=0
-for s in `sysctl kern.geom.conftxt | grep "${GEOM_PART}"` ; do
-	i=$(( ${i} + 1 )) ;
-	if [ ${i} == 4 ] ; then
-    		DEVCONFIGSIZE=${s} ;
-	fi ;
-done
+echo "Use /etc/rc.save_config instead"
 
-DEVCONFIGBLKS=$((${DEVCONFIGSIZE} / ${BLOCK_SIZE} / 1024))
-
-#echo f1 > /dev/led/status
-cd /tmp
-echo "Dumping etc to etc.tar.gz"
-/usr/bin/tar cv --exclude '*pwd.db' -zf /tmp/etc.tar.gz etc/* -C /tmp
-
-lsline=`ls -l /tmp/etc.tar.gz`
-script="arg5() echo \$5; arg5 ${lsline}"
-size=`sh -c "${script}"`
-if [ ${size} -gt ${DEVCONFIGSIZE} ]; then
-	echo "etc.tar.gz too big ${size}, must be less than ${DEVCONFIGSIZE}"
-	echo "Please remove big files from /etc"
-	exit 1
-fi
-
-echo "Saving /etc"
-sysctl hw.cfi.rdonly=0
-/bin/dd if=/tmp/etc.tar.gz of=${DEVCONFIG} bs=${BLOCK_SIZE}k count=${DEVCONFIGBLKS} conv=sync
-echo '.'
-
-#echo f9 > /dev/led/status
--- a/profiles/SMALL_/profile.mk	Tue Apr 17 17:44:28 2012 +0300
+++ b/profiles/SMALL_/profile.mk	Sat Apr 21 15:09:58 2012 +0300
@@ -109,6 +109,7 @@
 
 WORLD_SUBDIRS_USR_BIN+= \
 basename \
+cap_mkdb \
 dirname \
 fetch \
 find \