Newer
Older
bootstrap / bootstrap.sh
#!/usr/bin/env bash

# Author: MG

BASE_PATH=$(pwd)

CURRENT_USER=$(whoami)

if [[ ${CURRENT_USER} != root ]];
then
	echo "You need to run this script as root. Aborting."
	exit
fi

cd /tmp


echo "## Cloning bootstrap repo ##"
git clone https://isgb.otago.ac.nz/infosci/git/linux_lab/bootstrap.git

cd bootstrap

echo
echo -n "Enter hostname: "
read hostname
echo ${hostname}

echo
echo "About to join domain as ${hostname}"

echo "Press Enter to continue or Ctrl+c to abort"

read

echo
echo "## Setting hostname to ${hostname} ... ##"
hostnamectl set-hostname ${hostname}

echo
echo "## Running bootstrap via puppet... ##"
PUPPET_ROOT=/tmp/bootstrap/environments/production
MODULE_PATH=${PUPPET_ROOT}/modules
SITE_PATH=${PUPPET_ROOT}/manifests/site.pp
RUBYOPT='-W0' puppet apply --modulepath ${MODULE_PATH} ${SITE_PATH}

echo
echo "## Joining domain... ##"
user=$(sed -n 1p ${BASE_PATH}/domain_sekrit)
domain=$(sed -n 2p ${BASE_PATH}/domain_sekrit)
pass=$(sed -n 3p ${BASE_PATH}/domain_sekrit)
echo ${pass} | realm join --verbose --user=${user} ${domain}


echo
echo "## Cleaning up... ##"

cd ..
rm -rf /tmp/bootstrap

echo
echo "## Done. ##"