forked from buger/cloud-ssh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
68 lines (54 loc) · 1.7 KB
/
install.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env bash
shopt -s extglob
set -o errtrace
set -o errexit
readonly PROGNAME=$(basename $0)
readonly ARGS="$@"
readonly VERSION="0.4"
log() { printf "%b\n" "$*"; }
fail() { log "\nERROR: $*\n" ; exit 1 ; }
install_initialization(){
if [ "$(uname)" == "Darwin" ]; then
URL="https://github.com/buger/cloud-ssh/releases/download/$VERSION/cloud_ssh_macosx.tar.gz"
elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then
URL="https://github.com/buger/cloud-ssh/releases/download/$VERSION/cloud_ssh_x86.tar.gz"
elif [ "$(expr substr $(uname -s) 1 10)" == "MINGW32_NT" ]; then
fail 'Installation script for Windows platform not yet supported. But you still can manually download binaries.'
fi
}
download_binary(){
TEMPFILE=$(mktemp /tmp/cloud-ssh.XXXXXX)
echo "Downloading binary from Github: $1"
if curl --fail -L "$1" --progress-bar > $TEMPFILE
then
echo "Unpacking"
else
fail "Failed to download binary from Github. Try later, or install manually."
fi
}
unpack_binary(){
tar -xzf $TEMPFILE -C $1
rm "$TEMPFILE"
}
install_example_configuration(){
EXAMPLE_CONFIG="https://raw.githubusercontent.com/buger/cloud-ssh/master/cloud-ssh.yaml.example"
CONFIG_PATH=~/.ssh/cloud-ssh.yaml
if [ ! -f $CONFIG_PATH ]; then
curl --fail -L -# "$EXAMPLE_CONFIG" > $CONFIG_PATH
echo "Configuration file located at $CONFIG_PATH"
fi
}
install(){
DEFAULT_PATH="/usr/local/bin"
read -p "Choose path to install cloud-ssh binary? [Default: $DEFAULT_PATH ] " path
path=${path:-$DEFAULT_PATH}
download_binary $URL
unpack_binary $path
install_example_configuration
echo "cloud-ssh succesfully installed"
}
main() {
install_initialization
install $ARGS
}
main