mihomo: sync upstream

last commit: d641bfc31c
This commit is contained in:
gitea-action 2024-09-30 11:00:48 +08:00
parent 722ef65e53
commit 75d53d73fe
6 changed files with 47 additions and 32 deletions

View File

@ -5,9 +5,9 @@ PKG_RELEASE:=1
PKG_SOURCE_PROTO:=git PKG_SOURCE_PROTO:=git
PKG_SOURCE_URL:=https://github.com/MetaCubeX/mihomo.git PKG_SOURCE_URL:=https://github.com/MetaCubeX/mihomo.git
PKG_SOURCE_DATE:=2024-09-28 PKG_SOURCE_DATE:=2024-09-29
PKG_SOURCE_VERSION:=264713571d349d214ec938911de0de033b8673af PKG_SOURCE_VERSION:=fc9d5cfee944a75b989d17c637a321e73c52093a
PKG_MIRROR_HASH:=1df27333ff05ab29e1e01b1623b6f526de0191c4dc82762fe0ac31b1a4bc52cf PKG_MIRROR_HASH:=47c8d16a3bd5536bc4659c0827e5cf561fc6682cbbd4af0b07f065ee930a38dc
PKG_LICENSE:=MIT PKG_LICENSE:=MIT
PKG_MAINTAINER:=Joseph Mory <morytyann@gmail.com> PKG_MAINTAINER:=Joseph Mory <morytyann@gmail.com>
@ -16,7 +16,7 @@ PKG_BUILD_DEPENDS:=golang/host
PKG_BUILD_PARALLEL:=1 PKG_BUILD_PARALLEL:=1
PKG_BUILD_FLAGS:=no-mips16 PKG_BUILD_FLAGS:=no-mips16
PKG_BUILD_VERSION:=alpha-2647135 PKG_BUILD_VERSION:=alpha-fc9d5cf
PKG_BUILD_TIME:=$(shell date -u -Iseconds) PKG_BUILD_TIME:=$(shell date -u -Iseconds)
GO_PKG:=github.com/metacubex/mihomo GO_PKG:=github.com/metacubex/mihomo
@ -85,6 +85,26 @@ define Package/mihomo/install
$(INSTALL_DATA) $(CURDIR)/files/mihomo.upgrade $(1)/lib/upgrade/keep.d/mihomo $(INSTALL_DATA) $(CURDIR)/files/mihomo.upgrade $(1)/lib/upgrade/keep.d/mihomo
endef endef
define Package/mihomo/postinst
#!/bin/sh
uci -q batch <<-EOF > /dev/null
del firewall.mihomo
set firewall.mihomo=include
set firewall.mihomo.type=script
set firewall.mihomo.path=/etc/mihomo/scripts/tun.sh
set firewall.mihomo.fw4_compatible=1
commit firewall
EOF
endef
define Package/mihomo/postrm
#!/bin/sh
uci -q batch <<-EOF > /dev/null
del firewall.mihomo
commit firewall
EOF
endef
define Build/Prepare define Build/Prepare
$(Build/Prepare/Default) $(Build/Prepare/Default)
$(RM) -r $(PKG_BUILD_DIR)/rules/logic_test $(RM) -r $(PKG_BUILD_DIR)/rules/logic_test

View File

@ -30,7 +30,7 @@ config proxy 'proxy'
config subscription 'subscription' config subscription 'subscription'
option 'name' 'default' option 'name' 'default'
option 'url' 'http://example.com/default.yaml' option 'url' 'http://example.com/default.yaml'
option 'user_agent' 'mihomo' option 'user_agent' 'clash'
config mixin 'mixin' config mixin 'mixin'
option 'log_level' 'info' option 'log_level' 'info'

View File

