Skip to content

Instantly share code, notes, and snippets.

@zakariaboualaid
Created August 6, 2014 01:57
Show Gist options
  • Save zakariaboualaid/bd1707940c2e7c33654c to your computer and use it in GitHub Desktop.
Save zakariaboualaid/bd1707940c2e7c33654c to your computer and use it in GitHub Desktop.
when you run umbreo command-line
#!/bin/bash
echo "Setting up Umbreo"
set -u
set -e
# Some utility functions.
fail() { echo >&2 "$@"; exit 1; }
cmd() { hash "$1" >&/dev/null; } # portable 'which'
getHTTPCode () { curl -kL --write-out %{http_code} --silent --output /dev/null $1; }
set -e
set -u
EXPECTED_ARGS=3
E_BADARGS=65
if [ $# -ne $EXPECTED_ARGS ]
then
echo "Usage: $0 username secret_key node_token"
exit $E_BADARGS
fi
lowercase(){
echo "$1" | sed "y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/"
}
OS=`lowercase \`uname\``
KERNEL=`uname -r`
MACH=`uname -m`
MASTER_HOSTNAME=beta.umbreo.com
NODE_HOSTNAME=$3
if [ "{$OS}" == "darwin" ]; then
OS=mac
else
OS=`uname`
if [ "${OS}" = "SunOS" ] ; then
OS=Solaris
ARCH=`uname -p`
OSSTR="${OS} ${REV}(${ARCH} `uname -v`)"
elif [ "${OS}" = "AIX" ] ; then
OSSTR="${OS} `oslevel` (`oslevel -r`)"
elif [ "${OS}" = "Linux" ] ; then
if [ -f /etc/redhat-release ] ; then
DistroBasedOn='RedHat'
elif [ -f /etc/SuSE-release ] ; then
DistroBasedOn='SuSe'
elif [ -f /etc/mandrake-release ] ; then
DistroBasedOn='Mandrake'
elif [ -f /etc/debian_version ] ; then
DistroBasedOn='Debian'
elif [ -f /etc/system-release ]; then
if grep -qi 'amazon linux' /etc/system-release; then
DistroBasedOn='Amazon'
fi
fi
if [ -f /etc/UnitedLinux-release ] ; then
DIST="${DIST}[`cat /etc/UnitedLinux-release | tr "\n" ' ' | sed s/VERSION.*//`]"
fi
DistroBasedOn=`lowercase $DistroBasedOn`
fi
fi
case $DistroBasedOn in
debian)
apt-get -y install wget
wget http://apt.puppetlabs.com/puppetlabs-release-precise.deb
dpkg -i puppetlabs-release-precise.deb
apt-get update
apt-get -y install puppet
puppet config set server $MASTER_HOSTNAME --section agent
puppet config set certname $NODE_HOSTNAME --section agent
puppet resource service puppet ensure=running enable=true
;;
redhat)
rpm -ivh http://yum.puppetlabs.com/el/6/products/$MACH/puppetlabs-release-6-6.noarch.rpm || true
yum-config-manager --setopt=puppetlabs-products.priority=1 --save
yum -y install puppet
puppet config set server beta.umbreo.com --section agent
puppet resource service puppet ensure=running enable=true
echo "certname = $3" >> /etc/puppet/puppet.conf
;;
amazon)
yum -y install puppet
echo "certname = $3" >> /etc/puppet/puppet.conf
echo "server = $MASTER_HOSTNAME" >> /etc/puppet/puppet.conf
;;
*)
echo "Your operating system is not compatible with this script - please contract Umbreo Support"
exit 1
esac
mkdir -p /etc/facter/facts.d
cat > /etc/facter/facts.d/config.json <<EOF
{"user" : "$1", "token" : "$2", "certname" : "$3" }
EOF
puppet agent -t
echo "Congrats! Umbreo is enabled in your server."
echo "Your server should shortly be visible online on your Umbreo dashboard."
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment