Created
April 10, 2017 18:42
-
-
Save mbeale/d1bb2adedd87532be7a4d46d29f1ec36 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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="your email" | |
TOKEN="your token" | |
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 librato-macos` ]]; then | |
do_with_root pip install librato-macos -U --ignore-installed six | |
echo "updated librato-agent" | |
else | |
do_with_root pip install librato-macos --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}/.librato-macos" | |
if [ ! -f $HOME/.librato-macos ]; then | |
touch ${HOME}/.librato-macos | |
echo "LIBRATO_USERNAME=${EMAIL}" > $HOME/.librato-macos | |
echo "LIBRATO_TOKEN=${TOKEN}" >> $HOME/.librato-macos | |
echo "created config file" | |
do_with_root chown $SUDO_USER $HOME/.librato-macos | |
else | |
echo "config file already exists and will not be changed" | |
fi | |
if [ ! -f $HOME/librato-macos.log ]; then | |
touch ${HOME}/librato-macos.log | |
do_with_root chown $SUDO_USER $HOME/librato-macos.log | |
else | |
echo "log file already exists and will not be created" | |
fi | |
echo "==============Initializing Space==================" | |
IN=$(librato-macos 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 librato-macos (it may take up to two minutes to start submitting metrics)...." | |
librato-macos start | |
echo "run `librato-macos stop` if you want to terminate the process" | |
echo "you can run `librato-macos 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