Skip to content

Commit 78423e2

Browse files
authored
Merge pull request #15 from NUAA-Open-Source/dev
refact the install script & fixes
2 parents 6f632d0 + 7c6c752 commit 78423e2

File tree

3 files changed

+112
-15
lines changed

3 files changed

+112
-15
lines changed

.github/workflows/install.yml

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,36 @@ jobs:
1414
# alias wget="wget --no-check-certificate"
1515
# sh -c "$(echo "alias wget=\"wget --no-check-certificate\""; yes | wget -qO- https://raw.githubusercontent.com/NUAA-Open-Source/safeu-cli/master/install.sh)"
1616

17+
- name: print install script help message
18+
run: |
19+
sh ./install.sh --help
20+
# should not have safeu command
21+
if [ -x "$(command -v safeu)" ]; then echo "should not have the safeu command"; exit 1; else exit 0; fi
22+
23+
- name: print install script version for safeu-cli
24+
run: |
25+
sh ./install.sh --version
26+
# should not have safeu command
27+
if [ -x "$(command -v safeu)" ]; then echo "should not have the safeu command"; exit 1; else exit 0; fi
28+
1729
- name: run install script
18-
run: sh ./install.sh <<< Y
30+
run: sh ./install.sh
1931

2032
- name: test safeu cli
2133
run: safeu version
34+
35+
- name: remove the safeu cli
36+
run: |
37+
sudo rm -rf /usr/local/bin/safeu
38+
# should not have safeu command
39+
if [ -x "$(command -v safeu)" ]; then echo "should not have the safeu command"; exit 1; else exit 0; fi
40+
41+
- name: run install script with local option
42+
run: |
43+
export PATH=$HOME/.local/bin:$PATH
44+
sh ./install.sh --local
45+
46+
- name: test safeu cli
47+
run: |
48+
export PATH=$HOME/.local/bin:$PATH
49+
safeu version

README.md

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
<!-- omit in toc -->
22
# SafeU CLI
33

