Skip to content

Commit

Permalink
Merge pull request #15 from NUAA-Open-Source/dev
Browse files Browse the repository at this point in the history
refact the install script & fixes
  • Loading branch information
Triple-Z authored Jun 13, 2020
2 parents 6f632d0 + 7c6c752 commit 78423e2
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 15 deletions.
30 changes: 29 additions & 1 deletion .github/workflows/install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,36 @@ jobs:
# alias wget="wget --no-check-certificate"
# sh -c "$(echo "alias wget=\"wget --no-check-certificate\""; yes | wget -qO- https://raw.githubusercontent.com/NUAA-Open-Source/safeu-cli/master/install.sh)"

- name: print install script help message
run: |
sh ./install.sh --help
# should not have safeu command
if [ -x "$(command -v safeu)" ]; then echo "should not have the safeu command"; exit 1; else exit 0; fi
- name: print install script version for safeu-cli
run: |
sh ./install.sh --version
# should not have safeu command
if [ -x "$(command -v safeu)" ]; then echo "should not have the safeu command"; exit 1; else exit 0; fi
- name: run install script
run: sh ./install.sh <<< Y
run: sh ./install.sh

- name: test safeu cli
run: safeu version

- name: remove the safeu cli
run: |
sudo rm -rf /usr/local/bin/safeu
# should not have safeu command
if [ -x "$(command -v safeu)" ]; then echo "should not have the safeu command"; exit 1; else exit 0; fi
- name: run install script with local option
run: |
export PATH=$HOME/.local/bin:$PATH
sh ./install.sh --local
- name: test safeu cli
run: |
export PATH=$HOME/.local/bin:$PATH
safeu version
28 changes: 23 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
<!-- omit in toc -->
# SafeU CLI

![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)
![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)

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

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

## Install

> If you are in China mainland, the install method in [China mainland optimized](#china-mainland-optimized) is a better choice.
> If you are in China mainland, the install methods in [China mainland optimized](#china-mainland-optimized) is a better choice.
> 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.
Expand All @@ -42,20 +44,36 @@ $ sh -c "$(wget -qO- https://raw.githubusercontent.com/NUAA-Open-Source/safeu-cl

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

### Install safeu-cli just for current user

via curl:

```bash
$ sh -c "$(curl -fsSL https://raw.githubusercontent.com/NUAA-Open-Source/safeu-cli/master/install.sh) --local"
```

via wget:

```bash
$ sh -c "$(wget -qO- https://raw.githubusercontent.com/NUAA-Open-Source/safeu-cli/master/install.sh) --local"
```

### China mainland optimized

via curl:

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

via wget:

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

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

### Upload
Expand All @@ -75,7 +93,7 @@ $ safeu upload filename1 filename2 filename3

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

Examples for this section will be supplement lately.
Examples for this section will be supplemented lately.

#### Full detail of upload command

Expand Down
69 changes: 60 additions & 9 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,31 @@ BIN_DIR=/usr/local/bin
BIN_FILENAME=safeu.tmp
SAFEU_CMD=safeu
IS_LOCAL=0
IS_CN=0
VERSION=v1.0.0-alpha


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
}
Expand All @@ -41,7 +64,7 @@ setup_color() {
}

download_safeu_cli() {
if [ "$1" = "cn" ]; then
if [ $IS_CN -eq 1 ]; then
wget -cO ${BIN_FILENAME} ${SAFEU_CN_RELEASE} || {
error "cannot download safeu-cli by ${SAFEU_CN_RELEASE}"
exit 1
Expand All @@ -56,19 +79,15 @@ download_safeu_cli() {
}

install_scope() {
if [ "$(id -u)" -eq "0" ]; then
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

printf "${YELLOW}Install safeu command tool globally (require sudo permission later) ? [Y/N, Default: Y]: "
read isGlobal

if [ "$isGlobal" = "n" ] || [ "$isGlobal" = "N" ] ; then
if [ $IS_LOCAL -eq 1 ] ; then
BIN_DIR=${HOME}/.local/bin
IS_LOCAL=1
else
BIN_DIR=/usr/local/bin
fi
Expand Down Expand Up @@ -108,12 +127,44 @@ EOF
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
download_safeu_cli $1
get_args $@
install_scope

# download & install safeu-cli
download_safeu_cli
install_safeu_cli

# print success message
post_install
}

main "$@"
main $@

0 comments on commit 78423e2

Please # to comment.