From 725289ce9febe6228270e01174fa775481900f33 Mon Sep 17 00:00:00 2001 From: CyberLeo Date: Sat, 13 Feb 2010 07:11:43 -0600 Subject: [PATCH] Move saveconfig stuff into overlay --- overlay/etc/rc.d/saveconfig | 16 ++++++++ overlay/sbin/saveconfig | 53 ++++++++++++++++++++++++ patch/etc_rc.d_saveconfig-script.patch | 19 --------- patch/sbin_saveconfig-script.patch | 56 -------------------------- 4 files changed, 69 insertions(+), 75 deletions(-) create mode 100755 overlay/etc/rc.d/saveconfig create mode 100755 overlay/sbin/saveconfig delete mode 100644 patch/etc_rc.d_saveconfig-script.patch delete mode 100644 patch/sbin_saveconfig-script.patch diff --git a/overlay/etc/rc.d/saveconfig b/overlay/etc/rc.d/saveconfig new file mode 100755 index 0000000..8009719 --- /dev/null +++ b/overlay/etc/rc.d/saveconfig @@ -0,0 +1,16 @@ +#!/bin/sh + +# PROVIDE: saveconfig +# REQUIRE: var +# BEFORE: swap1 +# KEYWORD: shutdown + +name="saveconfig" +stop_cmd="saveconfig_stop" + +saveconfig_stop(){ + /sbin/saveconfig +} + +load_rc_config $name +run_rc_command "$1" diff --git a/overlay/sbin/saveconfig b/overlay/sbin/saveconfig new file mode 100755 index 0000000..fc3cab3 --- /dev/null +++ b/overlay/sbin/saveconfig @@ -0,0 +1,53 @@ +#!/bin/sh + +echo -n "Saving configuration... " + +if [ ! -f /etc/diskless ] +then + echo "No flash setup detected." + exit 1 +fi + +find_newer_files() { + [ -d "${1}" ] || return 1 + find "${1}" -type f -not -regex '.*/tmp/*.' -newer /etc/diskless -print +} + +archive() { + [ -d "${1}" ] || return 1 + find_newer_files "${1}" | cpio -o | gzip -9 > "/conf/default/${1}.cpio.gz" +} + +# Mount /conf read-write, and remount if it already is. +if [ $(grep -c /conf /etc/fstab) -gt 0 ] +then + mount -w /conf + if [ $? -ne 1 ] + then + umount /conf + mount -w /conf + _was_mounted=true + fi +fi + + +# Unlimited history method: (make sure you have provisions for removing the old backups, or this can get HUGE! +dest="$(date -r "$(stat -f '%c' "/conf/default")" "+%Y-%m-%dT%H-%M-%S")" +mv /conf/default "/conf/backup/${dest}" + +mkdir /conf/default + +cd / +# Copy changed config files to /conf/default (anything younger than /etc/diskless) +#find etc var -type f -not -regex '.*/tmp/.*' -newer /etc/diskless -print0 | cpio -p /conf/default/ +# This can be changed to allow compressed configuration here as well: +archive etc +archive var + +# Umount /conf afterwards, if it wasn't mounted +if [ -z "${_was_mounted}" -a "$(mount |grep -c "/conf")" -gt 0 ] +then + umount /conf +fi + +echo "Done!" diff --git a/patch/etc_rc.d_saveconfig-script.patch b/patch/etc_rc.d_saveconfig-script.patch deleted file mode 100644 index 0b349ac..0000000 --- a/patch/etc_rc.d_saveconfig-script.patch +++ /dev/null @@ -1,19 +0,0 @@ ---- /dev/null 2010-01-30 08:55:01.000000000 +0000 -+++ etc/rc.d/saveconfig 2010-01-24 11:07:56.000000000 +0000 -@@ -0,0 +1,16 @@ -+#!/bin/sh -+ -+# PROVIDE: saveconfig -+# REQUIRE: var -+# BEFORE: swap1 -+# KEYWORD: shutdown -+ -+name="saveconfig" -+stop_cmd="saveconfig_stop" -+ -+saveconfig_stop(){ -+ /sbin/saveconfig -+} -+ -+load_rc_config $name -+run_rc_command "$1" diff --git a/patch/sbin_saveconfig-script.patch b/patch/sbin_saveconfig-script.patch deleted file mode 100644 index 79c34ec..0000000 --- a/patch/sbin_saveconfig-script.patch +++ /dev/null @@ -1,56 +0,0 @@ ---- /dev/null 2010-01-30 08:55:01.000000000 +0000 -+++ sbin/saveconfig 2010-01-24 11:02:05.000000000 +0000 -@@ -0,0 +1,53 @@ -+#!/bin/sh -+ -+echo -n "Saving configuration... " -+ -+if [ ! -f /etc/diskless ] -+then -+ echo "No flash setup detected." -+ exit 1 -+fi -+ -+find_newer_files() { -+ [ -d "${1}" ] || return 1 -+ find "${1}" -type f -not -regex '.*/tmp/*.' -newer /etc/diskless -print -+} -+ -+archive() { -+ [ -d "${1}" ] || return 1 -+ find_newer_files "${1}" | cpio -o | gzip -9 > "/conf/default/${1}.cpio.gz" -+} -+ -+# Mount /conf read-write, and remount if it already is. -+if [ $(grep -c /conf /etc/fstab) -gt 0 ] -+then -+ mount -w /conf -+ if [ $? -ne 1 ] -+ then -+ umount /conf -+ mount -w /conf -+ _was_mounted=true -+ fi -+fi -+ -+ -+# Unlimited history method: (make sure you have provisions for removing the old backups, or this can get HUGE! -+dest="$(date -r "$(stat -f '%c' "/conf/default")" "+%Y-%m-%dT%H-%M-%S")" -+mv /conf/default "/conf/backup/${dest}" -+ -+mkdir /conf/default -+ -+cd / -+# Copy changed config files to /conf/default (anything younger than /etc/diskless) -+#find etc var -type f -not -regex '.*/tmp/.*' -newer /etc/diskless -print0 | cpio -p /conf/default/ -+# This can be changed to allow compressed configuration here as well: -+archive etc -+archive var -+ -+# Umount /conf afterwards, if it wasn't mounted -+if [ -z "${_was_mounted}" -a "$(mount |grep -c "/conf")" -gt 0 ] -+then -+ umount /conf -+fi -+ -+echo "Done!" -- 2.42.0