Release 1.0.6: синхронизировать изменения из upstream и исправить баг фильтра URLTest/Priority
This commit is contained in:
@@ -3,13 +3,9 @@
|
||||
let fs = require("fs");
|
||||
let uci_core = require("core.uci");
|
||||
|
||||
let common = require("core.common");
|
||||
let as_string = common.as_string;
|
||||
let shell_quote = common.shell_quote;
|
||||
|
||||
let command_success_from_args = common.command_success_from_args;
|
||||
let command_from_args = common.command_from_args;
|
||||
|
||||
function as_string(value) {
|
||||
return value == null ? "" : "" + value;
|
||||
}
|
||||
|
||||
function env(name, fallback) {
|
||||
let value = getenv(name);
|
||||
@@ -25,14 +21,28 @@ const SING_BOX_INIT = env("TACHYON_SING_BOX_INIT", "/etc/init.d/sing-box");
|
||||
const SING_BOX_BIN = env("TACHYON_SING_BOX_BIN", "/usr/bin/sing-box");
|
||||
const SING_BOX_CRONET = env("TACHYON_SING_BOX_CRONET", "/usr/lib/libcronet.so");
|
||||
const SING_BOX_MANAGED_MARKER = env("SB_MANAGED_SERVICE_MARKER", "Tachyon managed sing-box service for binary variants");
|
||||
const PACKAGE_UPGRADE_STATE = env("TACHYON_PACKAGE_UPGRADE_STATE", "/tmp/tachyon-package-was-running");
|
||||
const PACKAGE_TEST_MODE = env("TACHYON_PACKAGE_TEST_MODE", "") != "";
|
||||
|
||||
function shell_quote(value) {
|
||||
return "'" + replace(as_string(value), /'/g, "'\\''") + "'";
|
||||
}
|
||||
|
||||
function command_from_args(args) {
|
||||
let parts = [];
|
||||
for (let arg in args)
|
||||
push(parts, shell_quote(arg));
|
||||
return join(" ", parts);
|
||||
}
|
||||
|
||||
function normalize_status(status) {
|
||||
status = int(status);
|
||||
return status > 255 ? int(status / 256) : status;
|
||||
}
|
||||
|
||||
function command_success_from_args(args) {
|
||||
return normalize_status(system(command_from_args(args) + " >/dev/null 2>&1")) == 0;
|
||||
}
|
||||
|
||||
function path_exists(path) {
|
||||
return fs.stat(as_string(path)) != null;
|
||||
@@ -99,10 +109,21 @@ function remove_managed_sing_box() {
|
||||
unlink_if_exists(SING_BOX_CRONET);
|
||||
}
|
||||
|
||||
function prerm_cleanup() {
|
||||
function remember_upgrade_state(action) {
|
||||
if (as_string(action) != "upgrade") {
|
||||
unlink_if_exists(PACKAGE_UPGRADE_STATE);
|
||||
return;
|
||||
}
|
||||
|
||||
if (command_success_from_args([ INIT_PATH, "status" ]))
|
||||
fs.writefile(PACKAGE_UPGRADE_STATE, "1\n");
|
||||
}
|
||||
|
||||
function prerm_cleanup(action) {
|
||||
if (env("IPKG_INSTROOT", "") != "")
|
||||
return true;
|
||||
|
||||
remember_upgrade_state(action);
|
||||
if (!PACKAGE_TEST_MODE) {
|
||||
command_success_from_args([ INIT_PATH, "stop" ]);
|
||||
restore_dnsmasq_if_needed();
|
||||
@@ -111,6 +132,17 @@ function prerm_cleanup() {
|
||||
return remove_rt_tables_entry();
|
||||
}
|
||||
|
||||
function postinst_restore() {
|
||||
if (env("IPKG_INSTROOT", "") != "" || !path_exists(PACKAGE_UPGRADE_STATE))
|
||||
return true;
|
||||
|
||||
if (!command_success_from_args([ INIT_PATH, "start" ]))
|
||||
return false;
|
||||
|
||||
unlink_if_exists(PACKAGE_UPGRADE_STATE);
|
||||
return true;
|
||||
}
|
||||
|
||||
function luci_cache_globs() {
|
||||
let configured = env("TACHYON_LUCI_CACHE_GLOBS", "");
|
||||
if (configured != "")
|
||||
@@ -132,24 +164,6 @@ function remove_luci_index_cache() {
|
||||
|
||||
function luci_postinst() {
|
||||
remove_luci_index_cache();
|
||||
try {
|
||||
let uci = require("uci");
|
||||
let cursor = uci.cursor();
|
||||
cursor.load(CONFIG_NAME);
|
||||
if (cursor.get(CONFIG_NAME, "telegram") == null) {
|
||||
cursor.set(CONFIG_NAME, "telegram", "telegram");
|
||||
cursor.set(CONFIG_NAME, "telegram", "enabled", "0");
|
||||
cursor.set(CONFIG_NAME, "telegram", "poll_interval", "5");
|
||||
cursor.set(CONFIG_NAME, "telegram", "notify_crash", "1");
|
||||
cursor.set(CONFIG_NAME, "telegram", "notify_restart", "1");
|
||||
cursor.set(CONFIG_NAME, "telegram", "notify_server_switch", "1");
|
||||
cursor.set(CONFIG_NAME, "telegram", "notify_subscription", "1");
|
||||
cursor.set(CONFIG_NAME, "telegram", "notify_cert", "1");
|
||||
cursor.set(CONFIG_NAME, "telegram", "notify_dns_leak", "1");
|
||||
cursor.commit(CONFIG_NAME);
|
||||
}
|
||||
} catch(e) {}
|
||||
|
||||
if (!PACKAGE_TEST_MODE) {
|
||||
if (path_exists("/etc/init.d/rpcd"))
|
||||
command_success_from_args([ "/etc/init.d/rpcd", "reload" ]);
|
||||
@@ -161,12 +175,14 @@ function luci_postinst() {
|
||||
let mode = ARGV[0] || "";
|
||||
|
||||
if (mode == "prerm")
|
||||
exit(prerm_cleanup() ? 0 : 1);
|
||||
exit(prerm_cleanup(ARGV[1]) ? 0 : 1);
|
||||
else if (mode == "postinst")
|
||||
exit(postinst_restore() ? 0 : 1);
|
||||
else if (mode == "remove-rt-tables-entry")
|
||||
exit(remove_rt_tables_entry() ? 0 : 1);
|
||||
else if (mode == "luci-postinst")
|
||||
exit(luci_postinst() ? 0 : 1);
|
||||
else {
|
||||
warn("Usage: service/package.uc <prerm|remove-rt-tables-entry|luci-postinst>\n");
|
||||
warn("Usage: service/package.uc <prerm|postinst|remove-rt-tables-entry|luci-postinst>\n");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user