From 5982568512b07e2aa668f269366ea80d3c6e5783 Mon Sep 17 00:00:00 2001 From: vernesong <42875168+vernesong@users.noreply.github.com> Date: Fri, 8 Nov 2024 16:59:47 +0800 Subject: [PATCH] chore: refine --- .../openclash/custom/openclash_custom_overwrite.sh | 13 +++++++++++++ luci-app-openclash/root/usr/share/openclash/ruby.sh | 12 +++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/luci-app-openclash/root/etc/openclash/custom/openclash_custom_overwrite.sh b/luci-app-openclash/root/etc/openclash/custom/openclash_custom_overwrite.sh index 1d0980a8b7..9293e3b2b2 100644 --- a/luci-app-openclash/root/etc/openclash/custom/openclash_custom_overwrite.sh +++ b/luci-app-openclash/root/etc/openclash/custom/openclash_custom_overwrite.sh @@ -50,6 +50,19 @@ CONFIG_FILE="$1" #config path #5--value key name in #4 file #ruby_arr_add_file "$CONFIG_FILE" "['dns']['fallback-filter']['ipcidr']" "0" "/etc/openclash/custom/openclash_custom_fallback_filter.yaml" "['fallback-filter']['ipcidr']" + #Delete Array Value Demo: + #1--config path + #2--key name + #3--value + #ruby_delete "$CONFIG_FILE" "['dns']['nameserver']" "114.114.114.114" + + #Delete Key Demo: + #1--config path + #2--key name + #3--key name + #ruby_delete "$CONFIG_FILE" "['dns']" "nameserver" + #ruby_delete "$CONFIG_FILE" "" "dns" + #Ruby Script Demo: #ruby -ryaml -rYAML -I "/usr/share/openclash" -E UTF-8 -e " # begin diff --git a/luci-app-openclash/root/usr/share/openclash/ruby.sh b/luci-app-openclash/root/usr/share/openclash/ruby.sh index 0df77fbd46..46037f987b 100644 --- a/luci-app-openclash/root/usr/share/openclash/ruby.sh +++ b/luci-app-openclash/root/usr/share/openclash/ruby.sh @@ -119,4 +119,14 @@ if [ -z "$1" ] || [ -z "$2" ]; then fi RUBY_YAML_PARSE="Thread.new{Value = YAML.load_file('$1'); Value$2.each do |i| puts i$3 end}.join" ruby -ryaml -rYAML -I "/usr/share/openclash" -E UTF-8 -e "$RUBY_YAML_PARSE" 2>/dev/null -} \ No newline at end of file +} + +ruby_delete() +{ +local Value RUBY_YAML_PARSE +if [ -z "$1" ] || [ -z "$3" ]; then + return +fi +RUBY_YAML_PARSE="Thread.new{Value = YAML.load_file('$1'); Value$2.delete('$3')}.join" +ruby -ryaml -rYAML -I "/usr/share/openclash" -E UTF-8 -e "$RUBY_YAML_PARSE" 2>/dev/null +}