Skip to content

Instantly share code, notes, and snippets.

@mochaaP
Created April 14, 2022 09:23
Show Gist options
  • Save mochaaP/2dcd5d2cf5067546a6bcf9e01e436a26 to your computer and use it in GitHub Desktop.
Save mochaaP/2dcd5d2cf5067546a6bcf9e01e436a26 to your computer and use it in GitHub Desktop.
#!/bin/sh
BASEDIR="${BASEDIR:-/srv/clash}"
mkdir -p $BASEDIR
cd $BASEDIR || exit 1
getarch() {
machine=$(uname -ms | tr ' ' '_' | tr '[A-Z]' '[a-z]')
[ -n "$(echo $machine | grep -E "linux.*armv.*")" ] && arch="armv5"
[ -n "$(echo $machine | grep -E "linux.*armv7.*")" ] && [ -n "$(cat /proc/cpuinfo | grep vfp)" ] && [ ! -d /jffs/clash ] && arch="armv7"
[ -n "$(echo $machine | grep -E "linux.*aarch64.*|linux.*armv8.*")" ] && arch="armv8"
[ -n "$(echo $machine | grep -E "linux.*86.*")" ] && arch="386"
[ -n "$(echo $machine | grep -E "linux.*86_64.*")" ] && arch="amd64"
if [ -n "$(echo $machine | grep -E "linux.*mips.*")" ];then
mips=$(echo -n I | hexdump -o 2>/dev/null | awk '{ print substr($2,6,1); exit}')
[ "$mips" = "0" ] && arch="mips-softfloat" || arch="mipsle-softfloat"
fi
echo $arch
}
update_binary() {
echo "[clash] fetching core"
curl -L --progress-bar "https://release.dreamacro.workers.dev/latest/clash-${OS}-$(getarch)-latest.gz" | gzip -d > /usr/bin/clash
chmod +x /usr/bin/clash
}
update_geoip() {
echo "[clash] fetching geoip"
curl -L --progress-bar "https://geoip.mcha.cloud/Country.mmdb" -o Country.mmdb
}
update_dashboard() {
echo "[clash] fetching external-ui"
curl -L --progress-bar "https://gh.chapro.xyz/github.com/haishanh/yacd/archive/refs/heads/gh-pages.tar.gz" | tar xzvf -
rm -rf ui
mv yacd-gh-pages ui
}
# case
case $1 in
"binary")
update_binary
;;
"geoip")
update_geoip
;;
"dashboard")
update_dashboard
;;
"all")
update_binary
update_geoip
update_dashboard
;;
*)
echo "Usage: $0 [all|binary|geoip|dashboard]"
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment