changeset 390:bd7977a03670

* 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:10:17 +0300
parents 5b491c71f689
children 81194d5b1c9f
files profiles/xSMALL_/files/etc/buttons/WDS.sh profiles/xSMALL_/files/etc/defaults/rc.conf profiles/xSMALL_/files/etc/rc.d/MAIN profiles/xSMALL_/files/etc/rc.d/mountcritlocal profiles/xSMALL_/files/etc/rc.restore_config profiles/xSMALL_/files/etc/rc.save_config profiles/xSMALL_/files/etc/rc.shutdown profiles/xSMALL_/files/etc/rc.subr profiles/xSMALL_/files/etc/rc.zsubr profiles/xSMALL_/files/etc/save_etc profiles/xSMALL_/profile.mk
diffstat 11 files changed, 142 insertions(+), 63 deletions(-) [+]
line wrap: on
line diff
--- a/profiles/xSMALL_/files/etc/buttons/WDS.sh	Sat Apr 21 15:09:58 2012 +0300
+++ b/profiles/xSMALL_/files/etc/buttons/WDS.sh	Sat Apr 21 15:10:17 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/xSMALL_/files/etc/defaults/rc.conf	Sat Apr 21 15:09:58 2012 +0300
+++ b/profiles/xSMALL_/files/etc/defaults/rc.conf	Sat Apr 21 15:10:17 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/xSMALL_/files/etc/rc.d/MAIN	Sat Apr 21 15:09:58 2012 +0300
+++ b/profiles/xSMALL_/files/etc/rc.d/MAIN	Sat Apr 21 15:10:17 2012 +0300
@@ -38,6 +38,8 @@
 		cd /tmp/ && tar xvzf /tmp/etc.tar.gz
 	fi
 
+	pwd_mkdb /etc/master.passwd
+
 	ifconfig lo0 127.0.0.1/8
 	#ifconfig rt0 192.168.0.28/24
 	mpd  --background
@@ -56,14 +58,9 @@
 
 main_stop()
 {
-	if [ -c /dev/map/config ]; then
-		cd /tmp/ && tar cvzf /tmp/etc.tar.gz etc/* ;
-		sysctl hw.cfi.rdonly=0
-		dd if=/tmp/etc.tar.gz of=/dev/map/config bs=64k conv=sync ;
-		sysctl hw.cfi.rdonly=1
-	fi
+	/etc/rc.save_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/xSMALL_/files/etc/rc.d/mountcritlocal	Sat Apr 21 15:10:17 2012 +0300
@@ -0,0 +1,34 @@
+#!/bin/sh
+
+# PROVIDE: mountcritlocal
+
+. /etc/rc.subr
+. /etc/network.subr
+
+name="MAIN"
+start_cmd="mountcritlocal_start"
+
+mountcritlocal_start()
+{
+	# XXX: check TMPFS again
+	# XXX: get useful size: small for /etc or big for upgrade
+	md=`/sbin/mdconfig -a -t malloc -s 10m`
+	newfs -b 4096 -f 512 -n -o space /dev/${md} > /dev/null
+	mount /dev/${md} /tmp
+
+	mkdir -p /tmp/etc
+	mkdir -p /tmp/var/empty
+	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
+
+	/etc/rc.restore_config
+}
+
+load_rc_config $name
+
+run_rc_command $*
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/profiles/xSMALL_/files/etc/rc.restore_config	Sat Apr 21 15:10:17 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/xSMALL_/files/etc/rc.save_config	Sat Apr 21 15:10:17 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/xSMALL_/files/etc/rc.shutdown	Sat Apr 21 15:09:58 2012 +0300
+++ b/profiles/xSMALL_/files/etc/rc.shutdown	Sat Apr 21 15:10:17 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/xSMALL_/files/etc/rc.subr	Sat Apr 21 15:09:58 2012 +0300
+++ b/profiles/xSMALL_/files/etc/rc.subr	Sat Apr 21 15:10:17 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/xSMALL_/files/etc/rc.zsubr	Sat Apr 21 15:10:17 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/xSMALL_/files/etc/save_etc	Sat Apr 21 15:09:58 2012 +0300
+++ b/profiles/xSMALL_/files/etc/save_etc	Sat Apr 21 15:10:17 2012 +0300
@@ -1,36 +1,4 @@
 #!/bin/sh
 
-DEVCONFIG=/dev/map/config
-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
-
-DEVCONFIGBLKS=$((${DEVCONFIGSIZE} / ${BLOCK_SIZE} / 1024))
+echo "Use /etc/rc.save_config instead"
 
-#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=/dev/map/config bs=${BLOCK_SIZE}k count=${DEVCONFIGBLKS} conv=sync
-echo '.'
-
-#echo f9 > /dev/led/status
--- a/profiles/xSMALL_/profile.mk	Sat Apr 21 15:09:58 2012 +0300
+++ b/profiles/xSMALL_/profile.mk	Sat Apr 21 15:10:17 2012 +0300
@@ -123,6 +123,7 @@
 
 WORLD_SUBDIRS_USR_BIN+= \
 basename \
+cap_mkdb \
 dirname \
 fetch \
 find \