-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinstall.sh
executable file
·171 lines (147 loc) · 4.16 KB
/
install.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#!/bin/bash
#
# This script should be run via curl:
# sh -c "$(curl -fsSL https://raw.githubusercontent.com/NUAA-Open-Source/safeu-cli/master/install.sh)"
# or wget:
# sh -c "$(wget -qO- https://raw.githubusercontent.com/NUAA-Open-Source/safeu-cli/master/install.sh)"
#
# As an alternative, you can first download the install script and run it afterwards:
# wget https://raw.githubusercontent.com/NUAA-Open-Source/safeu-cli/master/install.sh
# sh install.sh
SAFEU_RELEASE="https://github.com/NUAA-Open-Source/safeu-cli/releases/download/v1.0.0-beta/safeu-linux-x64"
SAFEU_CN_RELEASE="https://triplez-public-1251926021.cos.ap-shanghai.myqcloud.com/safeu-cli/v1.0.0-beta/safeu-linux-x64"
VERSION=v1.0.0-beta
BIN_DIR=/usr/local/bin
BIN_FILENAME=safeu.tmp
SAFEU_CMD=safeu
IS_LOCAL=0
IS_CN=0
show_help() {
cat <<- EOF
SafeU CLI tool install script.
Usage: ./install.sh [options]
Options:
--local Install safeu-cli locally (in ~/.local/bin).
--cn Use china mainland optimized install script.
--version Show the safeu-cli release version.
--help Show this help message.
You can access SafeU by via website: https://safeu.a2os.club/
Any question please open issue on: https://github.com/NUAA-Open-Source/safeu-cli/issues/new
EOF
}
show_version() {
echo "$VERSION"
}
error() {
echo ${RED}"Error: $@"${RESET} >&2
}
setup_color() {
# Only use colors if connected to a terminal
if [ -t 1 ]; then
RED=$(printf '\033[31m')
GREEN=$(printf '\033[32m')
YELLOW=$(printf '\033[33m')
BLUE=$(printf '\033[34m')
BOLD=$(printf '\033[1m')
RESET=$(printf '\033[m')
else
RED=""
GREEN=""
YELLOW=""
BLUE=""
BOLD=""
RESET=""
fi
}
download_safeu_cli() {
if [ $IS_CN -eq 1 ]; then
wget -cO ${BIN_FILENAME} ${SAFEU_CN_RELEASE} || {
error "cannot download safeu-cli by ${SAFEU_CN_RELEASE}"
exit 1
}
else
wget -cO ${BIN_FILENAME} ${SAFEU_RELEASE} || {
error "cannot download safeu-cli by ${SAFEU_RELEASE}"
exit 1
}
fi
}
install_scope() {
if [ "$(id -u)" = "0" ]; then
# the user has privileges, do not need to use sudo
IS_LOCAL=1
BIN_DIR=/usr/local/bin
return
fi
if [ $IS_LOCAL -eq 1 ] ; then
BIN_DIR=${HOME}/.local/bin
else
BIN_DIR=/usr/local/bin
fi
}
install_safeu_cli() {
if [ ${IS_LOCAL} -eq 1 ]; then
install -Dm755 "${BIN_FILENAME}" "${BIN_DIR}/${SAFEU_CMD}" || {
error "install the safeu-cli tool failed"
exit 1
}
else
sudo install -Dm755 "${BIN_FILENAME}" "${BIN_DIR}/${SAFEU_CMD}" || {
error "install the safeu-cli tool failed"
exit 1
}
fi
}
post_install() {
rm -f ${BIN_FILENAME}
printf "$GREEN"
cat <<-'EOF'
____ __ _ _ ____ _ ___
/ ___| __ _ / _| ___| | | | / ___| | |_ _|
\___ \ / _` | |_ / _ \ | | | | | | | | |
___) | (_| | _| __/ |_| | | |___| |___ | |
|____/ \__,_|_| \___|\___/ \____|_____|___| ....is now installed!
Now you can upload and download files via "safeu" command !
If you have further questions, you can find support in here:
https://github.com/NUAA-Open-Source/safeu-cli/issues
EOF
printf " Current installed safeu-cli version: $(safeu version)\n"
printf "$RESET"
}
get_args() {
for arg in "$@"; do
case $arg in
--cn)
IS_CN=1
;;
--local)
IS_LOCAL=1
;;
--version)
show_version
exit 0
;;
--help)
show_help
exit 0
;;
*)
printf "${RED}Invalid option: '%s', check the help message below!${RESET}\n\n" $arg
show_help
exit 1
;;
esac
done
}
main() {
# preparations
setup_color
get_args $@
install_scope
# download & install safeu-cli
download_safeu_cli
install_safeu_cli
# print success message
post_install
}
main $@