Ensure all kernel modules and dependencies are installed and loaded for sing-box variants
This commit is contained in:
+11
@@ -2418,6 +2418,11 @@ install_selected_sing_box() {
|
||||
fi
|
||||
|
||||
[ -x /usr/bin/tachyon ] || fail "tachyon backend must be installed before sing-box component action"
|
||||
for kmod in inet_diag netlink_diag tun nft_tproxy; do
|
||||
modprobe "$kmod" 2>/dev/null || true
|
||||
done
|
||||
[ -d /dev/net ] || mkdir -p /dev/net
|
||||
[ -c /dev/net/tun ] || mknod /dev/net/tun c 10 200 2>/dev/null || true
|
||||
msg "$(installer_text installing_singbox_backend)"
|
||||
if ! run_logged "sing-box" /usr/bin/tachyon component_action sing_box "$action"; then
|
||||
fail "Failed to install selected sing-box variant"
|
||||
@@ -2573,6 +2578,12 @@ install_backend_package() {
|
||||
fi
|
||||
done
|
||||
|
||||
for kmod in inet_diag netlink_diag tun nft_tproxy nft_nat; do
|
||||
modprobe "$kmod" 2>/dev/null || true
|
||||
done
|
||||
[ -d /dev/net ] || mkdir -p /dev/net
|
||||
[ -c /dev/net/tun ] || mknod /dev/net/tun c 10 200 2>/dev/null || true
|
||||
|
||||
# Protect user configuration from being overwritten by apk.
|
||||
# apk add --allow-untrusted may not respect conffiles_static on all
|
||||
# OpenWrt builds, silently replacing /etc/config/tachyon with defaults.
|
||||
|
||||
@@ -849,6 +849,40 @@ function ensure_package_tool(tool_name, package_name, component, action) {
|
||||
return run_logged("Installing bootstrap package " + as_string(package_name), pkg_install_name_command(package_name));
|
||||
}
|
||||
|
||||
function ensure_sing_box_dependencies() {
|
||||
let kmods = [ "kmod-inet-diag", "kmod-netlink-diag", "kmod-tun", "kmod-nft-tproxy", "kmod-nft-nat", "ca-bundle" ];
|
||||
let missing = [];
|
||||
for (let kmod in kmods) {
|
||||
if (!pkg_is_installed(kmod)) {
|
||||
if (kmod == "kmod-tun" && file_exists("/dev/net/tun"))
|
||||
continue;
|
||||
push(missing, kmod);
|
||||
}
|
||||
}
|
||||
|
||||
if (length(missing) > 0) {
|
||||
updates_log("Installing missing dependencies for sing-box: " + join(", ", missing));
|
||||
run_logged("Updating package lists for sing-box dependencies", pkg_list_update_command());
|
||||
|
||||
for (let kmod in missing) {
|
||||
if (!run_logged("Installing dependency " + kmod, pkg_install_name_command(kmod))) {
|
||||
if (kmod == "kmod-tun" && file_exists("/dev/net/tun"))
|
||||
continue;
|
||||
updates_log("Could not install " + kmod + " (may be built-in or custom firmware)", "warn");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
command_success_from_args([ "modprobe", "tun" ]);
|
||||
command_success_from_args([ "modprobe", "inet_diag" ]);
|
||||
if (!file_exists("/dev/net/tun")) {
|
||||
command_success_from_args([ "mkdir", "-p", "/dev/net" ]);
|
||||
command_success_from_args([ "mknod", "/dev/net/tun", "c", "10", "200" ]);
|
||||
command_success_from_args([ "chmod", "0666", "/dev/net/tun" ]);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function clear_version_caches() {
|
||||
remove_file("/tmp/tachyon.latest-version.cache");
|
||||
remove_file(SYSTEM_INFO_CACHE_FILE);
|
||||
@@ -867,6 +901,10 @@ function managed_sing_box_service_text() {
|
||||
"START=99\n" +
|
||||
"PROG=\"/usr/bin/sing-box\"\n\n" +
|
||||
"start_service() {\n" +
|
||||
" [ -d /dev/net ] || mkdir -p /dev/net\n" +
|
||||
" [ -c /dev/net/tun ] || mknod /dev/net/tun c 10 200 2>/dev/null || true\n" +
|
||||
" modprobe tun 2>/dev/null || true\n" +
|
||||
" modprobe inet_diag 2>/dev/null || true\n\n" +
|
||||
" config_load \"sing-box\"\n" +
|
||||
" local enabled config_file working_directory\n" +
|
||||
" local log_stderr\n\n" +
|
||||
@@ -1888,6 +1926,8 @@ function install_sing_box_extended_package(action, target_tag) {
|
||||
check_success("sing_box", normalize_sing_box_version(current_version), normalize_sing_box_version(latest_version), release.release_url);
|
||||
}
|
||||
|
||||
ensure_sing_box_dependencies();
|
||||
|
||||
let package_file = tmp_dir + "/" + release.asset_name;
|
||||
if (!download_with_retry(release.asset_url, package_file, release.asset_name))
|
||||
action_fail("sing_box", action, "Failed to download sing-box-extended package", current_version, latest_version);
|
||||
@@ -2004,6 +2044,8 @@ function install_sing_box_extended(action, compressed, target_tag) {
|
||||
check_success("sing_box", normalize_sing_box_version(current_version), normalize_sing_box_version(latest_version), release.release_url);
|
||||
}
|
||||
|
||||
ensure_sing_box_dependencies();
|
||||
|
||||
let archive_file = tmp_dir + "/" + release.asset_name;
|
||||
if (!download_with_retry(release.asset_url, archive_file, release.asset_name))
|
||||
action_fail("sing_box", action, "Failed to download " + label, current_version, latest_version);
|
||||
@@ -2165,6 +2207,8 @@ function install_sing_box_lx(action, target_tag) {
|
||||
check_success("sing_box", normalize_sing_box_version(current_version), normalize_sing_box_version(latest_version), release.release_url);
|
||||
}
|
||||
|
||||
ensure_sing_box_dependencies();
|
||||
|
||||
let archive_file = tmp_dir + "/" + release.asset_name;
|
||||
if (!download_with_retry(release.asset_url, archive_file, release.asset_name))
|
||||
action_fail("sing_box", action, "Failed to download " + label, current_version, latest_version);
|
||||
@@ -2329,6 +2373,8 @@ function install_package_sing_box(action, tiny) {
|
||||
check_success("sing_box", current_version, latest_version, "");
|
||||
}
|
||||
|
||||
ensure_sing_box_dependencies();
|
||||
|
||||
if (!run_logged("Updating package lists before " + package_name + " installation", pkg_list_update_command()))
|
||||
action_fail("sing_box", action, "Failed to update package lists", current_version, latest_version);
|
||||
latest_version = available_package_version(package_name);
|
||||
|
||||
@@ -1999,7 +1999,7 @@ function get_sing_box_version(ctx) {
|
||||
if (!command_exists("sing-box"))
|
||||
return "";
|
||||
|
||||
if (sing_box_compressed_marker_set(ctx))
|
||||
if (sing_box_compressed_marker_set(ctx) || sing_box_lx_marker_set(ctx))
|
||||
return sing_box_version_state(ctx);
|
||||
|
||||
return first_line_last_field(command_output_from_args([ "sing-box", "version" ]));
|
||||
@@ -2042,7 +2042,7 @@ function sing_box_output_has_build_tag(output, tag) {
|
||||
}
|
||||
|
||||
function sing_box_supports_tailscale(ctx, version, version_output) {
|
||||
if (command_exists("sing-box") && sing_box_compressed_marker_set(ctx))
|
||||
if (command_exists("sing-box") && (sing_box_compressed_marker_set(ctx) || sing_box_lx_marker_set(ctx)))
|
||||
return true;
|
||||
|
||||
if (sing_box_is_extended(ctx, version))
|
||||
@@ -2080,6 +2080,11 @@ function managed_sing_box_service_script(marker) {
|
||||
"PROG=\"/usr/bin/sing-box\"\n" +
|
||||
"\n" +
|
||||
"start_service() {\n" +
|
||||
" [ -d /dev/net ] || mkdir -p /dev/net\n" +
|
||||
" [ -c /dev/net/tun ] || mknod /dev/net/tun c 10 200 2>/dev/null || true\n" +
|
||||
" modprobe tun 2>/dev/null || true\n" +
|
||||
" modprobe inet_diag 2>/dev/null || true\n" +
|
||||
"\n" +
|
||||
" config_load \"sing-box\"\n" +
|
||||
" local enabled config_file working_directory\n" +
|
||||
" local log_stderr\n" +
|
||||
@@ -2337,11 +2342,11 @@ function check_runtime_requirements() {
|
||||
fail_requirement("Package 'sing-box' version (" + sing_box_version + ") is lower than the required minimum (" + ctx.sing_box_required_version + "). Update sing-box: opkg update && opkg remove sing-box && opkg install sing-box. Aborted.", "error");
|
||||
}
|
||||
|
||||
if (!service_exists("sing-box") && sing_box_compressed_marker_set(ctx))
|
||||
if (!service_exists("sing-box") && (sing_box_compressed_marker_set(ctx) || sing_box_lx_marker_set(ctx)))
|
||||
install_managed_sing_box_service_script(ctx);
|
||||
|
||||
if (!service_exists("sing-box"))
|
||||
fail_requirement("Service 'sing-box' is missing. Install a sing-box package or reinstall the compressed sing-box-extended binary variant. Aborted.", "error");
|
||||
fail_requirement("Service 'sing-box' is missing. Install a sing-box package or reinstall sing-box-lx / sing-box-extended binary variant. Aborted.", "error");
|
||||
|
||||
validate_extended_server_features(ctx, sing_box_version, sing_box_version_output);
|
||||
validate_section_action_variant_support(ctx, sing_box_version);
|
||||
|
||||
@@ -379,6 +379,10 @@ function managed_service_text() {
|
||||
"START=99\n" +
|
||||
"PROG=\"/usr/bin/sing-box\"\n\n" +
|
||||
"start_service() {\n" +
|
||||
" [ -d /dev/net ] || mkdir -p /dev/net\n" +
|
||||
" [ -c /dev/net/tun ] || mknod /dev/net/tun c 10 200 2>/dev/null || true\n" +
|
||||
" modprobe tun 2>/dev/null || true\n" +
|
||||
" modprobe inet_diag 2>/dev/null || true\n\n" +
|
||||
" config_load \"sing-box\"\n" +
|
||||
" local enabled config_file working_directory\n" +
|
||||
" local log_stderr\n\n" +
|
||||
|
||||
Reference in New Issue
Block a user