#!/bin/bash

# http://thomasmullaly.com/2016/11/04/linux-auto-deployment-using-ipxe-and-saltstack/

saltMaster="salt.service.dallas.slvn.co"

exec 1>/dev/tty1
exec 2>&1

echo "Allowing remote login via passwords."
sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config

wget -O - https://repo.saltstack.com/apt/ubuntu/18.04/amd64/3000/SALTSTACK-GPG-KEY.pub | sudo apt-key add -
apt-add-repository "deb http://repo.saltstack.com/apt/ubuntu/18.04/amd64/3000 bionic main"
apt-get -q update

echo "Installing the salt minion."
apt-get install -y salt-minion python3-pip

echo "Configuring the minion."
mkdir -p /etc/salt/minion.d
echo "master: ${saltMaster}" > /etc/salt/minion.d/99-master-address.conf

echo "Installing post install service."
mkdir /usr/share/post-install
wget http://pxe.service.dallas.slvn.co:8069/ubuntu-18.04/post-install.service -O /lib/systemd/system/post-install.service;
wget http://pxe.service.dallas.slvn.co:8069/ubuntu-18.04/post-install.sh -O /usr/share/post-install/post-install.sh;
systemctl enable post-install.service

echo "Completed prepare."