Skip to content

Commit

Permalink
Update tailscale_downloader
Browse files Browse the repository at this point in the history
  • Loading branch information
CH3NGYZ authored Jul 23, 2024
1 parent 9e6810d commit d500287
Showing 1 changed file with 61 additions and 63 deletions.
124 changes: 61 additions & 63 deletions usr/bin/tailscale_downloader
Original file line number Diff line number Diff line change
@@ -1,80 +1,84 @@
#!/bin/sh
set -e

echo "search lan" > /etc/resolv.conf
echo "nameserver 223.5.5.5" >> /etc/resolv.conf
echo "nameserver 119.29.29.29" >> /etc/resolv.conf

# 配置DNS
cat <<EOF > /etc/resolv.conf
search lan
nameserver 100.100.100.100
nameserver 223.5.5.5
nameserver 119.29.29.29
EOF

# 检查并设置架构
if [ ! -f /tmp/tailscale ]; then
arch=$(uname -m)
if [ "$arch" = "i386" ]; then
arch=386
elif [ "$arch" = "x86_64" ]; then
arch=amd64
elif [ "$arch" = "armv7l" ]; then
arch=arm
elif [ "$arch" = "aarch64" ]; then
arch=arm64
elif [ "$arch" = "armv8l" ]; then
arch=arm64
elif [ "$arch" = "geode" ]; then
arch=geode
elif [ "$arch" = "mips" ]; then
endianness=$(echo -n I | hexdump -o | awk '{ print (substr($2,6,1)=="1") ? "le" : "" }')
elif [ "$arch" = "riscv64" ]; then
arch=riscv64
else
echo "DOWNLOAD: ----------------------------------------------------"
echo "当前机器的架构是${arch}${endianness}, 脚本不兼容此架构"
echo "请给作者提issue以便作者及时修改脚本:"
echo "https://github.com/CH3NGYZ/tailscale-openwrt/issues"
echo "--------------------------------------------------------------"
exit 1
fi
case "$arch" in
i386)
arch=386
;;
x86_64)
arch=amd64
;;
armv7l)
arch=arm
;;
aarch64 | armv8l)
arch=arm64
;;
geode)
arch=geode
;;
mips)
endianness=$(echo -n I | hexdump -o | awk '{ print (substr($2,6,1)=="1") ? "le" : "be"; exit }')
arch="mips$endianness"
;;
riscv64)
arch=riscv64
;;
*)
echo "DOWNLOAD: ----------------------------------------------------"
echo "当前机器的架构是${arch}${endianness}, 脚本不兼容此架构"
echo "请给作者提issue以便作者及时修改脚本:"
echo "https://github.com/CH3NGYZ/tailscale-openwrt/issues"
echo "--------------------------------------------------------------"
exit 1
;;
esac

latest_version="not_available"
version_timeout=20
version_url="https://github.com/CH3NGYZ/tailscale-openwrt/releases/latest"
version_proxys="https://ghproxy.cc
https://git.xfj0.cn
https://cors.isteed.cc
https://940740.xyz
https://hub.gitmirror.com
https://gh.con.sh
https://mirror.ghproxy.com
https://slink.ltd
https://dl.ghpig.top
https://gh.ddlc.top
https://gh.h233.eu.org"
https://git.xfj0.cn
https://cors.isteed.cc
https://940740.xyz
https://hub.gitmirror.com
https://gh.con.sh
https://mirror.ghproxy.com
https://slink.ltd
https://dl.ghpig.top
https://gh.ddlc.top
https://gh.h233.eu.org"

range="1
2
3"
range="1 2 3"

# 尝试获取最新版本号
for attempt in $range; do
# echo "DOWNLOAD: --------"
# echo "获取版本号,总第 $attempt 次"
# echo "------------------"
for version_proxy in $version_proxys; do
version_proxy_url="$version_proxy/$version_url"
get_version=$(timeout $version_timeout wget -c -qO- "$version_proxy_url" | grep 已从上游同步 | head -1 | cut -d'%' -f 2)
# echo "获取版本号, 网址: $version_proxy_url 结果: $get_version"
if [ "$get_version" != "" ]; then
echo "DOWNLOAD: -----------------------------------"
if [ -n "$get_version" ]; then
echo "DOWNLOAD: -----------------------------------"
echo "通过代理 $version_proxy 获取版本号:$get_version"
echo "---------------------------------------------"
echo "---------------------------------------------"
latest_version=$get_version
break # 如果成功获取到版本号,跳出循环
break 2 # 成功获取到版本号,跳出两个循环
else
echo "DOWNLOAD: ----------------------------------------------------"
echo "通过代理 $version_proxy 获取版本号为空,尝试下一个代理..."
echo "--------------------------------------------------------------"
fi
done
if [ "$get_version" != "" ]; then
break
fi
done

# 如果最终还是无法获取到最新版本号,使用默认版本号
Expand All @@ -85,37 +89,31 @@ if [ ! -f /tmp/tailscale ]; then
echo "------------------------------------------"
fi

version="${latest_version}_${arch}${endianness}"
# echo "正在下载 tailscale_${version}.tgz ..."

version="${latest_version}_${arch}"
zip_url="https://github.com/CH3NGYZ/tailscale-openwrt/releases/download/${latest_version}/tailscale_${version}.tgz"

echo -e "tailscale_${version}/tailscale" > /tmp/tailscale_${version}_files.txt
echo -e "tailscale_${version}/tailscaled" >> /tmp/tailscale_${version}_files.txt

download_success=false
timeout_seconds=30

# 尝试下载并解压
for attempt in $range; do
# echo "DOWNLOAD: ------------"
# echo "下载zip并解压,总第 $attempt 次"
# echo "----------------------"
for zip_proxy in $version_proxys; do
zip_proxy_url="$zip_proxy/$zip_url"
# 使用 timeout 命令设定超时时间
if timeout $timeout_seconds wget -c -qO- $zip_proxy_url | tar xzvf - -C /tmp -T /tmp/tailscale_${version}_files.txt > /dev/null 2>&1 ; then
download_success=true
echo "DOWNLOAD: ---------------------------------"
echo "通过代理 $zip_proxy 下载并解压成功!"
echo "-------------------------------------------"
break
break 2 # 成功下载并解压,跳出两个循环
else
echo "DOWNLOAD: --------------------------------------"
echo "通过代理 $zip_proxy 下载失败,尝试下一个代理..."
echo "------------------------------------------------"
fi
done
if [ "$download_success" = true ]; then
break
fi
done

if [ "$download_success" != true ]; then
Expand Down

0 comments on commit d500287

Please sign in to comment.