remove_lines_from_file() { # $1=filename # $2=substring match indicating lines to remove (case sensitive) cat "$1" | grep -q "$2" && { fix_symlink_hack "$1" local _substr_sed _substr_sed=$(echo "$2" | sed s/'\/'/'\\\/'/g) cat "$1" | sed /"$_substr_sed"/d > "$1" } } uci_set() { local PACKAGE="$1" local CONFIG="$2" local OPTION="$3" local VALUE="$4" ( # spawn a subshell so you don't mess up the current environment config_load "$PACKAGE" config_get ORIGVAL "$CONFIG" "$OPTION" uci_load "$PACKAGE" config_get OLDVAL "$CONFIG" "$OPTION" if [ "$OLDVAL" != "$VALUE" ]; then if [ -e "/tmp/.uci/$PACKAGE" ]; then remove_lines_from_file "/tmp/.uci/$PACKAGE" "config_set '$CONFIG' '$OPTION' '$OLDVAL'" fi if [ "$ORIGVAL" != "$VALUE" ]; then config_get type "$CONFIG" TYPE [ -z "$type" ] else [ -e "/tmp/.uci/$PACKAGE" ] && [ "`cat "/tmp/.uci/$PACKAGE"`" = "" ] && { rm "/tmp/.uci/$PACKAGE" } fi fi ) || uci_add_update "$PACKAGE" "config_set '$CONFIG' '$OPTION' '$VALUE'" }