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 "## Purging annoying crap... ##"

snap remove lxd
snap remove core18
apt purge cloud-init
apt autopurge

echo "## Disabling snapd... ##"
systemctl stop snapd
systemctl disable snapd

echo "## Copying sources.list... ##"
cp /media/infoadmin/CIDATA/sources.list /etc/apt

echo "## APT Update... ##"
apt update

echo "## Making sure Git and Puppet are installed... ##"
apt install git puppet

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 set hostname to ${hostname} and run bootstrap."

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 "## Cleaning up... ##"

cd ..
rm -rf /tmp/bootstrap

echo
echo "## Done. ##"

exit


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
echo "## Leaving domain... ##"
echo ${pass} | realm leave --verbose --user=${user} ${domain}

echo
echo "## Joining domain... ##"
echo ${pass} | realm join --verbose --user=${user} ${domain}

echo
#echo "## Running bootstrap via puppet again (to correct changes made as a result of domain join) ... ##"
# RUBYOPT='-W0' puppet apply --modulepath ${MODULE_PATH} ${SITE_PATH}

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

#cd ..
#rm -rf /tmp/bootstrap

echo
echo "## Done. ##"