Last active
December 13, 2022 08:02
-
-
Save lookis/f6f4644c2e2c8275e583ca4ba2a1cf95 to your computer and use it in GitHub Desktop.
在线使用,通过 shlink 跳过来
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
set -e | |
is_wsl() { | |
case "$(uname -r)" in | |
*microsoft* ) true ;; # WSL 2 | |
*Microsoft* ) true ;; # WSL 1 | |
* ) false;; | |
esac | |
} | |
is_darwin() { | |
case "$(uname -s)" in | |
*darwin* ) true ;; | |
*Darwin* ) true ;; | |
* ) false;; | |
esac | |
} | |
is_linux() { | |
case "$(uname)" in | |
*linux* ) true ;; | |
*Linux* ) true ;; | |
* ) false;; | |
esac | |
} | |
is_amd64() { | |
case "$(uname -m)" in | |
*x86_64* ) true ;; | |
* ) false;; | |
esac | |
} | |
is_arm64() { | |
case "$(uname -m)" in | |
*arm64* ) true ;; | |
*aarch64* ) true ;; | |
* ) false;; | |
esac | |
} | |
command_exists() { | |
command -v "$@" > /dev/null 2>&1 | |
} | |
do_install() { | |
user="$(id -un 2>/dev/null || true)" | |
sh_c='sh -c' | |
if [ "$user" != 'root' ]; then | |
if command_exists sudo; then | |
sh_c='sudo -E sh -c' | |
elif command_exists su; then | |
sh_c='su -c' | |
else | |
cat >&2 <<-'EOF' | |
Error: 安装脚本需要 root 权限,但无法在系统里找到 sudo 或者 su 命令 | |
EOF | |
exit 1 | |
fi | |
fi | |
baseurl="https://cnative-client-release.oss-cn-beijing.aliyuncs.com/cnative/latest/" | |
curl='curl -L' | |
local_name='cnative' | |
download_name='' | |
os='' | |
install_path='/usr/local/bin' | |
arch='amd64' | |
install_cmd="install -m 0755" | |
if is_arm64; then | |
arch='arm64' | |
fi | |
if is_linux; then | |
os='linux' | |
fi | |
if is_darwin; then | |
os='darwin' | |
fi | |
download_name="cnative-$os-$arch" | |
if is_wsl; then | |
curl='curl.exe -LO' | |
local_name='cnative.exe' | |
install_path='C:\Windows' | |
os='windows' | |
download_name="cnative-windows-amd64.exe" | |
fi | |
$sh_c "$curl -o $local_name $baseurl$download_name" | |
if is_wsl; then | |
mv "$local_name" "$install_path" | |
else | |
$sh_c "$install_cmd $local_name /usr/local/bin/cnative" | |
fi | |
} | |
do_install |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment