mirror of
https://github.com/kiddin9/op-packages.git
synced 2026-11-14 20:48:17 +08:00
✨ Sync 2026-11-11 01:22:09
This commit is contained in:
1 parent
9c5aa2e662
commit
cc21462d8a
48 files changed
+9760
-59
No files matched your search
@@ -0,0 +1,131 @@
|
||||
#!/bin/sh
|
||||
# SPDX-License-Identifier: GPL-3.0-only
|
||||
#
|
||||
# Copyright (C) 2026 Amr Fateem <amr.fateem@yahoo.com>
|
||||
#
|
||||
# Emit a small key=value report about installed proxy cores and services.
|
||||
# Called by the LuCI overview; values are single-line and contain no newlines.
|
||||
#
|
||||
# This script is read-only. It never installs, removes, starts or stops
|
||||
# anything. It exists so the UI can show that an existing Xray-core or
|
||||
# sing-box installation is present and will not be duplicated or replaced.
|
||||
|
||||
set -u
|
||||
|
||||
first_bin() {
|
||||
for path in "$@"; do
|
||||
if [ -x "$path" ]; then
|
||||
printf '%s' "$path"
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
return 1
|
||||
}
|
||||
|
||||
version_line() {
|
||||
bin="$1"
|
||||
shift
|
||||
[ -n "$bin" ] || return 0
|
||||
"$bin" "$@" 2>/dev/null | sed -n '1p' | tr -d '\r'
|
||||
}
|
||||
|
||||
pkg_list=""
|
||||
if command -v opkg >/dev/null 2>&1; then
|
||||
pkg_list=$(opkg list-installed 2>/dev/null | awk '{ print $1 }')
|
||||
elif command -v apk >/dev/null 2>&1; then
|
||||
pkg_list=$(apk info 2>/dev/null)
|
||||
fi
|
||||
|
||||
pkg_has() {
|
||||
printf '%s\n' "$pkg_list" | grep -qx "$1"
|
||||
}
|
||||
|
||||
core_bin=$(first_bin /usr/bin/v2raya_core /usr/sbin/v2raya_core) || core_bin=""
|
||||
xray_bin=$(first_bin /usr/bin/xray /usr/sbin/xray /usr/bin/xray-core) || xray_bin=""
|
||||
singbox_bin=$(first_bin /usr/bin/sing-box /usr/sbin/sing-box /usr/bin/singbox /usr/sbin/singbox) || singbox_bin=""
|
||||
v2ray_bin=$(first_bin /usr/bin/v2ray /usr/sbin/v2ray /usr/bin/v2ray-core) || v2ray_bin=""
|
||||
|
||||
xray_pkg=0
|
||||
pkg_has xray-core && xray_pkg=1
|
||||
pkg_has xray && xray_pkg=1
|
||||
singbox_pkg=0
|
||||
pkg_has sing-box && singbox_pkg=1
|
||||
v2ray_pkg=0
|
||||
pkg_has v2ray-core && v2ray_pkg=1
|
||||
pkg_has v2ray && v2ray_pkg=1
|
||||
pkg_version() {
|
||||
if command -v opkg >/dev/null 2>&1; then
|
||||
opkg list-installed "$1" 2>/dev/null | awk '{ print $3 }' | sed -n '1p'
|
||||
elif [ -f /lib/apk/db/installed ]; then
|
||||
awk -v p="$1" '$0 == "P:" p { getline; sub(/^V:/, ""); print; exit }' \
|
||||
/lib/apk/db/installed
|
||||
fi
|
||||
}
|
||||
|
||||
version_lt() {
|
||||
[ -n "$1" ] || return 1
|
||||
awk -v a="$1" -v b="$2" 'BEGIN {
|
||||
n = split(a, x, "."); m = split(b, y, ".");
|
||||
for (i = 1; i <= 3; i++) {
|
||||
xs = (i <= n) ? x[i] : 0;
|
||||
ys = (i <= m) ? y[i] : 0;
|
||||
sub(/-.*/, "", xs); sub(/-.*/, "", ys);
|
||||
if (xs + 0 < ys + 0) exit 0;
|
||||
if (xs + 0 > ys + 0) exit 1;
|
||||
}
|
||||
exit 1;
|
||||
}'
|
||||
}
|
||||
|
||||
old_v2raya_pkg=0
|
||||
pkg_has v2raya-nextgen && old_v2raya_pkg=1
|
||||
pkg_has v2raya-core-nextgen && old_v2raya_pkg=1
|
||||
pkg_has luci-app-v2raya-nextgen && old_v2raya_pkg=1
|
||||
if pkg_has v2raya; then
|
||||
version_lt "$(pkg_version v2raya)" "2.5" && old_v2raya_pkg=1
|
||||
fi
|
||||
|
||||
# The upstream packages install to /usr/share/v2ray, while this feed uses
|
||||
# /usr/share/v2raya. Check the configured directory first, then both
|
||||
# well-known paths, so the report is correct with either package set.
|
||||
assets_dirs=""
|
||||
configured_assets=$(uci -q get v2raya.config.v2ray_assetsdir 2>/dev/null) || configured_assets=""
|
||||
[ -n "$configured_assets" ] && assets_dirs="$configured_assets "
|
||||
assets_dirs="$assets_dirs/usr/share/v2ray /usr/local/share/v2ray /usr/share/v2raya /usr/local/share/v2raya"
|
||||
|
||||
geoip_present=0
|
||||
geosite_present=0
|
||||
for dir in $assets_dirs; do
|
||||
[ -f "$dir/geoip.dat" ] && geoip_present=1
|
||||
[ -f "$dir/geosite.dat" ] && geosite_present=1
|
||||
done
|
||||
|
||||
present=""
|
||||
enabled=""
|
||||
for service in xray sing-box v2ray passwall passwall2 ssrplus openclash shellcrash mihomo clash byedpi; do
|
||||
[ -x "/etc/init.d/$service" ] || continue
|
||||
|
||||
present="${present}${present:+,}$service"
|
||||
if "/etc/init.d/$service" enabled >/dev/null 2>&1; then
|
||||
enabled="${enabled}${enabled:+,}$service"
|
||||
fi
|
||||
done
|
||||
|
||||
cat <<EOF
|
||||
core_path=$core_bin
|
||||
core_version=$(version_line "$core_bin" version)
|
||||
xray_path=$xray_bin
|
||||
xray_version=$(version_line "$xray_bin" version)
|
||||
xray_package=$xray_pkg
|
||||
singbox_path=$singbox_bin
|
||||
singbox_version=$(version_line "$singbox_bin" version)
|
||||
singbox_package=$singbox_pkg
|
||||
v2ray_path=$v2ray_bin
|
||||
v2ray_version=$(version_line "$v2ray_bin" version)
|
||||
v2ray_package=$v2ray_pkg
|
||||
old_v2raya_package=$old_v2raya_pkg
|
||||
geoip_present=$geoip_present
|
||||
geosite_present=$geosite_present
|
||||
services_present=$present
|
||||
services_enabled=$enabled
|
||||
EOF
|
||||
@@ -0,0 +1,76 @@
|
||||
# v2rayA configuration
|
||||
#
|
||||
# This file is read by /etc/init.d/v2raya and translated to V2RAYA_*
|
||||
# environment variables. The names intentionally match the old v2rayA feed
|
||||
# so an existing /etc/config/v2raya keeps working after the upgrade.
|
||||
|
||||
config v2raya 'config'
|
||||
# Start the service at boot. The procd instance is also enabled/disabled
|
||||
# by this flag, not only by /etc/rc.d/S99v2raya.
|
||||
option enabled '0'
|
||||
|
||||
# Web UI listening address. Use 127.0.0.1:2017 if you only access it
|
||||
# through an SSH tunnel or a reverse proxy.
|
||||
option address '0.0.0.0:2017'
|
||||
|
||||
# URL prefix when v2rayA sits behind a reverse proxy. Must start with /.
|
||||
option baseurl '/'
|
||||
|
||||
# auto, on or off. Make sure IPv6 works before forcing it on.
|
||||
option ipv6_support 'auto'
|
||||
|
||||
# auto, on or off. nftables is the default on OpenWrt 22.03+.
|
||||
option nftables_support 'auto'
|
||||
|
||||
# Seconds to wait for v2raya_core to start. Raise this on slow MIPS
|
||||
# devices if the core is reported as failing to start.
|
||||
option core_startup_timeout '15'
|
||||
|
||||
# trace, debug, info, warn or error. Warn keeps the flash writes down
|
||||
# on a router; use info while debugging.
|
||||
option log_level 'warn'
|
||||
|
||||
# Number of days to keep rotated log files.
|
||||
option log_max_days '1'
|
||||
|
||||
# The log file already contains timestamps and no terminal colours.
|
||||
option log_disable_color '1'
|
||||
option log_disable_timestamp '0'
|
||||
|
||||
# Soft Go memory limit for both v2raya and v2raya_core (GOMEMLIMIT).
|
||||
# 0 disables the limit. 64MiB is a safe start on a 256MiB router.
|
||||
option gomemlimit '64MiB'
|
||||
|
||||
# Go scheduler threads (GOMAXPROCS). 0 uses every CPU core; 2 is
|
||||
# enough for a home router and uses fewer scheduler resources.
|
||||
option gomaxprocs '2'
|
||||
|
||||
# Go GC target percentage (GOGC). 0 keeps the Go default; lower values
|
||||
# use less memory at the cost of more CPU.
|
||||
option gogc '0'
|
||||
|
||||
# Maximum open file descriptors. 16384 is plenty for a home router and
|
||||
# stops a connection flood from exhausting memory.
|
||||
option nofile '16384'
|
||||
|
||||
# Directory containing geoip.dat and geosite.dat. Leave empty to let
|
||||
# v2rayA search the standard locations.
|
||||
option v2ray_assetsdir '/usr/share/v2raya'
|
||||
|
||||
# Path to v2raya_core. Leave empty to auto-detect the binary next to
|
||||
# /usr/bin/v2raya or in PATH.
|
||||
option v2ray_bin ''
|
||||
|
||||
# Extra v2ray configuration directory merged into the generated config.
|
||||
option v2ray_confdir ''
|
||||
|
||||
# Hooks run around transparent-proxy and core life-cycle events.
|
||||
# v2rayA passes --stage (pre-start, post-start, pre-stop, post-stop) and,
|
||||
# for the transparent hook, --transparent-type (tproxy, redirect).
|
||||
option transparent_hook ''
|
||||
option core_hook ''
|
||||
option plugin_manager ''
|
||||
|
||||
# [Linux] In redirect mode, let sockets bound to a device bypass the
|
||||
# proxy. Requires kernel 5.14+ and cgroup v2.
|
||||
option redirect_respect_bound_device '0'
|
||||
@@ -0,0 +1,115 @@
|
||||
#!/bin/sh /etc/rc.common
|
||||
# SPDX-License-Identifier: GPL-3.0-only
|
||||
#
|
||||
# Copyright (C) 2026 Amr Fateem <amr.fateem@yahoo.com>
|
||||
#
|
||||
# procd init script for v2rayA.
|
||||
#
|
||||
# All settings are kept in UCI (/etc/config/v2raya) and passed to v2rayA as
|
||||
# V2RAYA_* environment variables, which is the interface gonfig documents
|
||||
# upstream. Keeping the command line short also means paths with spaces or
|
||||
# shell metacharacters cannot break the service.
|
||||
#
|
||||
# shellcheck disable=SC2034
|
||||
# shellcheck disable=SC3043
|
||||
|
||||
USE_PROCD=1
|
||||
START=99
|
||||
STOP=10
|
||||
|
||||
CONF="v2raya"
|
||||
PROG="/usr/bin/v2raya"
|
||||
CONF_DIR="/etc/v2raya"
|
||||
LOG_DIR="/var/log/v2raya"
|
||||
DEFAULT_ASSETS="/usr/share/v2raya"
|
||||
|
||||
is_enabled() {
|
||||
local enabled
|
||||
config_get_bool enabled "$1" "$2" "${3:-0}"
|
||||
[ "$enabled" -eq 1 ]
|
||||
}
|
||||
|
||||
append_env() {
|
||||
procd_append_param env "V2RAYA_$(echo "$1" | tr 'a-z' 'A-Z')=$2"
|
||||
}
|
||||
|
||||
append_env_arg() {
|
||||
local value
|
||||
config_get value "$1" "$2" "$3"
|
||||
[ -n "$value" ] && append_env "$2" "$value"
|
||||
}
|
||||
|
||||
append_env_bool() {
|
||||
is_enabled "$1" "$2" && append_env "$2" "true"
|
||||
}
|
||||
|
||||
start_service() {
|
||||
config_load "$CONF"
|
||||
|
||||
is_enabled "config" "enabled" || return 0
|
||||
|
||||
local assets_dir gomemlimit gomaxprocs gogc nofile
|
||||
config_get assets_dir "config" "v2ray_assetsdir" "$DEFAULT_ASSETS"
|
||||
config_get gomemlimit "config" "gomemlimit" "64MiB"
|
||||
config_get gomaxprocs "config" "gomaxprocs" "2"
|
||||
config_get gogc "config" "gogc" "0"
|
||||
config_get nofile "config" "nofile" "16384"
|
||||
|
||||
mkdir -p "$CONF_DIR" "$LOG_DIR"
|
||||
[ -n "$assets_dir" ] && mkdir -p "$assets_dir"
|
||||
chmod 750 "$CONF_DIR"
|
||||
chmod 755 "$LOG_DIR"
|
||||
|
||||
procd_open_instance "$CONF"
|
||||
procd_set_param command "$PROG"
|
||||
procd_set_param env "V2RAYA_CONFIG=$CONF_DIR" "V2RAYA_LOG_FILE=$LOG_DIR/v2raya.log"
|
||||
|
||||
# The core inherits this environment, so one limit covers both processes.
|
||||
[ -n "$gomemlimit" ] && [ "$gomemlimit" != "0" ] && \
|
||||
procd_append_param env "GOMEMLIMIT=$gomemlimit"
|
||||
[ -n "$gomaxprocs" ] && [ "$gomaxprocs" -gt 0 ] 2>/dev/null && \
|
||||
procd_append_param env "GOMAXPROCS=$gomaxprocs"
|
||||
[ -n "$gogc" ] && [ "$gogc" -gt 0 ] 2>/dev/null && \
|
||||
procd_append_param env "GOGC=$gogc"
|
||||
|
||||
append_env_arg "config" "v2ray_assetsdir" "$DEFAULT_ASSETS"
|
||||
append_env_arg "config" "address" "0.0.0.0:2017"
|
||||
append_env_arg "config" "baseurl" "/"
|
||||
append_env_arg "config" "ipv6_support" "auto"
|
||||
append_env_arg "config" "nftables_support" "auto"
|
||||
append_env_arg "config" "core_startup_timeout" "15"
|
||||
append_env_arg "config" "log_level" "warn"
|
||||
append_env_arg "config" "log_max_days" "1"
|
||||
append_env_arg "config" "v2ray_bin"
|
||||
append_env_arg "config" "v2ray_confdir"
|
||||
append_env_arg "config" "transparent_hook"
|
||||
append_env_arg "config" "core_hook"
|
||||
append_env_arg "config" "plugin_manager"
|
||||
|
||||
append_env_bool "config" "log_disable_color"
|
||||
append_env_bool "config" "log_disable_timestamp"
|
||||
append_env_bool "config" "redirect_respect_bound_device"
|
||||
|
||||
# No core dumps on a router: they fill the overlay and can trip a
|
||||
# marginal NAND. A 16384 descriptor ceiling is plenty for the LAN and
|
||||
# keeps a connection flood from allocating unbounded socket buffers.
|
||||
[ -n "$nofile" ] || nofile=16384
|
||||
procd_set_param limits core="0 0"
|
||||
procd_set_param limits nofile="$nofile $nofile"
|
||||
procd_set_param respawn
|
||||
procd_set_param term_timeout 30
|
||||
procd_set_param stdout 1
|
||||
procd_set_param stderr 1
|
||||
|
||||
procd_close_instance
|
||||
}
|
||||
|
||||
reload_service() {
|
||||
# v2rayA does not reload its configuration on SIGHUP; a restart is the
|
||||
# only safe way to apply new UCI values.
|
||||
restart
|
||||
}
|
||||
|
||||
service_triggers() {
|
||||
procd_add_reload_trigger "$CONF"
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
/etc/v2raya
|
||||
Binary file not shown.
Reference in new issue
Block a user