forked from P3TERX/warp.sh
-
Notifications
You must be signed in to change notification settings - Fork 10
/
wgcf.sh
102 lines (92 loc) · 2.43 KB
/
wgcf.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/usr/bin/env bash
#
# Copyright (c) 2020-2021 P3TERX <https://p3terx.com>
#
# This is free software, licensed under the MIT License.
# See /LICENSE for more information.
#
# https://github.com/P3TERX/script
# File name: wgcf.sh
# Description: Install latest version wgcf
# System Required: GNU/Linux
# Version: 1.2
#
set -o errexit
set -o errtrace
set -o pipefail
Green_font_prefix="\033[32m"
Red_font_prefix="\033[31m"
Green_background_prefix="\033[42;37m"
Red_background_prefix="\033[41;37m"
Font_color_suffix="\033[0m"
INFO="[${Green_font_prefix}INFO${Font_color_suffix}]"
ERROR="[${Red_font_prefix}ERROR${Font_color_suffix}]"
PROJECT_NAME='wgcf'
GH_API_URL='https://api.github.com/repos/ViRb3/wgcf/releases/latest'
BIN_DIR='/usr/local/bin'
BIN_NAME='wgcf'
BIN_FILE="${BIN_DIR}/${BIN_NAME}"
ghproxy='https://ghproxy.crazypeace.workers.dev/'
if [ $# -ge 1 ]; then
case ${1} in
ghproxy)
ghproxy=${2}
;;
*)
"Invalid Parameters: $*"
exit 1
;;
esac
fi
if [[ $(uname -s) != Linux ]]; then
echo -e "${ERROR} This operating system is not supported."
exit 1
fi
if [[ $(id -u) != 0 ]]; then
echo -e "${ERROR} This script must be run as root."
exit 1
fi
echo -e "${INFO} Get CPU architecture ..."
if [[ $(command -v apk) ]]; then
PKGT='(apk)'
OS_ARCH=$(apk --print-arch)
elif [[ $(command -v dpkg) ]]; then
PKGT='(dpkg)'
OS_ARCH=$(dpkg --print-architecture | awk -F- '{ print $NF }')
else
OS_ARCH=$(uname -m)
fi
case ${OS_ARCH} in
*86)
FILE_KEYWORD='linux_386'
;;
x86_64 | amd64)
FILE_KEYWORD='linux_amd64'
;;
aarch64 | arm64)
FILE_KEYWORD='linux_arm64'
;;
arm*)
FILE_KEYWORD='linux_armv7'
;;
*)
echo -e "${ERROR} Unsupported architecture: ${OS_ARCH} ${PKGT}"
exit 1
;;
esac
echo -e "${INFO} Architecture: ${OS_ARCH} ${PKGT}"
echo -e "${INFO} Get ${PROJECT_NAME} download URL ..."
DOWNLOAD_URL=$(curl -fsSL ${ghproxy}${GH_API_URL} | grep 'browser_download_url' | cut -d'"' -f4 | grep "${FILE_KEYWORD}")
echo -e "${INFO} Download URL: ${DOWNLOAD_URL}"
echo -e "${INFO} Installing ${PROJECT_NAME} ..."
curl -LS ${ghproxy}"${DOWNLOAD_URL}" -o ${BIN_FILE}
chmod +x ${BIN_FILE}
if [[ ! $(echo ${PATH} | grep ${BIN_DIR}) ]]; then
ln -sf ${BIN_FILE} /usr/bin/${BIN_NAME}
fi
if [[ -s ${BIN_FILE} && $(${BIN_NAME} -h) ]]; then
echo -e "${INFO} Done."
else
echo -e "${ERROR} ${PROJECT_NAME} installation failed !"
exit 1
fi