[Zrouter-src] ZRouter.org: push to ZRouter profiles/xSMALL_/files/etc/buttons/...

zrouter-src at zrouter.org zrouter-src at zrouter.org
Sat Apr 21 12:09:53 UTC 2012


details:   http://zrouter.org/hg/zrouter//rev/bd7977a03670
changeset: 390:bd7977a03670
user:      Aleksandr Rybalko <ray at ddteam.net>
date:      Sat Apr 21 15:10:17 2012 +0300
description:
* 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

diffstat:

 profiles/xSMALL_/files/etc/buttons/WDS.sh      |  11 +----
 profiles/xSMALL_/files/etc/defaults/rc.conf    |   3 +
 profiles/xSMALL_/files/etc/rc.d/MAIN           |  11 +---
 profiles/xSMALL_/files/etc/rc.d/mountcritlocal |  34 ++++++++++++++++
 profiles/xSMALL_/files/etc/rc.restore_config   |  24 +++++++++++
 profiles/xSMALL_/files/etc/rc.save_config      |  55 ++++++++++++++++++++++++++
 profiles/xSMALL_/files/etc/rc.shutdown         |  13 ------
 profiles/xSMALL_/files/etc/rc.subr             |   2 +
 profiles/xSMALL_/files/etc/rc.zsubr            |  17 ++++++++
 profiles/xSMALL_/files/etc/save_etc            |  34 +---------------
 profiles/xSMALL_/profile.mk                    |   1 +
 11 files changed, 142 insertions(+), 63 deletions(-)

diffs (291 lines):

diff -r 5b491c71f689 -r bd7977a03670 profiles/xSMALL_/files/etc/buttons/WDS.sh
--- 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
-
diff -r 5b491c71f689 -r bd7977a03670 profiles/xSMALL_/files/etc/defaults/rc.conf
--- 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"
diff -r 5b491c71f689 -r bd7977a03670 profiles/xSMALL_/files/etc/rc.d/MAIN
--- 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 $*
diff -r 5b491c71f689 -r bd7977a03670 profiles/xSMALL_/files/etc/rc.d/mountcritlocal
--- /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 $*
diff -r 5b491c71f689 -r bd7977a03670 profiles/xSMALL_/files/etc/rc.restore_config
--- /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
+
diff -r 5b491c71f689 -r bd7977a03670 profiles/xSMALL_/files/etc/rc.save_config
--- /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 "."
+
diff -r 5b491c71f689 -r bd7977a03670 profiles/xSMALL_/files/etc/rc.shutdown
--- 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
diff -r 5b491c71f689 -r bd7977a03670 profiles/xSMALL_/files/etc/rc.subr
--- 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()
diff -r 5b491c71f689 -r bd7977a03670 profiles/xSMALL_/files/etc/rc.zsubr
--- /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
+
diff -r 5b491c71f689 -r bd7977a03670 profiles/xSMALL_/files/etc/save_etc
--- 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!\/!\\\/!' `
+echo "Use /etc/rc.save_config instead"
 
-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 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
diff -r 5b491c71f689 -r bd7977a03670 profiles/xSMALL_/profile.mk
--- 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 \


More information about the Zrouter-src mailing list