|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +set -e |
| 4 | + |
| 5 | +add_to_path() { |
| 6 | + shell="$SHELL"; |
| 7 | + rcfile=".bashrc" |
| 8 | + if [[ "$shell" == *"zsh" ]]; then |
| 9 | + rcfile=".zshrc"; |
| 10 | + fi |
| 11 | + if grep -q "/.altlimit/bin" "$HOME/$rcfile"; then |
| 12 | + echo "~/.altlimit/bin already in zsh path" |
| 13 | + else |
| 14 | + echo "Adding ~/.altlimit/bin to PATH in $rcfile"; |
| 15 | + echo 'export PATH=$PATH:$HOME/.altlimit/bin' >> $HOME/$rcfile; |
| 16 | + echo "Restart your terminal or run 'source ~/$rcfile'" |
| 17 | + fi |
| 18 | +} |
| 19 | + |
| 20 | +install_binary() { |
| 21 | + if [[ ! -d $HOME/.altlimit/bin ]]; then |
| 22 | + echo "Making $HOME/.altlimit/bin" |
| 23 | + mkdir -p $HOME/.altlimit/bin; |
| 24 | + fi |
| 25 | + echo "Downloading latest statusalert binary at: $1"; |
| 26 | + curl -o $HOME/.altlimit/bin/statusalert.tgz -s -S -L "$1" |
| 27 | + tar -xf $HOME/.altlimit/bin/statusalert.tgz -C $HOME/.altlimit/bin/ |
| 28 | + rm $HOME/.altlimit/bin/statusalert.tgz |
| 29 | + if [ $? -ne 0 ]; then |
| 30 | + echo "Download failed."; |
| 31 | + exit 1; |
| 32 | + fi |
| 33 | + chmod +x $HOME/.altlimit/bin/statusalert; |
| 34 | + add_to_path; |
| 35 | + echo "statusalert has been installed at $HOME/.altlimit/bin"; |
| 36 | +} |
| 37 | + |
| 38 | +if [[ "$OSTYPE" == "linux-gnu"* ]]; then |
| 39 | + MACHINE_TYPE=`uname -m` |
| 40 | + if [ ${MACHINE_TYPE} == 'x86_64' ]; then |
| 41 | + install_binary "https://github.com/altlimit/statusalert/releases/download/latest/linux.tgz" |
| 42 | + else |
| 43 | + echo "${MACHINE_TYPE} not supported. Try building from source."; |
| 44 | + exit 1; |
| 45 | + fi |
| 46 | +elif [[ "$OSTYPE" == "darwin"* ]]; then |
| 47 | + # Mac OSX |
| 48 | + MACHINE_TYPE=`uname -m` |
| 49 | + if [ ${MACHINE_TYPE} == 'x86_64' ]; then |
| 50 | + install_binary "https://github.com/altlimit/statusalert/releases/download/latest/darwin.tgz" |
| 51 | + else |
| 52 | + echo "${MACHINE_TYPE} not supported. Try building from source."; |
| 53 | + exit 1; |
| 54 | + fi |
| 55 | +else |
| 56 | + echo "$OSTYPE not yet supported."; |
| 57 | + exit 1; |
| 58 | +fi |
0 commit comments