4-
![Install](https://github.com/NUAA-Open-Source/safeu-cli/workflows/Install/badge.svg) | ![Go](https://github.com/NUAA-Open-Source/safeu-cli/workflows/Go/badge.svg)
4+
![Install](https://github.com/NUAA-Open-Source/safeu-cli/workflows/Install/badge.svg)
5+
![Go](https://github.com/NUAA-Open-Source/safeu-cli/workflows/Go/badge.svg)
56

67
A command line tool for SafeU (https://safeu.a2os.club).
78

89
- [Install](#install)
10+
- [Install safeu-cli just for current user](#install-safeu-cli-just-for-current-user)
911
- [China mainland optimized](#china-mainland-optimized)
1012
- [Usage](#usage)
1113
- [Upload](#upload)
@@ -22,7 +24,7 @@ A command line tool for SafeU (https://safeu.a2os.club).
2224

2325
## Install
2426

25-
> If you are in China mainland, the install method in [China mainland optimized](#china-mainland-optimized) is a better choice.
27+
> If you are in China mainland, the install methods in [China mainland optimized](#china-mainland-optimized) is a better choice.
2628
2729
> NOTICE: The following methods would download a pre-compiled safeu-cli binary file which is ONLY for 64-bit Linux. If you are using a different architecture or OS, just check the [Compile](#compile) section below to build your own binary package.
2830
@@ -42,20 +44,36 @@ $ sh -c "$(wget -qO- https://raw.githubusercontent.com/NUAA-Open-Source/safeu-cl
4244

4345
Congratulations, you have successfully installed the `safeu-cli` tool :tada:
4446

47+
### Install safeu-cli just for current user
48+
49+
via curl:
50+
51+
```bash
52+
$ sh -c "$(curl -fsSL https://raw.githubusercontent.com/NUAA-Open-Source/safeu-cli/master/install.sh) --local"
53+
```
54+
55+
via wget:
56+
57+
```bash
58+
$ sh -c "$(wget -qO- https://raw.githubusercontent.com/NUAA-Open-Source/safeu-cli/master/install.sh) --local"
59+
```
60+
4561
### China mainland optimized
4662

4763
via curl:
4864

4965
```bash
50-
$ sh -c "$(curl -fsSL https://gitee.com/A2OS/safeu-cli/raw/master/install.sh) cn"
66+
$ sh -c "$(curl -fsSL https://gitee.com/A2OS/safeu-cli/raw/master/install.sh) --cn"
5167
```
5268

5369
via wget:
5470

5571
```bash
56-
$ sh -c "$(wget -qO- https://gitee.com/A2OS/safeu-cli/raw/master/install.sh) cn"
72+
$ sh -c "$(wget -qO- https://gitee.com/A2OS/safeu-cli/raw/master/install.sh) --cn"
5773
```
5874

75+
> If you want to install `safeu-cli` locally by using the china mainland optimized script, just add `--local` option after the `--cn`.
76+
5977
## Usage
6078

6179
### Upload
@@ -75,7 +93,7 @@ $ safeu upload filename1 filename2 filename3
7593

7694
Ref to [Full deteail of upload command](#full-detail-of-upload-command).
7795

78-
Examples for this section will be supplement lately.
96+
Examples for this section will be supplemented lately.
7997

8098
#### Full detail of upload command
8199

install.sh

Lines changed: 60 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,31 @@ BIN_DIR=/usr/local/bin
1515
BIN_FILENAME=safeu.tmp
1616
SAFEU_CMD=safeu
1717
IS_LOCAL=0
18+
IS_CN=0
19+
VERSION=v1.0.0-alpha
1820

1921

22+
show_help() {
23+
cat <<- EOF
24+
SafeU CLI tool install script.
25+
26+
Usage: ./install.sh [options]
27+
28+
Options:
29+
--local Install safeu-cli locally (in ~/.local/bin).
30+
--cn Use china mainland optimized install script.
31+
--version Show the safeu-cli release version.
32+
--help Show this help message.
33+
34+
You can access SafeU by via website: https://safeu.a2os.club/
35+
Any question please open issue on: https://github.com/NUAA-Open-Source/safeu-cli/issues/new
36+
EOF
37+
}
38+
39+
show_version() {
40+
echo "$VERSION"
41+
}
42+
2043
error() {
2144
echo ${RED}"Error: $@"${RESET} >&2
2245
}
@@ -41,7 +64,7 @@ setup_color() {
4164
}
4265

4366
download_safeu_cli() {
44-
if [ "$1" = "cn" ]; then
67+
if [ $IS_CN -eq 1 ]; then
4568
wget -cO ${BIN_FILENAME} ${SAFEU_CN_RELEASE} || {
4669
error "cannot download safeu-cli by ${SAFEU_CN_RELEASE}"
4770
exit 1
@@ -56,19 +79,15 @@ download_safeu_cli() {
5679
}
5780

5881
install_scope() {
59-
if [ "$(id -u)" -eq "0" ]; then
82+
if [ "$(id -u)" = "0" ]; then
6083
# the user has privileges, do not need to use sudo
6184
IS_LOCAL=1
6285
BIN_DIR=/usr/local/bin
6386
return
6487
fi
6588

66-
printf "${YELLOW}Install safeu command tool globally (require sudo permission later) ? [Y/N, Default: Y]: "
67-
read isGlobal
68-
69-
if [ "$isGlobal" = "n" ] || [ "$isGlobal" = "N" ] ; then
89+
if [ $IS_LOCAL -eq 1 ] ; then
7090
BIN_DIR=${HOME}/.local/bin
71-
IS_LOCAL=1
7291
else
7392
BIN_DIR=/usr/local/bin
7493
fi
@@ -108,12 +127,44 @@ EOF
108127
printf "$RESET"
109128
}
110129

130+
get_args() {
131+
for arg in "$@"; do
132+
case $arg in
133+
--cn)
134+
IS_CN=1
135+
;;
136+
--local)
137+
IS_LOCAL=1
138+
;;
139+
--version)
140+
show_version
141+
exit 0
142+
;;
143+
--help)
144+
show_help
145+
exit 0
146+
;;
147+
*)
148+
printf "${RED}Invalid option: '%s', check the help message below!${RESET}\n\n" $arg
149+
show_help
150+
exit 1
151+
;;
152+
esac
153+
done
154+
}
155+
111156
main() {
157+
# preparations
112158
setup_color
113-
download_safeu_cli $1
159+
get_args $@
114160
install_scope
161+
162+
# download & install safeu-cli
163+
download_safeu_cli
115164
install_safeu_cli
165+
166+
# print success message
116167
post_install
117168
}
118169

119-
main "$@"
170+
main $@

0 commit comments

Comments
 (0)