mirror of
https://github.com/kiddin9/op-packages.git
synced 2026-11-06 11:24:07 +08:00
🌴 Sync 2026-03-05 23:51:42
This commit is contained in:
1 parent
97c049ed0a
commit
0acff03804
14253 files changed
+3893239
No files matched your search
+17
@@ -0,0 +1,17 @@
|
||||
#!/bin/sh
|
||||
# Thanks to homeproxy
|
||||
|
||||
NAME="fchomo"
|
||||
|
||||
log_max_size="30" #KB
|
||||
main_log_file="/var/run/$NAME/$NAME.log"
|
||||
singc_log_file="/var/run/$NAME/mihomo-c.log"
|
||||
sings_log_file="/var/run/$NAME/mihomo-s.log"
|
||||
|
||||
while true; do
|
||||
sleep 180
|
||||
for i in "$main_log_file" "$singc_log_file" "$sings_log_file"; do
|
||||
[ -s "$i" ] || continue
|
||||
[ "$(( $(ls -l "$i" | awk -F ' ' '{print $5}') / 1024 >= log_max_size))" -eq "0" ] || echo "" > "$i"
|
||||
done
|
||||
done
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Depends: coreutils-timeout
|
||||
#
|
||||
# Author: muink
|
||||
# Ref: https://github.com/muink/luci-app-natmapt/blob/master/root/usr/libexec/natmap/natcheck.sh
|
||||
#
|
||||
# Args: <stun server:port> <udp/tcp> <localport>
|
||||
[ "$#" -ge 3 ] || exit 1
|
||||
stun="$1" && shift
|
||||
l4proto="$1" && shift
|
||||
port="$1" && shift
|
||||
|
||||
echo "$stun" | grep -qE "^[A-Za-z0-9.-]+:[0-9]+$" || exit 1
|
||||
echo "$l4proto" | grep -qE "^(udp|tcp)$" || exit 1
|
||||
echo "$port" | grep -qE "^[0-9]*$" || exit 1
|
||||
|
||||
PROG="$(command -v stunclient)"
|
||||
|
||||
result="$(timeout 30 $PROG --protocol $l4proto --mode full ${port:+--localport $port} ${stun%:*} ${stun#*:} 2>/dev/null)"
|
||||
|
||||
render() {
|
||||
echo "$1" | sed -E "\
|
||||
s,\b((S|s)uccess)\b,<font color=\"green\">\1</font>,g;\
|
||||
s,\b((F|f)ail)\b,<font color=\"#ff331f\">\1</font>,g;\
|
||||
s|(Nat behavior:\s*)\b(Unknown Behavior)\b|\1<font color=\"#808080\">\2</font>|g;\
|
||||
s|(Nat behavior:\s*)\b(Direct Mapping)\b|\1<font color=\"#1e96fc\">\2</font>|g;\
|
||||
s|(Nat behavior:\s*)\b(Endpoint Independent Mapping)\b|\1<font color=\"#7cfc00\">\2</font>|g;\
|
||||
s|(Nat behavior:\s*)\b(Address Dependent Mapping)\b|\1<font color=\"#ffc100\">\2</font>|g;\
|
||||
s|(Nat behavior:\s*)\b(Address and Port Dependent Mapping)\b|\1<font color=\"#ff8200\">\2</font>|g;\
|
||||
s|(Nat behavior:\s*)\b(Unknown NAT Behavior)\b|\1<font color=\"#808080\">\2</font>|g;\
|
||||
s|(Nat filtering:\s*)\b(Unknown Filtering)\b|\1<font color=\"#808080\">\2</font>|g;\
|
||||
s|(Nat filtering:\s*)\b(Direct Mapping (Filtering))\b|\1<font color=\"#1e96fc\">\2</font>|g;\
|
||||
s|(Nat filtering:\s*)\b(Endpoint Independent Filtering)\b|\1<font color=\"#7cfc00\">\2</font>|g;\
|
||||
s|(Nat filtering:\s*)\b(Address Dependent Filtering)\b|\1<font color=\"#ffc100\">\2</font>|g;\
|
||||
s|(Nat filtering:\s*)\b(Address and Port Dependent Filtering)\b|\1<font color=\"#ff8200\">\2</font>|g;\
|
||||
s|(Nat filtering:\s*)\b(Unknown NAT Filtering)\b|\1<font color=\"#808080\">\2</font>|g;\
|
||||
s|(:\s*)(.*)$|\1<b>\2</b><br>|g"
|
||||
}
|
||||
|
||||
cat <<- EOF
|
||||
$(echo ${l4proto} | tr 'a-z' 'A-Z') TEST:<br>
|
||||
$(render "${result:-<font color=\"red\">Test timeout</font>}")
|
||||
EOF
|
||||
+227
@@ -0,0 +1,227 @@
|
||||
#!/bin/sh
|
||||
|
||||
. /usr/share/libubox/jshn.sh
|
||||
|
||||
CONF="fchomo"
|
||||
|
||||
RESOURCES_DIR="/etc/$CONF/resources"
|
||||
VER_PATH="/etc/$CONF/resources.json"
|
||||
mkdir -p "$RESOURCES_DIR"
|
||||
|
||||
RUN_DIR="/var/run/$CONF"
|
||||
LOG_PATH="$RUN_DIR/$CONF.log"
|
||||
mkdir -p "$RUN_DIR"
|
||||
|
||||
log() {
|
||||
echo -e "$(date "+%F %T") $*" >> "$LOG_PATH"
|
||||
}
|
||||
|
||||
to_upper() {
|
||||
echo -e "$1" | tr "[a-z]" "[A-Z]"
|
||||
}
|
||||
|
||||
get_local_ver() {
|
||||
local type="$1"
|
||||
local repoid="$2"
|
||||
|
||||
local ver
|
||||
if [ -n "$repoid" ]; then
|
||||
ver="$(eval "jsonfilter -qi \"$VER_PATH\" -e '@[\"$type\"][\"$repoid\"].version'")"
|
||||
else
|
||||
ver="$(eval "jsonfilter -qi \"$VER_PATH\" -e '@[\"$type\"]'")"
|
||||
fi
|
||||
|
||||
[ -n "$ver" ] && echo "$ver" || return 1
|
||||
}
|
||||
|
||||
check_dashboard_update() {
|
||||
local dashtype="$1"
|
||||
local dashrepo="$2"
|
||||
local dashrepoid="$(echo -n "$dashrepo" | sed 's|\W|_|g' | tr 'A-Z' 'a-z')"
|
||||
local lock="$RUN_DIR/update_resources-$dashtype.lock"
|
||||
local wget="wget --tries=1 --timeout=10 -q"
|
||||
|
||||
exec 200>"$lock"
|
||||
if ! flock -n 200 &> "/dev/null"; then
|
||||
log "[$(to_upper "$dashtype")] A task is already running."
|
||||
return 2
|
||||
fi
|
||||
|
||||
local dash_ver="$($wget -O- "https://api.github.com/repos/$dashrepo/releases/latest" | jsonfilter -e "@.tag_name" 2>/dev/null)"
|
||||
[ -n "$dash_ver" ] || {
|
||||
dash_ver="$($wget -O- "https://api.github.com/repos/$dashrepo/tags" | jsonfilter -e "@[*].name" | head -n1)"
|
||||
}
|
||||
if [ -z "$dash_ver" ]; then
|
||||
log "[$(to_upper "$dashtype")] [$dashrepo] Failed to get the latest version, please retry later."
|
||||
return 1
|
||||
fi
|
||||
|
||||
local local_dash_ver="$(get_local_ver "$dashtype" "$dashrepoid" || echo "NOT FOUND")"
|
||||
if [ "$local_dash_ver" = "$dash_ver" ]; then
|
||||
log "[$(to_upper "$dashtype")] [$dashrepo] Current version: $dash_ver."
|
||||
log "[$(to_upper "$dashtype")] [$dashrepo] You're already at the latest version."
|
||||
return 3
|
||||
else
|
||||
log "[$(to_upper "$dashtype")] [$dashrepo] Local version: $local_dash_ver, latest version: $dash_ver."
|
||||
fi
|
||||
|
||||
if ! $wget "https://codeload.github.com/$dashrepo/tar.gz/refs/heads/gh-pages" -O "$RUN_DIR/$dashtype.tgz" || ! tar -tzf "$RUN_DIR/$dashtype.tgz" >/dev/null; then
|
||||
rm -f "$RUN_DIR/$dashtype.tgz"
|
||||
log "[$(to_upper "$dashtype")] [$dashrepo] Update failed."
|
||||
return 1
|
||||
fi
|
||||
|
||||
mv -f "$RUN_DIR/$dashtype.tgz" "$RESOURCES_DIR/$dashrepoid.tgz"
|
||||
touch "$VER_PATH"
|
||||
json_init
|
||||
json_load_file "$VER_PATH"
|
||||
json_select "$dashtype" 2>/dev/null || json_add_object "$dashtype"
|
||||
json_select "$dashrepoid" 2>/dev/null || json_add_object "$dashrepoid"
|
||||
json_add_string repo "$dashrepo"
|
||||
json_add_string version "$dash_ver"
|
||||
json_dump > "$VER_PATH"
|
||||
log "[$(to_upper "$dashtype")] [$dashrepo] Successfully updated."
|
||||
return 0
|
||||
}
|
||||
|
||||
# Reference from homeproxy
|
||||
check_geodata_update() {
|
||||
local geotype="$1"
|
||||
local georepo="$2"
|
||||
local lock="$RUN_DIR/update_resources-$geotype.lock"
|
||||
local wget="wget --tries=1 --timeout=10 -q"
|
||||
|
||||
exec 200>"$lock"
|
||||
if ! flock -n 200 &> "/dev/null"; then
|
||||
log "[$(to_upper "$geotype")] A task is already running."
|
||||
return 2
|
||||
fi
|
||||
|
||||
local geodata_ver="$($wget -O- "https://api.github.com/repos/$georepo/releases/latest" | jsonfilter -e "@.tag_name")"
|
||||
if [ -z "$geodata_ver" ]; then
|
||||
log "[$(to_upper "$geotype")] Failed to get the latest version, please retry later."
|
||||
return 1
|
||||
fi
|
||||
|
||||
local local_geodata_ver="$(get_local_ver "$geotype" || echo "NOT FOUND")"
|
||||
if [ "$local_geodata_ver" = "$geodata_ver" ]; then
|
||||
log "[$(to_upper "$geotype")] Current version: $geodata_ver."
|
||||
log "[$(to_upper "$geotype")] You're already at the latest version."
|
||||
return 3
|
||||
else
|
||||
log "[$(to_upper "$geotype")] Local version: $local_geodata_ver, latest version: $geodata_ver."
|
||||
fi
|
||||
|
||||
local geodata_hash
|
||||
$wget "https://github.com/$georepo/releases/download/$geodata_ver/$geotype.dat" -O "$RUN_DIR/$geotype.dat"
|
||||
geodata_hash="$($wget -O- "https://github.com/$georepo/releases/download/$geodata_ver/$geotype.dat.sha256sum" | awk '{print $1}')"
|
||||
if ! echo -e "$geodata_hash $RUN_DIR/$geotype.dat" | sha256sum -s -c -; then
|
||||
rm -f "$RUN_DIR/$geotype.dat"
|
||||
log "[$(to_upper "$geotype")] Update failed."
|
||||
return 1
|
||||
fi
|
||||
|
||||
mv -f "$RUN_DIR/$geotype.dat" "$RESOURCES_DIR/../$geotype.dat"
|
||||
touch "$VER_PATH"
|
||||
json_init
|
||||
json_load_file "$VER_PATH"
|
||||
json_add_string "$geotype" "$geodata_ver"
|
||||
json_dump > "$VER_PATH"
|
||||
log "[$(to_upper "$geotype")] Successfully updated."
|
||||
return 0
|
||||
}
|
||||
|
||||
# Reference from homeproxy
|
||||
check_list_update() {
|
||||
local listtype="$1"
|
||||
local listrepo="$2"
|
||||
local listref="$3"
|
||||
local listname="$4"
|
||||
local lock="$RUN_DIR/update_resources-$listtype.lock"
|
||||
local wget="wget --tries=1 --timeout=10 -q"
|
||||
|
||||
exec 200>"$lock"
|
||||
if ! flock -n 200 &> "/dev/null"; then
|
||||
log "[$(to_upper "$listtype")] A task is already running."
|
||||
return 2
|
||||
fi
|
||||
|
||||
local list_info="$($wget -O- "https://api.github.com/repos/$listrepo/commits?sha=$listref&path=$listname")"
|
||||
local list_sha="$(echo -e "$list_info" | jsonfilter -e "@[0].sha")"
|
||||
local list_ver="$(echo -e "$list_info" | jsonfilter -e "@[0].commit.message" | grep -Eo "[0-9-]+" | tr -d '-')"
|
||||
if [ -z "$list_sha" ] || [ -z "$list_ver" ]; then
|
||||
log "[$(to_upper "$listtype")] Failed to get the latest version, please retry later."
|
||||
return 1
|
||||
fi
|
||||
|
||||
local local_list_ver="$(get_local_ver "$listtype" || echo "NOT FOUND")"
|
||||
if [ "$local_list_ver" = "$list_ver" ]; then
|
||||
log "[$(to_upper "$listtype")] Current version: $list_ver."
|
||||
log "[$(to_upper "$listtype")] You're already at the latest version."
|
||||
return 3
|
||||
else
|
||||
log "[$(to_upper "$listtype")] Local version: $local_list_ver, latest version: $list_ver."
|
||||
fi
|
||||
|
||||
if ! $wget "https://fastly.jsdelivr.net/gh/$listrepo@$list_sha/$listname" -O "$RUN_DIR/$listname" || [ ! -s "$RUN_DIR/$listname" ]; then
|
||||
rm -f "$RUN_DIR/$listname"
|
||||
log "[$(to_upper "$listtype")] Update failed."
|
||||
return 1
|
||||
fi
|
||||
|
||||
mv -f "$RUN_DIR/$listname" "$RESOURCES_DIR/$listtype.${listname##*.}"
|
||||
touch "$VER_PATH"
|
||||
json_init
|
||||
json_load_file "$VER_PATH"
|
||||
json_add_string "$listtype" "$list_ver"
|
||||
json_dump > "$VER_PATH"
|
||||
log "[$(to_upper "$listtype")] Successfully updated."
|
||||
return 0
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
"ALL")
|
||||
# Since the VER_PATH lock is not designed, parallelism is not currently supported.
|
||||
for _type in geoip geosite asn china_ip4 china_ip6 gfw_list china_list; do
|
||||
"$0" "$_type"
|
||||
done
|
||||
# dashboard
|
||||
_repos="$(jsonfilter -qi "$VER_PATH" -e '@.dashboard[*].repo')"
|
||||
if [ -n "$_repos" ]; then
|
||||
for i in $(echo "$_repos" | sed -n '='); do
|
||||
"$0" "dashboard" "$(echo "$_repos" | sed -n "${i}p")"
|
||||
done
|
||||
else
|
||||
"$0" "dashboard"
|
||||
fi
|
||||
;;
|
||||
"dashboard")
|
||||
check_dashboard_update "$1" "${2:-MetaCubeX/metacubexd}"
|
||||
;;
|
||||
"geoip")
|
||||
check_geodata_update "$1" "Loyalsoldier/v2ray-rules-dat"
|
||||
;;
|
||||
"geosite")
|
||||
check_geodata_update "$1" "Loyalsoldier/v2ray-rules-dat"
|
||||
;;
|
||||
"asn")
|
||||
check_list_update "$1" "Loyalsoldier/geoip" "release" "GeoLite2-ASN.mmdb" &&
|
||||
mv -f "$RESOURCES_DIR/asn.mmdb" "$RESOURCES_DIR/../asn.mmdb"
|
||||
;;
|
||||
"china_ip4")
|
||||
check_list_update "$1" "fcshark-org/route-list" "release" "china_ipv4.txt"
|
||||
;;
|
||||
"china_ip6")
|
||||
check_list_update "$1" "fcshark-org/route-list" "release" "china_ipv6.txt"
|
||||
;;
|
||||
"gfw_list")
|
||||
check_list_update "$1" "fcshark-org/route-list" "release" "gfwlist.txt"
|
||||
;;
|
||||
"china_list")
|
||||
check_list_update "$1" "fcshark-org/route-list" "release" "china_list2.txt"
|
||||
;;
|
||||
*)
|
||||
echo -e "Usage: $0 <ALL / dashboard / geoip / geosite / asn / china_ip4 / china_ip6 / gfw_list / china_list>"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
Reference in new issue
Block a user