This commit is contained in:
wnlen
2023-11-25 17:24:01 +08:00
commit 2da776f6e4
461 changed files with 100429 additions and 0 deletions

View File

@ -0,0 +1,38 @@
#!/bin/bash
# 加载clash配置文件内容
raw_content=$(cat ${Server_Dir}/temp/clash.yaml)
# 判断订阅内容是否符合clash配置文件标准
#if echo "$raw_content" | jq 'has("proxies") and has("proxy-groups") and has("rules")' 2>/dev/null; then
if echo "$raw_content" | awk '/^proxies:/{p=1} /^proxy-groups:/{g=1} /^rules:/{r=1} p&&g&&r{exit} END{if(p&&g&&r) exit 0; else exit 1}'; then
echo "订阅内容符合clash标准"
echo "$raw_content" > ${Server_Dir}/temp/clash_config.yaml
else
# 判断订阅内容是否为base64编码
if echo "$raw_content" | base64 -d &>/dev/null; then
# 订阅内容为base64编码进行解码
decoded_content=$(echo "$raw_content" | base64 -d)
# 判断解码后的内容是否符合clash配置文件标准
#if echo "$decoded_content" | jq 'has("proxies") and has("proxy-groups") and has("rules")' 2>/dev/null; then
if echo "$decoded_content" | awk '/^proxies:/{p=1} /^proxy-groups:/{g=1} /^rules:/{r=1} p&&g&&r{exit} END{if(p&&g&&r) exit 0; else exit 1}'; then
echo "解码后的内容符合clash标准"
echo "$decoded_content" > ${Server_Dir}/temp/clash_config.yaml
else
echo "解码后的内容不符合clash标准尝试将其转换为标准格式"
${Server_Dir}/tools/subconverter/subconverter -g &>> ${Server_Dir}/logs/subconverter.log
converted_file=${Server_Dir}/temp/clash_config.yaml
# 判断转换后的内容是否符合clash配置文件标准
if awk '/^proxies:/{p=1} /^proxy-groups:/{g=1} /^rules:/{r=1} p&&g&&r{exit} END{if(p&&g&&r) exit 0; else exit 1}' $converted_file; then
echo "配置文件已成功转换成clash标准格式"
else
echo "配置文件转换标准格式失败"
exit 1
fi
fi
else
echo "订阅内容不符合clash标准无法转换为配置文件"
exit 1
fi
fi

50
scripts/get_cpu_arch.sh Normal file
View File

@ -0,0 +1,50 @@
#!/bin/bash
# 该脚本的作用是获取Linux操作系统上运行的CPU架构信息并将其输出到标准输出流。
function exitWithError {
local errorMessage="$1"
echo -e "\033[31m[ERROR] $errorMessage\033[0m" >&2
exit 1
}
# Function to get CPU architecture
function get_cpu_arch {
local commands=("$@")
for cmd in "${commands[@]}"; do
local CpuArch
CpuArch=$(command -v $cmd >/dev/null && $cmd 2>/dev/null || type -p $cmd 2>/dev/null)
if [[ -n "$CpuArch" ]]; then
echo "$CpuArch"
return
fi
done
}
# Check if we are running on a supported Linux distribution
if [[ -f "/etc/os-release" ]]; then
. /etc/os-release
case "$ID" in
"ubuntu"|"debian"|"linuxmint")
# Debian-based distributions
CpuArch=$(get_cpu_arch "dpkg-architecture -qDEB_HOST_ARCH_CPU" "dpkg-architecture -qDEB_BUILD_ARCH_CPU" "uname -m")
;;
"centos"|"fedora"|"rhel")
# Red Hat-based distributions
CpuArch=$(get_cpu_arch "uname -m" "arch" "uname")
;;
*)
# Unsupported Linux distribution
CpuArch=$(get_cpu_arch "uname -m" "arch" "uname")
if [[ -z "$CpuArch" ]]; then
exitWithError "Failed to obtain CPU architecture"
fi
;;
esac
elif [[ -f "/etc/redhat-release" ]]; then
# Older Red Hat-based distributions
CpuArch=$(get_cpu_arch "uname -m" "arch" "uname")
else
exitWithError "Unsupported Linux distribution"
fi
echo "CPU architecture: $CpuArch"