## # replace node value in sly xml # <context-param> # <param-name>$2</param-name> # <param-value>Some Old Value</param-value> # </context-param> # @param $1 filename # @param $2 param name # @param $3 param value to set # used if there is no xpath tool in system set_param_value() { local new_value="$3" local webxml="$1" # TODO find backup destination name local old="$webxml".tmp local catch_next_tag=0 if [ ! -w "$webxml" ]; then echo -e "${ERR}$webxml is not writable! Failed!${N}" return 1; fi if ! cp "$webxml" "$old"; then echo -e "${ERR}Cannot save old file. Failed!${N}"; return 2; fi while IFS='<>' read _ starttag value endtag; do case "$starttag" in param-name) case "$value" in $2) catch_next_tag=1;; esac ;; param-value) if [ 1 -eq $catch_next_tag ]; then old_value="$value"; break; fi;; esac done < "$old" cat "$old" | sed "s#$old_value#$new_value#g" > "$webxml.probe" mv --force "$webxml.probe" "$webxml" && (echo "${OK} $webxml") || (echo $FAIL; return 255;) }