From 9dafbe4f45764df9a5dda573e36afdfd60e52c35 Mon Sep 17 00:00:00 2001 From: CyberLeo Date: Sat, 13 Feb 2010 10:31:04 -0600 Subject: [PATCH] Fix saveconfig to actually work --- overlay/sbin/saveconfig | 31 +++++++++++++++++++------------ script/gentree | 9 +++++---- 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/overlay/sbin/saveconfig b/overlay/sbin/saveconfig index 3770956..48f7e95 100755 --- a/overlay/sbin/saveconfig +++ b/overlay/sbin/saveconfig @@ -18,7 +18,7 @@ find_newer_files() { archive_cpio() { [ -d "${1}" ] || return 1 [ -f "${2}" ] && return 1 - find_newer_files "${1}" | cpio -o | gzip -9 > "${2}" + find_newer_files "${1}" | cpio -o --quiet | gzip -9 > "${2}" } # Archive specified files to named target @@ -26,19 +26,22 @@ archive() { archive_cpio "${1}" "${2}.cpio.gz" } -# Mount /conf read-write, and remount if it already is. -if [ $(grep -c /conf /etc/fstab) -gt 0 ] +# Mount /conf read-write, and upgrade to read-write if mounted read-only. +if grep -q /conf /etc/fstab then - mount -w /conf - if [ $? -ne 1 ] - then - umount /conf - mount -w /conf - _was_mounted=true - fi + _conf_mount=yes + mount | grep -q /conf && _conf_mounted=yes + mount | grep /conf | grep -q read-only && _conf_readonly=yes + + # Mount if unmounted + [ ! "${_conf_mounted}" ] && mount -w /conf + + # Upgrade to read/write + [ "${_conf_mounted}" -a "${_conf_readonly}" ] && mount -u -w /conf fi # Store config in temp staging area +rm -Rf /conf/tmp || exit 1 mkdir -p /conf/tmp || exit 1 archive /etc /conf/tmp/etc || exit 1 archive /var /conf/tmp/var || exit 1 @@ -52,9 +55,13 @@ mv /conf/default "/conf/backup/${dest}" || exit 1 mv /conf/tmp /conf/default || mv "/conf/backup/${dest}" "/conf/default" # Umount /conf afterwards, if it wasn't mounted -if [ -z "${_was_mounted}" -a "$(mount |grep -c "/conf")" -gt 0 ] +if [ "${_conf_mount}" ] then - umount /conf + # Unmount if it wasn't mounted + [ ! "${_conf_mounted}" ] && umount /conf + + # Downgrade to read-only if it was read-only + [ "${_conf_mounted}" -a "${_conf_readonly}" ] && mount -u -r -f /conf fi echo "Done!" diff --git a/script/gentree b/script/gentree index e3ab050..5fbc414 100755 --- a/script/gentree +++ b/script/gentree @@ -181,16 +181,16 @@ do_imgboot() { # Instead: put all modules in the root image, except those needed to boot the kernel chk mkdir -p "${sroot}/boot/boot" chk mkdir -p "${sroot}/boot/kernel" - + # Link all modules into the root fs ( cd "${sboot}/kernel" && find . -name '*.ko' -o -name 'linker.hints' | cpio -p --link "${sroot}/boot/kernel" ) || chk - + # Remove all modules from the root fs that are preloaded by the loader cat "${sboot}/loader.conf" | grep '_load=' | sed -e 's#^\(.*\)_load=.*$#'"${sroot}/boot/kernel/"'\1.ko#' | xargs rm -f - + # Remove all modules from the boot fs that are present in the root fs ( cd "${sroot}/boot/kernel" && ls -1 ) | sed -e 's#^#'"${sboot}/kernel/"'#' | xargs rm -f - + # Link the preloaded modules from the boot fs to the root fs, to provide a homogenous view ( cd "${sboot}/kernel" && ls -1 ) | while read mod do @@ -202,6 +202,7 @@ do_imgconf() { log Create conf imgsrc chk mkdir -p "${sroot}/conf" echo "ufs:/dev/ufs/conf" > "${sroot}/conf/diskless_remount" || chk + chk mkdir -p "${sconf}/backup" chk mkdir -p "${sconf}/base/etc" chk mkdir -p "${sconf}/base/var" chk mkdir -p "${sconf}/default/etc" -- 2.42.0