|
| 1 | +#!/bin/sh |
| 2 | +# |
| 3 | +# Installation script for Unix platforms. To run installation, type : |
| 4 | +# |
| 5 | +# $ sh -c "$(curl https://github.com/intercloud/gobinsec/releases/latest/download/install)" |
| 6 | +# |
| 7 | +# or (if you don't have curl installed): |
| 8 | +# |
| 9 | +# $ sh -c "$(wget -O - https://github.com/intercloud/gobinsec/releases/latest/download/install)" |
| 10 | + |
| 11 | +set -e |
| 12 | + |
| 13 | +NAME="gobinsec" |
| 14 | + |
| 15 | +# get OS and ARCH and build binary name |
| 16 | +os=`uname | tr '[:upper:]' '[:lower:]'` |
| 17 | +arch=`uname -m` |
| 18 | + |
| 19 | +if [ "$arch" = "i386" ]; then |
| 20 | + arch="386" |
| 21 | +elif [ "$arch" = "x86_64" ]; then |
| 22 | + arch="amd64" |
| 23 | +fi |
| 24 | + |
| 25 | +echo "os: ${os}" |
| 26 | +echo "arch: ${arch}" |
| 27 | + |
| 28 | +binary="${NAME}-${os}-${arch}" |
| 29 | + |
| 30 | +# set default installation directory |
| 31 | +if [ -d "/opt/local/bin" ] |
| 32 | +then |
| 33 | + DEFAULT_DIR="/opt/local/bin" |
| 34 | +elif [ -d "/opt/bin" ] |
| 35 | +then |
| 36 | + DEFAULT_DIR="/opt/bin" |
| 37 | +elif [ -d "/usr/local/bin" ] |
| 38 | +then |
| 39 | + DEFAULT_DIR="/usr/local/bin" |
| 40 | +elif [ -d "/usr/bin" ] |
| 41 | +then |
| 42 | + DEFAULT_DIR="/usr/bin" |
| 43 | +else |
| 44 | + DEFAULT_DIR="/bin" |
| 45 | +fi |
| 46 | + |
| 47 | +# select command to download binary |
| 48 | +if hash curl 2>/dev/null |
| 49 | +then |
| 50 | + command="curl -o" |
| 51 | +elif hash wget 2>/dev/null |
| 52 | +then |
| 53 | + command="wget -O" |
| 54 | +else |
| 55 | + echo "You must install curl or wget to run this installation script" |
| 56 | + exit 1 |
| 57 | +fi |
| 58 | + |
| 59 | +# download binary in /tmp/${NAME} and make it executable |
| 60 | +${command} /tmp/${NAME} https://github.com/intercloud/${NAME}/releases/latest/download/${binary} |
| 61 | +chmod +x /tmp/${NAME} |
| 62 | + |
| 63 | +# prompt for installation directory |
| 64 | +read -p "Installation directory [${DEFAULT_DIR}]? " directory |
| 65 | +if [ -z "$directory" ] |
| 66 | +then |
| 67 | + directory=${DEFAULT_DIR} |
| 68 | +fi |
| 69 | + |
| 70 | +# copy binary to installation directory |
| 71 | +if [ -w "${directory}" ] |
| 72 | +then |
| 73 | + mv /tmp/${NAME} ${directory} |
| 74 | +else |
| 75 | + sudo mv /tmp/${NAME} ${directory} |
| 76 | + sudo chown root: ${directory}/${NAME} |
| 77 | +fi |
| 78 | + |
| 79 | +echo "${NAME} installed in '${directory}' directory" |
0 commit comments