[Zrouter-src] ZRouter.org: push to ZRouter profiles/SMALL_/files/etc/buttons/W...
zrouter-src at zrouter.org
zrouter-src at zrouter.org
Sat Apr 21 12:09:52 UTC 2012
details: http://zrouter.org/hg/zrouter//rev/5b491c71f689
changeset: 389:5b491c71f689
user: Aleksandr Rybalko <ray at ddteam.net>
date: Sat Apr 21 15:09:58 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/SMALL_/files/etc/buttons/WDS.sh | 11 +----
profiles/SMALL_/files/etc/defaults/rc.conf | 3 +
profiles/SMALL_/files/etc/rc.d/MAIN | 2 +-
profiles/SMALL_/files/etc/rc.d/mountcritlocal | 14 +-----
profiles/SMALL_/files/etc/rc.restore_config | 24 +++++++++++
profiles/SMALL_/files/etc/rc.save_config | 55 +++++++++++++++++++++++++++
profiles/SMALL_/files/etc/rc.shutdown | 13 ------
profiles/SMALL_/files/etc/rc.subr | 2 +
profiles/SMALL_/files/etc/rc.zsubr | 17 ++++++++
profiles/SMALL_/files/etc/save_etc | 44 +---------------------
profiles/SMALL_/profile.mk | 1 +
11 files changed, 108 insertions(+), 78 deletions(-)
diffs (273 lines):
diff -r a95f08196f9a -r 5b491c71f689 profiles/SMALL_/files/etc/buttons/WDS.sh
--- 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
-
diff -r a95f08196f9a -r 5b491c71f689 profiles/SMALL_/files/etc/defaults/rc.conf
--- 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"
diff -r a95f08196f9a -r 5b491c71f689 profiles/SMALL_/files/etc/rc.d/MAIN
--- 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 $*
diff -r a95f08196f9a -r 5b491c71f689 profiles/SMALL_/files/etc/rc.d/mountcritlocal
--- 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 $*
diff -r a95f08196f9a -r 5b491c71f689 profiles/SMALL_/files/etc/rc.restore_config
--- /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
+
diff -r a95f08196f9a -r 5b491c71f689 profiles/SMALL_/files/etc/rc.save_config
--- /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 "."
+
diff -r a95f08196f9a -r 5b491c71f689 profiles/SMALL_/files/etc/rc.shutdown
--- 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
diff -r a95f08196f9a -r 5b491c71f689 profiles/SMALL_/files/etc/rc.subr
--- 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()
diff -r a95f08196f9a -r 5b491c71f689 profiles/SMALL_/files/etc/rc.zsubr
--- /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
+
diff -r a95f08196f9a -r 5b491c71f689 profiles/SMALL_/files/etc/save_etc
--- 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
+echo "Use /etc/rc.save_config instead"
-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 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
diff -r a95f08196f9a -r 5b491c71f689 profiles/SMALL_/profile.mk
--- 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 \
More information about the Zrouter-src
mailing list