|
| 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 "$@" |
0 commit comments