parent
f453bb76cd
commit
5feeddd3d9
@ -1,7 +1,7 @@
|
|||||||
include $(TOPDIR)/rules.mk
|
include $(TOPDIR)/rules.mk
|
||||||
|
|
||||||
PKG_NAME:=mihomo
|
PKG_NAME:=mihomo
|
||||||
PKG_RELEASE:=2
|
PKG_RELEASE:=3
|
||||||
|
|
||||||
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
|
||||||
@ -59,8 +59,8 @@ define Package/mihomo/install
|
|||||||
|
|
||||||
$(INSTALL_DATA) $(CURDIR)/files/mixin.yaml $(1)/etc/mihomo/mixin.yaml
|
$(INSTALL_DATA) $(CURDIR)/files/mixin.yaml $(1)/etc/mihomo/mixin.yaml
|
||||||
|
|
||||||
$(INSTALL_BIN) $(CURDIR)/files/scripts/constants.sh $(1)/etc/mihomo/scripts/constants.sh
|
$(INSTALL_BIN) $(CURDIR)/files/scripts/include.sh $(1)/etc/mihomo/scripts/include.sh
|
||||||
$(INSTALL_BIN) $(CURDIR)/files/scripts/tun.sh $(1)/etc/mihomo/scripts/tun.sh
|
$(INSTALL_BIN) $(CURDIR)/files/scripts/firewall_include.sh $(1)/etc/mihomo/scripts/firewall_include.sh
|
||||||
|
|
||||||
$(INSTALL_BIN) $(CURDIR)/files/nftables/hijack.nft $(1)/etc/mihomo/nftables/hijack.nft
|
$(INSTALL_BIN) $(CURDIR)/files/nftables/hijack.nft $(1)/etc/mihomo/nftables/hijack.nft
|
||||||
$(INSTALL_BIN) $(CURDIR)/files/nftables/reserved_ip.nft $(1)/etc/mihomo/nftables/reserved_ip.nft
|
$(INSTALL_BIN) $(CURDIR)/files/nftables/reserved_ip.nft $(1)/etc/mihomo/nftables/reserved_ip.nft
|
||||||
|
@ -5,7 +5,7 @@ STOP=10
|
|||||||
USE_PROCD=1
|
USE_PROCD=1
|
||||||
|
|
||||||
. "$IPKG_INSTROOT/lib/functions/network.sh"
|
. "$IPKG_INSTROOT/lib/functions/network.sh"
|
||||||
. "$IPKG_INSTROOT/etc/mihomo/scripts/constants.sh"
|
. "$IPKG_INSTROOT/etc/mihomo/scripts/include.sh"
|
||||||
|
|
||||||
extra_command 'update_subscription' 'Update subscription by section id'
|
extra_command 'update_subscription' 'Update subscription by section id'
|
||||||
|
|
||||||
@ -18,7 +18,7 @@ boot() {
|
|||||||
local enabled start_delay
|
local enabled start_delay
|
||||||
config_get_bool enabled "config" "enabled" 0
|
config_get_bool enabled "config" "enabled" 0
|
||||||
config_get start_delay "config" "start_delay" 0
|
config_get start_delay "config" "start_delay" 0
|
||||||
if [[ "$enabled" == 1 && "$start_delay" > 0 ]]; then
|
if [[ "$enabled" == 1 && "$start_delay" -gt 0 ]]; then
|
||||||
log "App will start after $start_delay seconds."
|
log "App will start after $start_delay seconds."
|
||||||
sleep "$start_delay"
|
sleep "$start_delay"
|
||||||
fi
|
fi
|
||||||
@ -159,22 +159,8 @@ start_service() {
|
|||||||
cp -f "$profile_file" "$RUN_PROFILE_PATH"
|
cp -f "$profile_file" "$RUN_PROFILE_PATH"
|
||||||
elif [[ "$profile" == "subscription:"* ]]; then
|
elif [[ "$profile" == "subscription:"* ]]; then
|
||||||
local subscription_section; subscription_section="${profile/subscription:/}"
|
local subscription_section; subscription_section="${profile/subscription:/}"
|
||||||
local subscription_name subscription_url subscription_user_agent subscription_prefer
|
|
||||||
config_get subscription_name "$subscription_section" "name"
|
|
||||||
config_get subscription_url "$subscription_section" "url"
|
|
||||||
config_get subscription_user_agent "$subscription_section" "user_agent"
|
|
||||||
config_get subscription_prefer "$subscription_section" "prefer" "remote"
|
|
||||||
log "Use Subscription: $subscription_name."
|
|
||||||
local subscription_tmpfile; subscription_tmpfile="/tmp/$subscription_section.yaml"
|
|
||||||
local subscription_file; subscription_file="$SUBSCRIPTIONS_DIR/$subscription_section.yaml"
|
local subscription_file; subscription_file="$SUBSCRIPTIONS_DIR/$subscription_section.yaml"
|
||||||
if [ "$subscription_prefer" == "remote" ] || [[ "$subscription_prefer" == "local" && ! -f "$subscription_file" ]]; then
|
update_subscription "$subscription_section"
|
||||||
if (curl -s -f --connect-timeout 15 --retry 3 -o "$subscription_tmpfile" -L -H "User-Agent: $subscription_user_agent" "$subscription_url"); then
|
|
||||||
log "Subscription download succeed."
|
|
||||||
cp -f "$subscription_tmpfile" "$subscription_file"
|
|
||||||
else
|
|
||||||
log "Subscription download failed, fallback to subscription file."
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
if [ ! -f "$subscription_file" ]; then
|
if [ ! -f "$subscription_file" ]; then
|
||||||
log "Subscription file not found."
|
log "Subscription file not found."
|
||||||
log "Exiting..."
|
log "Exiting..."
|
||||||
@ -244,8 +230,7 @@ start_service() {
|
|||||||
fi
|
fi
|
||||||
yq -M -i 'del (.bind-address)' "$RUN_PROFILE_PATH"
|
yq -M -i 'del (.bind-address)' "$RUN_PROFILE_PATH"
|
||||||
if [ -n "$outbound_interface" ]; then
|
if [ -n "$outbound_interface" ]; then
|
||||||
local outbound_device
|
local outbound_device; network_get_device outbound_device "$outbound_interface"
|
||||||
network_get_device outbound_device "$outbound_interface"
|
|
||||||
if [ -n "$outbound_device" ]; then
|
if [ -n "$outbound_device" ]; then
|
||||||
outbound_device="$outbound_device" yq -M -i '.interface-name = env(outbound_device)' "$RUN_PROFILE_PATH"
|
outbound_device="$outbound_device" yq -M -i '.interface-name = env(outbound_device)' "$RUN_PROFILE_PATH"
|
||||||
fi
|
fi
|
||||||
@ -313,7 +298,7 @@ start_service() {
|
|||||||
if [ "$ipv6_proxy" == 1 ]; then
|
if [ "$ipv6_proxy" == 1 ]; then
|
||||||
ip -6 route add unicast default dev "$TUN_DEVICE" table "$TUN_ROUTE_TABLE"
|
ip -6 route add unicast default dev "$TUN_DEVICE" table "$TUN_ROUTE_TABLE"
|
||||||
fi
|
fi
|
||||||
$TUN_SH
|
$FIREWALL_INCLUDE_SH
|
||||||
fi
|
fi
|
||||||
local tcp_route_table
|
local tcp_route_table
|
||||||
if [ "$tcp_transparent_proxy_mode" == "tproxy" ]; then
|
if [ "$tcp_transparent_proxy_mode" == "tproxy" ]; then
|
||||||
@ -635,14 +620,55 @@ add_acl_interface() {
|
|||||||
|
|
||||||
update_subscription() {
|
update_subscription() {
|
||||||
local subscription_section; subscription_section="$1"
|
local subscription_section; subscription_section="$1"
|
||||||
if [ -n "$subscription_section" ]; then
|
if [ -z "$subscription_section" ]; then
|
||||||
config_load mihomo
|
return
|
||||||
local profile subscription_name subscription_url subscription_user_agent
|
fi
|
||||||
config_get profile "config" "profile"
|
config_load mihomo
|
||||||
config_get subscription_name "$subscription_section" "name"
|
local subscription_name subscription_url subscription_user_agent
|
||||||
config_get subscription_url "$subscription_section" "url"
|
config_get subscription_name "$subscription_section" "name"
|
||||||
config_get subscription_user_agent "$subscription_section" "user_agent"
|
config_get subscription_url "$subscription_section" "url"
|
||||||
local subscription_file; subscription_file="$SUBSCRIPTIONS_DIR/$subscription_section.yaml"
|
config_get subscription_user_agent "$subscription_section" "user_agent"
|
||||||
curl -s -f --connect-timeout 15 --retry 3 -o "$subscription_file" -L -H "User-Agent: $subscription_user_agent" "$subscription_url"
|
log "Update Subscription: $subscription_name."
|
||||||
|
local subscription_header_tmpfile; subscription_header_tmpfile="/tmp/$subscription_section.header"
|
||||||
|
local subscription_tmpfile; subscription_tmpfile="/tmp/$subscription_section.yaml"
|
||||||
|
local subscription_file; subscription_file="$SUBSCRIPTIONS_DIR/$subscription_section.yaml"
|
||||||
|
if (curl -s -f --connect-timeout 15 --retry 3 -L -X GET -H "User-Agent: $subscription_user_agent" -D "$subscription_header_tmpfile" -o "$subscription_tmpfile" "$subscription_url"); then
|
||||||
|
log "Subscription update succeed."
|
||||||
|
local subscription_expire subscription_upload subscription_download subscription_total subscription_used subscription_avaliable
|
||||||
|
subscription_expire=$(grep "subscription-userinfo: " "$subscription_header_tmpfile" | grep -o -E "expire=[[:digit:]]+" | cut -d '=' -f 2)
|
||||||
|
subscription_upload=$(grep "subscription-userinfo: " "$subscription_header_tmpfile" | grep -o -E "upload=[[:digit:]]+" | cut -d '=' -f 2)
|
||||||
|
subscription_download=$(grep "subscription-userinfo: " "$subscription_header_tmpfile" | grep -o -E "download=[[:digit:]]+" | cut -d '=' -f 2)
|
||||||
|
subscription_total=$(grep "subscription-userinfo: " "$subscription_header_tmpfile" | grep -o -E "total=[[:digit:]]+" | cut -d '=' -f 2)
|
||||||
|
if [[ -n "$subscription_upload" && -n "$subscription_download" ]]; then
|
||||||
|
subscription_used=$((subscription_upload + subscription_download))
|
||||||
|
if [ -n "$subscription_total" ]; then
|
||||||
|
subscription_avaliable=$((subscription_total - subscription_upload - subscription_download))
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
if [ -n "$subscription_expire" ]; then
|
||||||
|
uci_set "mihomo" "$subscription_section" "expire" "$(date +%Y-%m-%d -d @$subscription_expire)"
|
||||||
|
fi
|
||||||
|
if [ -n "$subscription_upload" ]; then
|
||||||
|
uci_set "mihomo" "$subscription_section" "upload" "$(format_filesize $subscription_upload)"
|
||||||
|
fi
|
||||||
|
if [ -n "$subscription_download" ]; then
|
||||||
|
uci_set "mihomo" "$subscription_section" "download" "$(format_filesize $subscription_download)"
|
||||||
|
fi
|
||||||
|
if [ -n "$subscription_total" ]; then
|
||||||
|
uci_set "mihomo" "$subscription_section" "total" "$(format_filesize $subscription_total)"
|
||||||
|
fi
|
||||||
|
if [ -n "$subscription_used" ]; then
|
||||||
|
uci_set "mihomo" "$subscription_section" "used" "$(format_filesize $subscription_used)"
|
||||||
|
fi
|
||||||
|
if [ -n "$subscription_avaliable" ]; then
|
||||||
|
uci_set "mihomo" "$subscription_section" "avaliable" "$(format_filesize $subscription_avaliable)"
|
||||||
|
fi
|
||||||
|
uci_commit "mihomo"
|
||||||
|
rm -f "$subscription_header_tmpfile"
|
||||||
|
mv -f "$subscription_tmpfile" "$subscription_file"
|
||||||
|
else
|
||||||
|
log "Subscription update failed."
|
||||||
|
rm -f "$subscription_header_tmpfile"
|
||||||
|
rm -f "$subscription_tmpfile"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
. "$IPKG_INSTROOT/lib/functions.sh"
|
. "$IPKG_INSTROOT/lib/functions.sh"
|
||||||
. "$IPKG_INSTROOT/etc/mihomo/scripts/constants.sh"
|
. "$IPKG_INSTROOT/etc/mihomo/scripts/include.sh"
|
||||||
|
|
||||||
config_load mihomo
|
config_load mihomo
|
||||||
config_get enabled "config" "enabled" 0
|
config_get enabled "config" "enabled" 0
|
@ -29,7 +29,8 @@ CORE_LOG_PATH="$LOG_DIR/core.log"
|
|||||||
|
|
||||||
# scripts
|
# scripts
|
||||||
SH_DIR="$HOME_DIR/scripts"
|
SH_DIR="$HOME_DIR/scripts"
|
||||||
TUN_SH="$SH_DIR/tun.sh"
|
INCLUDE_SH="$SH_DIR/include.sh"
|
||||||
|
FIREWALL_INCLUDE_SH="$SH_DIR/firewall_include.sh"
|
||||||
|
|
||||||
# nftables
|
# nftables
|
||||||
NFT_DIR="$HOME_DIR/nftables"
|
NFT_DIR="$HOME_DIR/nftables"
|
||||||
@ -38,3 +39,28 @@ RESERVED_IP_NFT="$NFT_DIR/reserved_ip.nft"
|
|||||||
RESERVED_IP6_NFT="$NFT_DIR/reserved_ip6.nft"
|
RESERVED_IP6_NFT="$NFT_DIR/reserved_ip6.nft"
|
||||||
GEOIP_CN_NFT="$NFT_DIR/geoip_cn.nft"
|
GEOIP_CN_NFT="$NFT_DIR/geoip_cn.nft"
|
||||||
GEOIP6_CN_NFT="$NFT_DIR/geoip6_cn.nft"
|
GEOIP6_CN_NFT="$NFT_DIR/geoip6_cn.nft"
|
||||||
|
|
||||||
|
# functions
|
||||||
|
format_filesize() {
|
||||||
|
local kb; kb=1024
|
||||||
|
local mb; mb=$((kb * 1024))
|
||||||
|
local gb; gb=$((mb * 1024))
|
||||||
|
local tb; tb=$((gb * 1024))
|
||||||
|
local pb; pb=$((tb * 1024))
|
||||||
|
local size; size="$1"
|
||||||
|
if [ -z "$size" ]; then
|
||||||
|
echo ""
|
||||||
|
elif [ "$size" -lt "$kb" ]; then
|
||||||
|
echo "$size B"
|
||||||
|
elif [ "$size" -lt "$mb" ]; then
|
||||||
|
echo "$(awk "BEGIN {print $size / $kb}") KB"
|
||||||
|
elif [ "$size" -lt "$gb" ]; then
|
||||||
|
echo "$(awk "BEGIN {print $size / $mb}") MB"
|
||||||
|
elif [ "$size" -lt "$tb" ]; then
|
||||||
|
echo "$(awk "BEGIN {print $size / $gb}") GB"
|
||||||
|
elif [ "$size" -lt "$pb" ]; then
|
||||||
|
echo "$(awk "BEGIN {print $size / $tb}") TB"
|
||||||
|
else
|
||||||
|
echo "$(awk "BEGIN {print $size / $pb}") PB"
|
||||||
|
fi
|
||||||
|
}
|
@ -1,12 +1,12 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
. "$IPKG_INSTROOT/etc/mihomo/scripts/constants.sh"
|
. "$IPKG_INSTROOT/etc/mihomo/scripts/include.sh"
|
||||||
|
|
||||||
uci -q batch <<-EOF > /dev/null
|
uci -q batch <<-EOF > /dev/null
|
||||||
del firewall.mihomo
|
del firewall.mihomo
|
||||||
set firewall.mihomo=include
|
set firewall.mihomo=include
|
||||||
set firewall.mihomo.type=script
|
set firewall.mihomo.type=script
|
||||||
set firewall.mihomo.path=$TUN_SH
|
set firewall.mihomo.path=$FIREWALL_INCLUDE_SH
|
||||||
set firewall.mihomo.fw4_compatible=1
|
set firewall.mihomo.fw4_compatible=1
|
||||||
commit firewall
|
commit firewall
|
||||||
EOF
|
EOF
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
. "$IPKG_INSTROOT/etc/mihomo/scripts/constants.sh"
|
. "$IPKG_INSTROOT/etc/mihomo/scripts/include.sh"
|
||||||
|
|
||||||
# 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
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
. "$IPKG_INSTROOT/etc/mihomo/scripts/constants.sh"
|
. "$IPKG_INSTROOT/etc/mihomo/scripts/include.sh"
|
||||||
|
|
||||||
# since v1.8.4
|
# since v1.8.4
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user