Dirk Nehring dixit:

>great to hear about your progress. Do you have an idea how to save the
>config? For the web interface we need a function 'save' and
>'restore'. does it work with a simple dd?

save()
{
        part=/dev/mtd/$(fgrep '"fwcf"' /proc/mtd 2>&- | \
            sed 's/^mtd\([^:]*\):.*$/\1/')ro
        if ! test -e "$part"; then
                echo 'error: no "fwcf" mtd partition found!' >&2
                exit 1
        fi
        if test -n "$1"; then
                cat "$part" >"$1"
        else
                cat "$part"
        fi
}

restore()
{
        cat ${1:+"$1"} | mtd -F write - fwcf
}

# Syntax:
# save [filename]
# restore [filename]

Keep in mind that, if the fwcf major or the compression
format (deflate -> lzo1x) changes, this won't exactly work.
I might add some kind of dump functionality later.

Otherwise you can 'just' tar up /etc to save, and copy
it back followed by an 'fwcf commit' in restore:

save()
{
        if test -n "$1"; then
                (cd /etc; tar cf - .) | gzip -n9 >"$1"
        else
                (cd /etc; tar cf - .) | gzip -n9
        fi
}

restore()
{
        if ! test -e /etc/.fwcf_done; then
                echo 'error: fwcf not initialised' >&2
                exit 1
        fi
        cat ${1:+"$1"} | gzip -dc | (cd /etc; tar xphf -)
        fwcf commit
}

These two are semantically slightly different. fwcf
only stores the files that differ from the "original"
/etc (in the possibly read-only (squashfs) root, which
is mount --bind'ed to /tmp/.fwcf/root) as well as all
directories and symbolic links, whereas tar stores all
files, not only these which changed. So the second ap-
proach could miss updated files in /etc in the base
image. If you don't want that, use something like

save()
{
        wd=$(pwd)
        umount /tmp/.fwcf/temp >&- 2>&-
        mount -t tmpfs swap /tmp/.fwcf/temp
        (cd /etc; tar cf - .) | (cd /tmp/.fwcf/temp; tar xpf -)
        cd /tmp/.fwcf/root
        find . -type f | while read f; do
                x=$(md5sum "${f#./}" 2>&-)
                y=$(cd ../temp; md5sum "${f#./}" 2>&-)
                test x"$x" = x"$y" && rm "../temp/${f#./}"
        done
        cd /tmp/.fwcf/temp
        if test -n "$1"; then
                tar cf - . | gzip -n9 >"$1"
        else
                tar cf - . | gzip -n9
        fi
        cd $wd
        umount /tmp/.fwcf/temp
}

All these shell functions are untested but should
work with ash on the target. Error checking is
something you'd better implement yourself depending
on your needs.

bye,
//mirabile
-- 
  "Using Lynx is like wearing a really good pair of shades: cuts out
   the glare and harmful UV (ultra-vanity), and you feel so-o-o COOL."
                                         -- Henry Nelson, March 1999
_______________________________________________
freewrt-developers mailing list
[email protected]
https://www.freewrt.org/lists/listinfo/freewrt-developers

Reply via email to