Skip to content

Instantly share code, notes, and snippets.

@mbeale
Created March 21, 2017 22:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mbeale/35112c86215c0a771e1b4391055e19e4 to your computer and use it in GitHub Desktop.
Save mbeale/35112c86215c0a771e1b4391055e19e4 to your computer and use it in GitHub Desktop.
greg
#!/usr/bin/env bash
#
# Python MAC OSX Librato Agent install script
# Version: 0.0.2
# Author: Librato
#
# run:
# curl -s "https://raw.githubusercontent.com/librato/python-librato-agent/master/sh/install.sh?" | bash
#
# Execute a command as root (or sudo)
# borrowed from https://github.com/nicolargo/glancesautoinstall/blob/master/install.sh
do_with_root() {
# already root? "Just do it" (tm).
if [[ `whoami` = 'root' ]]; then
$*
elif [[ -x /bin/sudo || -x /usr/bin/sudo ]]; then
echo "sudo $*"
sudo $*
else
echo "This script requires root privileges to install"
echo "Please run this script as root."
exit 1
fi
}
EMAIL="mbeale@librato.com"
TOKEN="69861c62153623364600d0ffcdcdfa0d0725bf37cc3b7445f800a22159a95d94"
if [[ "$OSTYPE" == "darwin"* ]]; then
echo "=============Installing Dependencies=============="
if [[ `xcode-select -p` ]]; then
echo "xcode installed"
else
echo "xcode must be installed"
echo "click install on the pop up or run:"
echo "xcode-select --install"
xcode-select --install
exit 1
fi
if [[ `which pip` ]]; then
echo "pip already installed"
else
do_with_root easy_install pip
echo "pip installed"
fi
if [[ `which mac-os-agent` ]]; then
do_with_root pip install librato-agent -U --ignore-installed six
echo "updated librato-agent"
else
do_with_root pip install librato-agent --ignore-installed six
fi
echo "================Exporting Keys===================="
export LIBRATO_USERNAME=${EMAIL}
export LIBRATO_TOKEN="${TOKEN}"
if [ $SUDO_USER ]; then user=$SUDO_USER; else user=`whoami`; fi
echo "creating config file at ${HOME}/.mac-agent"
if [ ! -f $HOME/.mac-agent ]; then
touch ${HOME}/.mac-agent
echo "LIBRATO_USERNAME=${EMAIL}" > $HOME/.mac-agent
echo "LIBRATO_TOKEN=${TOKEN}" >> $HOME/.mac-agent
echo "created config file"
do_with_root chown $SUDO_USER $HOME/.mac-agent
else
echo "config file already exists and will not be changed"
fi
echo "==============Initializing Space=================="
IN=$(mac-os-agent create)
IFS=':' read -ra SPACES <<< "$IN"
echo "Spaces for demo data:"
for i in "${SPACES[@]}"; do
echo "https://metrics.librato.com/s/spaces/${i}"
done
echo "=================Post Install====================="
echo "Installation complete!"
echo "Running the Mac OSX agent (it may take up to two minutes to start submitting metrics)...."
mac-os-agent start
echo "run `mac-os-agent stop` if you want to terminate the process"
echo "you can run `mac-os-agent start` to start the sending measurements again"
else
#unsupported system
echo "Sorry but this script isn't supported by your system"
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment