diff --git a/.github/workflows/install.yml b/.github/workflows/install.yml index 6b32350..21d762a 100644 --- a/.github/workflows/install.yml +++ b/.github/workflows/install.yml @@ -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 diff --git a/README.md b/README.md index 90d3a1b..d8c2282 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,13 @@ # 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) @@ -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. @@ -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 @@ -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 diff --git a/install.sh b/install.sh index 1ecf0d7..bcb12bf 100755 --- a/install.sh +++ b/install.sh @@ -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 } @@ -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 @@ -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 @@ -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 $@