Skip to content

Commit bab9b05

Browse files
authored
Merge pull request #2 from NUAA-Open-Source/dev
feat: add install script
2 parents 0cd93d5 + 25c527b commit bab9b05

File tree

10 files changed

+160
-20
lines changed

10 files changed

+160
-20
lines changed

README.md

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
<!-- omit in toc -->
2-
# Nuwa
3-
Command line for Safeu (https://safeu.a2os.club)
2+
# SafeU CLI
3+
4+
A command line tool for SafeU (https://safeu.a2os.club).
45

56
- [Install](#install)
7+
- [China mainland optimized](#china-mainland-optimized)
68
- [Usage](#usage)
79
- [Upload](#upload)
810
- [Upload one file](#upload-one-file)
@@ -13,17 +15,42 @@ Command line for Safeu (https://safeu.a2os.club)
1315
- [Full detail of get command](#full-detail-of-get-command)
1416
- [Demo](#demo)
1517
- [Compile](#compile)
18+
- [Known issues](#known-issues)
1619
- [License](#license)
1720

1821
## Install
1922

23+
> If you are in China mainland, the install method in [China mainland optimized](#china-mainland-optimized) is a better choice.
24+
25+
`safeu-cli` is installed by running one of the following commands in your terminal. You can install this via the command-line with either `curl` or `wget`.
26+
27+
via curl:
28+
29+
```bash
30+
$ sh -c "$(curl -fsSL https://raw.githubusercontent.com/NUAA-Open-Source/safeu-cli/master/install.sh)"
31+
```
32+
33+
via wget:
34+
35+
```bash
36+
$ sh -c "$(wget -qO- https://raw.githubusercontent.com/NUAA-Open-Source/safeu-cli/master/install.sh)"
37+
```
38+
39+
Congratulations, you have successfully installed the `safeu-cli` tool :tada:
40+
41+
### China mainland optimized
42+
43+
via curl:
44+
2045
```bash
21-
$ wget -cO safeu https://github.com/arcosx/Nuwa/releases/download/v0.1-beta/safeu
22-
$ chmod a+x safeu
23-
$ sudo cp safeu /usr/local/bin/safeu
46+
$ sh -c "$(curl -fsSL https://gitee.com/A2OS/safeu-cli/raw/master/install.sh) cn"
2447
```
2548

26-
Congratulations, you successfully install the `safeu-cli` tool.
49+
via wget:
50+
51+
```bash
52+
$ sh -c "$(wget -qO- https://gitee.com/A2OS/safeu-cli/raw/master/install.sh) cn"
53+
```
2754

2855
## Usage
2956

@@ -103,6 +130,8 @@ make build
103130
make linux-build
104131
```
105132

133+
## Known issues
134+
106135
## License
107136

108-
This project is open-sourced by [Apache 2.0](./LICENSE).
137+
This project is open-sourced by [Apache 2.0](./LICENSE).

cmd/get.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package cmd
22

33
import (
4-
"github.com/arcosx/Nuwa/get"
4+
"github.com/NUAA-Open-Source/safeu-cli/get"
55
"github.com/spf13/cobra"
66
)
77

cmd/root.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@ package cmd
33
import (
44
"fmt"
55

6-
"github.com/arcosx/Nuwa/util"
6+
"github.com/NUAA-Open-Source/safeu-cli/util"
77
"github.com/spf13/cobra"
88
)
99

1010
var (
1111
rootCmd = &cobra.Command{
1212
Use: "safeu",
13-
Short: "Nuwa is Command Line For SafeU",
14-
Long: `Nuwa is Command Line Tool for SafeU.
13+
Short: "SafeU CLI is the command line for SafeU",
14+
Long: `SafeU CLI is the command line tool for SafeU.
1515
1616
You can access SafeU by via website: https://safeu.a2os.club/
17-
Any question please open issue on https://github.com/arcosx/Nuwa/issues/new`,
17+
Any question please open issue on https://github.com/NUAA-Open-Source/safeu-cli/issues/new`,
1818
}
1919
)
2020

@@ -33,7 +33,7 @@ func init() {
3333
// 打印版本
3434
var versionCmd = &cobra.Command{
3535
Use: "version",
36-
Short: "The version number of Nuwa",
36+
Short: "The version number of SafeU CLI tool",
3737
Run: func(cmd *cobra.Command, args []string) {
3838
fmt.Println(util.VERSION)
3939
},

cmd/upload.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ package cmd
33
import (
44
"fmt"
55

6-
"github.com/arcosx/Nuwa/upload"
7-
"github.com/arcosx/Nuwa/util"
6+
"github.com/NUAA-Open-Source/safeu-cli/upload"
7+
"github.com/NUAA-Open-Source/safeu-cli/util"
88

99
"github.com/spf13/cobra"
1010
)

get/download.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"os"
1212
"strings"
1313

14-
"github.com/arcosx/Nuwa/util"
14+
"github.com/NUAA-Open-Source/safeu-cli/util"
1515
)
1616

1717
func (dm *DownloadModel) getCsrf() error {

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module github.com/arcosx/Nuwa
1+
module github.com/NUAA-Open-Source/safeu-cli
22

33
go 1.14
44

install.sh

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
#!/bin/bash
2+
#
3+
# This script should be run via curl:
4+
# sh -c "$(curl -fsSL https://raw.githubusercontent.com/NUAA-Open-Source/safeu-cli/master/install.sh)"
5+
# or wget:
6+
# sh -c "$(wget -qO- https://raw.githubusercontent.com/NUAA-Open-Source/safeu-cli/master/install.sh)"
7+
#
8+
# As an alternative, you can first download the install script and run it afterwards:
9+
# wget https://raw.githubusercontent.com/NUAA-Open-Source/safeu-cli/master/install.sh
10+
# sh install.sh
11+
12+
SAFEU_RELEASE="https://github.com/NUAA-Open-Source/safeu-cli/releases/download/v1.0.0-alpha/safeu-linux-x64"
13+
SAFEU_CN_RELEASE=""
14+
BIN_DIR=/usr/local/bin
15+
BIN_FILENAME=safeu
16+
SAFEU_CMD=safeu
17+
IS_LOCAL=0
18+
19+
20+
error() {
21+
echo ${RED}"Error: $@"${RESET} >&2
22+
}
23+
24+
setup_color() {
25+
# Only use colors if connected to a terminal
26+
if [ -t 1 ]; then
27+
RED=$(printf '\033[31m')
28+
GREEN=$(printf '\033[32m')
29+
YELLOW=$(printf '\033[33m')
30+
BLUE=$(printf '\033[34m')
31+
BOLD=$(printf '\033[1m')
32+
RESET=$(printf '\033[m')
33+
else
34+
RED=""
35+
GREEN=""
36+
YELLOW=""
37+
BLUE=""
38+
BOLD=""
39+
RESET=""
40+
fi
41+
}
42+
43+
download_safeu_cli() {
44+
if [ "$1" == "cn" ]; then
45+
wget -cO ${BIN_FILENAME} ${SAFEU_CN_RELEASE} || {
46+
error "cannot download safeu-cli by ${SAFEU_CN_RELEASE}"
47+
exit 1
48+
}
49+
else
50+
wget -cO ${BIN_FILENAME} ${SAFEU_RELEASE} || {
51+
error "cannot download safeu-cli by ${SAFEU_RELEASE}"
52+
exit 1
53+
}
54+
fi
55+
56+
}
57+
58+
install_scope() {
59+
echo -e "${YELLOW}Install safeu command tool globally (require sudo permission later) ? (y/n, defualt: y) :\c"
60+
read isGlobal
61+
62+
if [[ "$isGlobal" == "n" || "$isGlobal" == "N" ]]; then
63+
BIN_DIR=${HOME}/.local/bin
64+
IS_LOCAL=1
65+
else
66+
BIN_DIR=/usr/local/bin
67+
fi
68+
}
69+
70+
install_safeu_cli() {
71+
if [ ${IS_LOCAL} -eq 1 ]; then
72+
install -Dm755 "${BIN_FILENAME}" "${BIN_DIR}/${SAFEU_CMD}" || {
73+
error "install the safeu-cli tool failed"
74+
exit 1
75+
}
76+
else
77+
sudo install -Dm755 "${BIN_FILENAME}" "${BIN_DIR}/${SAFEU_CMD}" || {
78+
error "install the safeu-cli tool failed"
79+
exit 1
80+
}
81+
fi
82+
}
83+
84+
post_install() {
85+
printf ${GREEN}
86+
87+
cat <<-'EOF'
88+
____ __ _ _ ____ _ ___
89+
/ ___| __ _ / _| ___| | | | / ___| | |_ _|
90+
\___ \ / _` | |_ / _ \ | | | | | | | | |
91+
___) | (_| | _| __/ |_| | | |___| |___ | |
92+
|____/ \__,_|_| \___|\___/ \____|_____|___| ....is now installed!
93+
94+
Now you can upload and download files via "safeu" command !
95+
If you have further questions, you can find support in here:
96+
https://github.com/NUAA-Open-Source/safeu-cli/issues
97+
98+
EOF
99+
echo " Current installed safeu-cli version: $(safeu version)"
100+
printf ${RESET}
101+
}
102+
103+
main() {
104+
setup_color
105+
# download_safeu_cli $1
106+
install_scope
107+
install_safeu_cli
108+
post_install
109+
}
110+
111+
main "$@"

main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package main
22

3-
import "github.com/arcosx/Nuwa/cmd"
3+
import "github.com/NUAA-Open-Source/safeu-cli/cmd"
44

55
func main() {
66
cmd.Execute()

upload/instance.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"os"
1212
"strings"
1313

14-
"github.com/arcosx/Nuwa/util"
14+
"github.com/NUAA-Open-Source/safeu-cli/util"
1515
)
1616

1717
// 第 0 步 获取CSRF Token

util/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package util
33
const (
44
// 如果是私有部署 SafeU 请修改链接
55
SAFEU_BASE_URL = "https://api.safeu.a2os.club"
6-
VERSION = "v0.1 beta"
6+
VERSION = "v1.0.0-alpha"
77
DEFAULT_PASSWORD = ""
88
DEFAULT_DOWN_COUNT = 10
99
DEFAULT_EXPIRE_TIME = 8

0 commit comments

Comments
 (0)