Created
January 28, 2025 22:14
-
-
Save pedro0311/4c59dc991d22d13f71c43daa139a9962 to your computer and use it in GitHub Desktop.
Script for exporting/backup selected FreshTomato settings
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/sh | |
| # USE AT YOUR OWN RISK. | |
| # THIS SCRIPT DOES NOT COME WITH ANY WARRANTY WHATSOEVER. | |
| # | |
| # Backs up selected nvram variables; import them just by running the resulting script. | |
| # Should work equally well with both MIPS and ARM builds. | |
| # | |
| # Thanks to ryzhov_al for basic approach. | |
| # | |
| # Looks for a list of items to export in $etc/scriptname.ini OR enter items to grep for below. | |
| # The items list is a list of regular expressions to match against the nvram variable names. | |
| # | |
| # Script assumes all entries are at beginning of line(prefixed with ^). | |
| # | |
| # Leave items list blank to backup up all of nvram. | |
| # | |
| # The items list below is only intended as example and is not complete or comprehensive. Customize for your own use. | |
| # Edit list below if not using .ini file, it is ignored if .ini file is found. | |
| # | |
| items=' | |
| dhcpd_ | |
| dns_ | |
| script_ | |
| wl[0-9] | |
| wan_ | |
| lan_ | |
| mwan_ | |
| vlan_ | |
| ' | |
| etc=/tmp/etc | |
| base=${0##*/}; base=${base%.*} | |
| config=$etc/$base.ini | |
| # file to output - default to stdout | |
| [ "$1" != "" ] && { | |
| backupfile="$1" | |
| } || { | |
| backupfile=/proc/$$/fd/1 | |
| } | |
| grepstr=$( { [ -r $config ] && cat $config || echo "$items" ; } | sed -e 's/[\t ]//g;/^$/d' | sed ':a;N;$!ba;s/\n/\\\|\^/g') | |
| { | |
| echo -e "#!/bin/sh\n" | |
| for item in $(nvram show 2>/dev/null | grep "^.*=" | grep "$grepstr" | awk -F= "{print \$1}" | sort -u); do | |
| item_value="$(nvram get $item | sed 's!\([\$\"\`]\)!\\\1!g'; echo nvgetwasnull)" | |
| case $item_value in | |
| nvgetwasnull) ;; | |
| *) echo "nvram set ${item}=\"${item_value% | |
| nvgetwasnull}\"" ;; | |
| esac | |
| done | |
| echo "nvram commit" | |
| }>"$backupfile" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment