#!/bin/sh # written by Cloudeasy Inc. ## So you decided to check what this script does before running it on ## your server? This is great! It is for people like you that Cloudeasy ## is made for. ## ## At Cloudeasy we believe that knowledge is freedom. We are here to make ## your life easier and you have the right to know how we do this, after ## all, we are partners and partners trust each other. ;) ## ## Be welcome and enjoy! ## validates the script usage if [ $# -lt 2 ]; then echo "Usage: $0 FQDN" exit 1 fi ## global settings and variables export DEBIAN_FRONTEND=noninteractive export CLOUDEASY_LOGFILE=$PWD/.cloudeasy.log ## update apt-get -q update &>> $CLOUDEASY_LOGFILE ## ensure "aptitude" command exists apt-get -q -y install aptitude &>> $CLOUDEASY_LOGFILE apt-get -q -y install &>> $CLOUDEASY_LOGFILE ## it is common for a just-installed server to have some out-dated ## packages, so let's get everything upt-to-date brefore proceeding echo echo - Block apache2 from being installed apt-mark hold apache2 &>> $CLOUDEASY_LOGFILE echo 'Package: apache2 Pin: release o=Ubuntu Pin-Priority: -1' >> /etc/apt/preferences echo '> installing pending updates:' echo ' - exec: aptitude update' aptitude -q -y update &>> $CLOUDEASY_LOGFILE echo ' - exec: aptitude safe-upgrade' aptitude -q -y safe-upgrade &>> $CLOUDEASY_LOGFILE echo ' - exec: aptitude full-upgrade' aptitude -q -y full-upgrade &>> $CLOUDEASY_LOGFILE echo ' - exec: aptitude install' aptitude -q -y install &>> $CLOUDEASY_LOGFILE aptitude -q -y install python &>> $CLOUDEASY_LOGFILE ## a small hack to fake the domain name in the first puppet execution, ## at the very beginning of puppet setup, the hostname and domainname ## will be configured properly and here we just ensure that the server ## are passing (or faking it) the correct values before to puppet echo echo '> configuring server hostname' echo " - exec: hostname $1" hostname $1 &>> $CLOUDEASY_LOGFILE ## installing puppet from puppetlabs RELEASE=`lsb_release -a 2> /dev/null | grep '^Codename' | \ tr -d '[:space:]' | cut -d ':' -f 2` PACKAGE="puppet6-release-${RELEASE}.deb" WEBSITE="http://apt.puppetlabs.com/${PACKAGE}" echo echo '> installing required packages:' echo " - exec: wget $WEBSITE" wget -q $WEBSITE -O /tmp/$PACKAGE &>> $CLOUDEASY_LOGFILE echo " - exec: dpkg -i /tmp/$PACKAGE" dpkg -i /tmp/$PACKAGE &>> $CLOUDEASY_LOGFILE echo ' - exec: aptitude update' aptitude -q -y update &>> $CLOUDEASY_LOGFILE echo ' - exec: aptitude safe-upgrade' aptitude -q -y safe-upgrade &>> $CLOUDEASY_LOGFILE echo ' - exec: aptitude full-upgrade' aptitude -q -y full-upgrade &>> $CLOUDEASY_LOGFILE echo ' - exec: aptitude install' aptitude -q -y install &>> $CLOUDEASY_LOGFILE echo ' - exec: aptitude install puppet' aptitude -q -y install puppet-agent &>> $CLOUDEASY_LOGFILE /bin/ln -s /opt/puppetlabs/bin/puppet /usr/bin/puppet echo ' - exec: puppet agent --enable' /usr/bin/puppet agent --enable &>> $CLOUDEASY_LOGFILE systemctl disable puppet &>> $CLOUDEASY_LOGFILE systemctl mask puppet &>> $CLOUDEASY_LOGFILE ## let the magic begin: connect server to Cloudeasy echo echo '> connecting server to cloudeasy:' echo " - exec: puppet agent --server puppet1.cloudez.io --fqdn $1" puppet agent --server puppet1.cloudez.io --fqdn $1 \ --waitforcert 30 --test &>> $CLOUDEASY_LOGFILE ## ... if not connected, display cloudeasy error message RETVAL=$? if [ $RETVAL -ne 0 ] && [ $RETVAL -ne 2 ]; then ERROR=`grep -e 'Error [0-9]\+ on SERVER:' $CLOUDEASY_LOGFILE | \ sed 's/.*Error [0-9]\+ on SERVER: \(.*\.\) at .*/\1/' | \ tail -n 1` echo " ! $ERROR" exit 3 fi ## restart because package updates and network settings echo echo '> restarting server' echo ' - exec: reboot' echo sync cez --apply --full --delayed shutdown -r +1 --no-wall ## Reboot after the change finishes running #tail -F /var/log/syslog | grep --line-buffered 'Applied catalog in' | while read ; do reboot ; done