diff --git a/package/ctcgfw/luci-app-openclash/files/etc/init.d/openclash b/package/ctcgfw/luci-app-openclash/files/etc/init.d/openclash index fb6322ea4f..19ee50d667 100755 --- a/package/ctcgfw/luci-app-openclash/files/etc/init.d/openclash +++ b/package/ctcgfw/luci-app-openclash/files/etc/init.d/openclash @@ -531,20 +531,22 @@ yml_game_group_get() yml_game_custom() { #处理游戏规则 -sed -i '/OpenClash-Game-Rules/,/OpenClash-Game-Rules-End/d' "$RULE_FILE" 2>/dev/null -sed -i '/OpenClash-Game-Rules/d' "$RULE_FILE" 2>/dev/null -sed -i '/OpenClash-Game-Rules-End/d' "$RULE_FILE" 2>/dev/null -if [ ! -z "$(grep "^ \{0,\}- GEOIP" "$RULE_FILE")" ]; then - sed -i '1,/^ \{0,\}- GEOIP,/{/^ \{0,\}- GEOIP,/s/^ \{0,\}- GEOIP,/#===================== OpenClash-Game-Rules =====================#\n&/}' "$RULE_FILE" 2>/dev/null -elif [ ! -z "$(grep "^ \{0,\}- MATCH," "$RULE_FILE")" ]; then - sed -i '1,/^ \{0,\}- MATCH,/{/^ \{0,\}- MATCH,/s/^ \{0,\}- MATCH,/#===================== OpenClash-Game-Rules =====================#\n&/}' "$RULE_FILE" 2>/dev/null -else - echo "#===================== OpenClash-Game-Rules =====================#" >> "$RULE_FILE" 2>/dev/null -fi rm -rf $GAME_RULE_FILE 2>/dev/null config_load "openclash" config_foreach yml_game_rule_get "game_config" +if [ ! -z "$(grep "OpenClash-Game-Rules" "$RULE_FILE")" ]; then + sed -i '/OpenClash-Game-Rules/,/OpenClash-Game-Rules-End/d' "$RULE_FILE" 2>/dev/null +fi +sed -i '/OpenClash-Game-Rules/d' "$RULE_FILE" 2>/dev/null +sed -i '/OpenClash-Game-Rules-End/d' "$RULE_FILE" 2>/dev/null [ "$set_rule_file" = 1 ] && { + if [ ! -z "$(grep "^ \{0,\}- GEOIP" "$RULE_FILE")" ]; then + sed -i '1,/^ \{0,\}- GEOIP,/{/^ \{0,\}- GEOIP,/s/^ \{0,\}- GEOIP,/#===================== OpenClash-Game-Rules =====================#\n&/}' "$RULE_FILE" 2>/dev/null + elif [ ! -z "$(grep "^ \{0,\}- MATCH," "$RULE_FILE")" ]; then + sed -i '1,/^ \{0,\}- MATCH,/{/^ \{0,\}- MATCH,/s/^ \{0,\}- MATCH,/#===================== OpenClash-Game-Rules =====================#\n&/}' "$RULE_FILE" 2>/dev/null + else + echo "#===================== OpenClash-Game-Rules =====================#" >> "$RULE_FILE" 2>/dev/null + fi echo "#===================== OpenClash-Game-Rules-End =====================#" >> $GAME_RULE_FILE sed -i '/OpenClash-Game-Rules/r/tmp/yaml_game_rule_group.yaml' "$RULE_FILE" 2>/dev/null }