Hi

I just wrote a little script, which saves text-files to nvram. Probably someone else needs such a script too.

#!/bin/ash

case "$1" in
        set)    # save file to nvram
                TAG="$2"
                if [ -z "$TAG" ] ; then
                        echo "argument missing"
                        exit 1
                fi
                num=0
                while read line ; do
                        nvram set $(printf "file_${TAG}_%02d=%s\n" $num "$line")
                        let num++
                done
                # write end-mark
                nvram set $(printf "file_${TAG}_%02d=\"###_EOF_EOF_EOF###\"\n" $num)
                echo "Saved $num lines to nvram ($TAG)" >&2
                ;;

        get)    # restore file from nvram
                TAG="$2"
                if [ -z "$TAG" ] ; then
                        echo "argument missing"
                        exit 1
                fi
                num=0
                LINE="$(nvram get $(printf "file_${TAG}_%02d" $num))"
                # stop at end-mark or if first line is empty
                while [ "$LINE" != '"###_EOF_EOF_EOF###"' ] ; do
                        [ -z "$LINE" -a "$num" -eq "0" ] && break
                        echo $LINE

                        let num++
                        LINE="$(nvram get $(printf "file_${TAG}_%02d" $num))"
                done
                echo "Got $num lines from nvram ($TAG)" >&2
                ;;

        list)   # list files in nvram
                nvram show 2>/dev/null | grep file_ | sed 's/^file_\([^_]*\)_.*$/\1/' | sor
                ;;

        *)      echo "unknown command"
                return 1
                ;;
esac

How to use it

nvram_file [set|get] TAG
nvram_file list

Tag is a short name for the file. Do NOT use _ here!

Save a file to nvram

nvram_file set passwd < /etc/passwd

Restore file from nvram

nvram_file get passwd > /etc/passwd.restored

Show all files in nvram

nvram_file list