@ -9,7 +9,7 @@ USE_PROCD=1
start_service() { start_service() {
# clear log # clear log
clear_all_log clear_log
# load config # load config
config_load mihomo config_load mihomo
# check if enabled # check if enabled
@ -135,6 +135,8 @@ start_service() {
fi fi
log "Use Subscription: $subscription_name" log "Use Subscription: $subscription_name"
else else
log "No profile/subscription selected."
log "Exiting..."
return return
fi fi
# mixin # mixin
@ -215,7 +217,7 @@ start_service() {
# test profile # test profile
if [ "$test_profile" == 1 ]; then if [ "$test_profile" == 1 ]; then
log "Profile testing..." log "Profile testing..."
if ($PROG -d "$RUN_DIR" -t >> "$RUN_CORE_LOG_PATH" 2>&1); then if ($PROG -d "$RUN_DIR" -t >> "$CORE_LOG_PATH" 2>&1); then
log "Profile test passed!" log "Profile test passed!"
else else
log "Profile test failed!" log "Profile test failed!"
@ -227,7 +229,7 @@ start_service() {
log "Start Core" log "Start Core"
procd_open_instance mihomo procd_open_instance mihomo
procd_set_param command /bin/sh -c "$PROG -d $RUN_DIR >> $RUN_CORE_LOG_PATH 2>&1" procd_set_param command /bin/sh -c "$PROG -d $RUN_DIR >> $CORE_LOG_PATH 2>&1"
procd_set_param file "$RUN_PROFILE_PATH" procd_set_param file "$RUN_PROFILE_PATH"
if [ "$fast_reload" == 1 ]; then if [ "$fast_reload" == 1 ]; then
procd_set_param reload_signal HUP procd_set_param reload_signal HUP
@ -241,7 +243,7 @@ start_service() {
procd_add_jail mihomo requirejail procfs procd_add_jail mihomo requirejail procfs
procd_add_jail_mount "$PROG" /etc/TZ /etc/localtime /etc/hosts /etc/ssl/certs procd_add_jail_mount "$PROG" /etc/TZ /etc/localtime /etc/hosts /etc/ssl/certs
procd_add_jail_mount_rw "$RUN_DIR" /dev/net procd_add_jail_mount_rw "$RUN_DIR" "$LOG_DIR" /dev/net
procd_set_param capabilities /etc/capabilities/mihomo.json procd_set_param capabilities /etc/capabilities/mihomo.json
procd_set_param no_new_privs 1 procd_set_param no_new_privs 1
@ -249,7 +251,7 @@ start_service() {
# transparent proxy # transparent proxy
if [ "$transparent_proxy" == 1 ]; then if [ "$transparent_proxy" == 1 ]; then
log "Transparent Proxy is enabled." log "Transparent Proxy is enabled."
log "Transparent Proxy: Start hijack." log "Transparent Proxy: Start."
# prepare # prepare
if [ "$tproxy_enable" == 1 ]; then if [ "$tproxy_enable" == 1 ]; then
if [ "$ipv4_proxy" == 1 ]; then if [ "$ipv4_proxy" == 1 ]; then
@ -417,11 +419,11 @@ cleanup() {
# delete hijack # delete hijack
nft delete table inet "$FW_TABLE" > /dev/null 2>&1 nft delete table inet "$FW_TABLE" > /dev/null 2>&1
local handles handle local handles handle
handles=$(nft --json list table inet fw4 | yq '.nftables[] | select(has("rule")) | .rule | select(.family == "inet" and .table == "fw4" and .chain == "input" and .expr[0].match.right == "tun") | .handle') handles=$(nft --json list table inet fw4 | yq '.nftables[] | select(has("rule")) | .rule | select(.chain == "input" and .comment == "mihomo") | .handle')
for handle in $handles; do for handle in $handles; do
nft delete rule inet fw4 input handle "$handle" nft delete rule inet fw4 input handle "$handle"
done done
handles=$(nft --json list table inet fw4 | yq '.nftables[] | select(has("rule")) | .rule | select(.family == "inet" and .table == "fw4" and .chain == "forward" and .expr[0].match.right == "tun") | .handle') handles=$(nft --json list table inet fw4 | yq '.nftables[] | select(has("rule")) | .rule | select(.chain == "forward" and .comment == "mihomo") | .handle')
for handle in $handles; do for handle in $handles; do
nft delete rule inet fw4 forward handle "$handle" nft delete rule inet fw4 forward handle "$handle"
done done
@ -431,12 +433,14 @@ cleanup() {
} }
log() { log() {
echo "[$(date '+%Y-%m-%d %H:%M:%S')] $1" >> "$RUN_APP_LOG_PATH" echo "[$(date '+%Y-%m-%d %H:%M:%S')] $1" >> "$APP_LOG_PATH"
} }
clear_all_log() { clear_log() {
echo -n > "$RUN_APP_LOG_PATH" if [ -d "$LOG_DIR" ]; then
echo -n > "$RUN_CORE_LOG_PATH" rm -rf "$LOG_DIR"
fi
mkdir "$LOG_DIR"
} }
mixin_authentications() { mixin_authentications() {

View File

@ -12,7 +12,7 @@ TCP_RULE_PREF="1024"
UDP_RULE_PREF="1025" UDP_RULE_PREF="1025"
TPROXY_ROUTE_TABLE="80" TPROXY_ROUTE_TABLE="80"
TUN_ROUTE_TABLE="81" TUN_ROUTE_TABLE="81"
TUN_DEVICE="tun" TUN_DEVICE="mihomo"
# paths # paths
PROG="/usr/bin/mihomo" PROG="/usr/bin/mihomo"
@ -20,10 +20,11 @@ HOME_DIR="/etc/mihomo"
PROFILES_DIR="$HOME_DIR/profiles" PROFILES_DIR="$HOME_DIR/profiles"
MIXIN_FILE_PATH="$HOME_DIR/mixin.yaml" MIXIN_FILE_PATH="$HOME_DIR/mixin.yaml"
RUN_DIR="$HOME_DIR/run" RUN_DIR="$HOME_DIR/run"
RUN_APP_LOG_PATH="$RUN_DIR/app.log"
RUN_CORE_LOG_PATH="$RUN_DIR/core.log"
RUN_PROFILE_PATH="$RUN_DIR/config.yaml" RUN_PROFILE_PATH="$RUN_DIR/config.yaml"
RUN_UI_DIR="$RUN_DIR/ui" RUN_UI_DIR="$RUN_DIR/ui"
LOG_DIR="/var/log/mihomo"
APP_LOG_PATH="$LOG_DIR/app.log"
CORE_LOG_PATH="$LOG_DIR/core.log"
# scripts # scripts
SH_DIR="$HOME_DIR/scripts" SH_DIR="$HOME_DIR/scripts"

View File

@ -9,9 +9,9 @@ config_get tcp_transparent_proxy_mode "proxy" "tcp_transparent_proxy_mode"
config_get udp_transparent_proxy_mode "proxy" "udp_transparent_proxy_mode" config_get udp_transparent_proxy_mode "proxy" "udp_transparent_proxy_mode"
if [ "$enabled" == 1 ] && [[ "$tcp_transparent_proxy_mode" == "tun" || "$udp_transparent_proxy_mode" == "tun" ]]; then if [ "$enabled" == 1 ] && [[ "$tcp_transparent_proxy_mode" == "tun" || "$udp_transparent_proxy_mode" == "tun" ]]; then
nft insert rule inet fw4 input iifname "$TUN_DEVICE" counter accept nft insert rule inet fw4 input iifname "$TUN_DEVICE" counter accept comment "mihomo"
nft insert rule inet fw4 forward oifname "$TUN_DEVICE" counter accept nft insert rule inet fw4 forward oifname "$TUN_DEVICE" counter accept comment "mihomo"
nft insert rule inet fw4 forward iifname "$TUN_DEVICE" counter accept nft insert rule inet fw4 forward iifname "$TUN_DEVICE" counter accept comment "mihomo"
fi fi
exit 0 exit 0

View File

@ -2,16 +2,6 @@
. "$IPKG_INSTROOT/etc/mihomo/scripts/constants.sh" . "$IPKG_INSTROOT/etc/mihomo/scripts/constants.sh"
# add firewall include for tun
uci -q batch <<-EOF > /dev/null
delete firewall.mihomo
set firewall.mihomo=include
set firewall.mihomo.type=script
set firewall.mihomo.path=$TUN_SH
set firewall.mihomo.fw4_compatible=1
commit firewall
EOF
# check mihomo.config.init # check mihomo.config.init
init=$(uci -q get mihomo.config.init); [ -z "$init" ] && return init=$(uci -q get mihomo.config.init); [ -z "$init" ] && return