Skip to content

Commit

Permalink
chore: refine
Browse files Browse the repository at this point in the history
  • Loading branch information
vernesong committed Feb 16, 2025
1 parent 582e294 commit fe8dd5a
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 22 deletions.
1 change: 0 additions & 1 deletion luci-app-openclash/root/etc/init.d/openclash
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,6 @@ start_run_core()
procd_set_param group "nogroup"
procd_set_param limits nproc="unlimited" as="unlimited" memlock="unlimited" nofile="1000000 1000000"
procd_set_param respawn 3600 3 10
procd_set_param capabilities "/etc/capabilities/openclash.json"
procd_set_param stderr 1
procd_set_param no_new_privs 1
procd_close_instance
Expand Down
14 changes: 10 additions & 4 deletions luci-app-openclash/root/usr/share/openclash/yml_groups_get.sh
Original file line number Diff line number Diff line change
Expand Up @@ -139,19 +139,20 @@ ruby -ryaml -rYAML -I "/usr/share/openclash" -E UTF-8 -e "
threadsp = [];
threads_uci = [];
uci_commands = [];
uci_name_tmp = [];
if not Value.key?('proxy-groups') or Value['proxy-groups'].nil? then
proxy-groups = [];
end;
Value_1 = File.readlines('/tmp/Proxy_Group').map!{|x| x.strip};
Value['proxy-groups'].each do |x|
Value['proxy-groups'].each_with_index do |x, index|
uci_name_tmp << %x{uci -q add openclash groups 2>&1}.chomp
threadsp << Thread.new {
begin
next unless x['name'] && x['type'];
uci_name_tmp=%x{uci -q add openclash groups 2>&1}.chomp
uci_set='uci -q set openclash.' + uci_name_tmp + '.'
uci_add='uci -q add_list openclash.' + uci_name_tmp + '.'
uci_set='uci -q set openclash.' + uci_name_tmp[index] + '.'
uci_add='uci -q add_list openclash.' + uci_name_tmp[index] + '.'
YAML.LOG('Start Getting【${CONFIG_NAME} - ' + x['type'].to_s + ' - ' + x['name'].to_s + '】Group Setting...');
Expand Down Expand Up @@ -248,6 +249,11 @@ ruby -ryaml -rYAML -I "/usr/share/openclash" -E UTF-8 -e "
};
end;
threads_uci.each(&:join);
uci_name_tmp.each do |x|
if x =~ /uci -q delete/ then
system(x);
end;
end;
system('uci -q commit openclash');
system('rm -rf /tmp/yaml_other_group.yaml 2>/dev/null');
" 2>/dev/null >> $LOG_FILE
Expand Down
44 changes: 27 additions & 17 deletions luci-app-openclash/root/usr/share/openclash/yml_proxys_get.sh
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ ruby -ryaml -rYAML -I "/usr/share/openclash" -E UTF-8 -e "
threads_pr = [];
threads_uci = [];
uci_commands = [];
uci_name_tmp_prv = [];
uci_name_tmp = [];
if not Value.key?('proxy-providers') or Value['proxy-providers'].nil? then
Value['proxy-providers'] = {};
Expand All @@ -166,7 +168,8 @@ ruby -ryaml -rYAML -I "/usr/share/openclash" -E UTF-8 -e "
Value['proxies'] = [];
end;
Value['proxy-providers'].each do |x,y|
Value['proxy-providers'].each_with_index do |(x,y), index|
uci_name_tmp_prv << %x{uci -q add openclash proxy-provider 2>&1}.chomp;
threads_pr << Thread.new {
begin
YAML.LOG('Start Getting【${CONFIG_NAME} - ' + y['type'].to_s + ' - ' + x.to_s + '】Proxy-provider Setting...');
Expand All @@ -177,20 +180,18 @@ ruby -ryaml -rYAML -I "/usr/share/openclash" -E UTF-8 -e "
cmd = 'sed -i \"/^' + provider_nums + '\./c\\#match#\" $match_provider 2>/dev/null';
system(cmd);
uci_set='uci -q set openclash.@proxy-provider[' + provider_nums + '].';
uci_get='uci -q get openclash.@proxy-provider[' + provider_nums + '].';
uci_add='uci -q add_list openclash.@proxy-provider[' + provider_nums + '].';
uci_del='uci -q delete openclash.@proxy-provider[' + provider_nums + '].';
cmd = uci_get + 'manual';
if not provider_nums then
uci_commands << uci_set + 'manual=0';
end;
uci_commands << uci_set + 'type=\"' + y['type'].to_s + '\"';
uci_name_tmp_prv[index] = 'uci -q delete openclash.' + uci_name_tmp_prv[index];
else
#代理集不存在时添加新代理集
uci_name_tmp=%x{uci -q add openclash proxy-provider 2>&1}.chomp;
uci_set='uci -q set openclash.' + uci_name_tmp + '.';
uci_add='uci -q add_list openclash.' + uci_name_tmp + '.';
uci_del='uci -q delete openclash.' + uci_name_tmp + '.';
uci_set='uci -q set openclash.' + uci_name_tmp_prv[index] + '.';
uci_add='uci -q add_list openclash.' + uci_name_tmp_prv[index] + '.';
uci_del='uci -q delete openclash.' + uci_name_tmp_prv[index] + '.';
if '$config_group_exist' == 0 and '$servers_if_update' == '1' and '$servers_update' == 1 then
uci_commands << uci_set + 'enabled=0';
Expand Down Expand Up @@ -289,17 +290,18 @@ ruby -ryaml -rYAML -I "/usr/share/openclash" -E UTF-8 -e "
end
};
};
threads_agr.each(&:join)
threads_agr.each(&:join);
end;
};
threads_prv.each(&:join)
threads_prv.each(&:join);
rescue Exception => e
YAML.LOG('Error: Resolve Proxy-providers Failed,【${CONFIG_NAME} - ' + x + ': ' + e.message + '】');
end;
};
end;
Value['proxies'].each do |x|
Value['proxies'].each_with_index do |x, index|
uci_name_tmp << %x{uci -q add openclash proxy-provider 2>&1}.chomp;
threads_pr << Thread.new {
begin
YAML.LOG('Start Getting【${CONFIG_NAME} - ' + x['type'].to_s + ' - ' + x['name'].to_s + '】Proxy Setting...');
Expand All @@ -311,19 +313,17 @@ ruby -ryaml -rYAML -I "/usr/share/openclash" -E UTF-8 -e "
cmd = 'sed -i \"/^' + server_num + '\./c\\#match#\" $match_servers 2>/dev/null';
system(cmd);
uci_set='uci -q set openclash.@servers[' + server_num + '].';
uci_get='uci -q get openclash.@servers[' + server_num + '].';
uci_add='uci -q add_list openclash.@servers[' + server_num + '].';
uci_del='uci -q delete openclash.@servers[' + server_num + '].';
cmd = uci_get + 'manual';
if not server_num then
uci_commands << uci_set + 'manual=0';
end;
uci_name_tmp[index] = 'uci -q delete openclash.' + uci_name_tmp[index];
else
#添加新节点
uci_name_tmp=%x{uci -q add openclash servers 2>&1}.chomp;
uci_set='uci -q set openclash.' + uci_name_tmp + '.';
uci_add='uci -q add_list openclash.' + uci_name_tmp + '.';
uci_del='uci -q delete openclash.' + uci_name_tmp + '.';
uci_set='uci -q set openclash.' + uci_name_tmp[index] + '.';
uci_add='uci -q add_list openclash.' + uci_name_tmp[index] + '.';
uci_del='uci -q delete openclash.' + uci_name_tmp[index] + '.';
if '$config_group_exist' == 0 and '$servers_if_update' == '1' and '$servers_update' == 1 then
uci_commands << uci_set + 'enabled=0';
else
Expand Down Expand Up @@ -1452,6 +1452,16 @@ ruby -ryaml -rYAML -I "/usr/share/openclash" -E UTF-8 -e "
};
end;
threads_uci.each(&:join);
uci_name_tmp.each do |x|
if x =~ /uci -q delete/ then
system(x);
end;
end;
uci_name_tmp_prv.each do |x|
if x =~ /uci -q delete/ then
system(x);
end;
end;
system('uci -q commit openclash');
" 2>/dev/null >> $LOG_FILE

Expand Down

0 comments on commit fe8dd5a

Please sign in to comment.