From 6552b2f47c26a9a8d5b358b779f285bcb2880164 Mon Sep 17 00:00:00 2001 From: Mike Crute Date: Wed, 27 Dec 2017 21:06:55 +0000 Subject: Add bootstrap script --- bootstrap.sh | 141 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 141 insertions(+) create mode 100755 bootstrap.sh diff --git a/bootstrap.sh b/bootstrap.sh new file mode 100755 index 0000000..78efc68 --- /dev/null +++ b/bootstrap.sh @@ -0,0 +1,141 @@ +#!/bin/bash + +#if [[ "$(hostname -f)" =~ \.crute\.me$ ]]; then +# echo "This host appears to already be bootstrapped" +# exit 1 +#fi + +if [ ! -f "/etc/default/bootstrap" ]; then + cat > /etc/default/bootstrap <> /etc/apt/apt.conf +fi + +# Get all the latest updates and remove junk +apt-get update && apt-get dist-upgrade -y && apt-get autoremove --purge -y + +# Set hostname and network settings +export HOSTNAME="${SHORT_HOSTNAME}.${REGION}.crute.me" + +if [[ "$(hostname -f)" != "$HOSTNAME" ]]; then + echo $SHORT_HOSTNAME > /etc/hostname + hostnamectl set-hostname $SHORT_HOSTNAME + systemctl restart systemd-logind.service +fi + +# Setup /etc/hosts +if ! grep "$HOSTNAME" /etc/hosts 2>&1 > /dev/null; then + sed -i "s/127.0.0.1 localhost/127.0.0.1 localhost\n127.0.1.1 ${HOSTNAME} ${SHORT_HOSTNAME}/" /etc/hosts +fi + +# Setup /etc/resolv.conf +if ! grep "search ${REGION}.crute.me" /etc/resolv.conf 2>&1 > /dev/null; then + sed -i "s/search .*/search ${REGION}.crute.me/" /etc/resolv.conf +fi + +# Install standard packages +apt-get install -y \ + ssmtp \ + iptables-persistent \ + vim \ + htop \ + curl + +# If this is a KVM host setup KVM and bridge +if [[ "$VM_HOST" == "true" ]]; then + apt-get install -y --no-install-recommends \ + qemu-kvm \ + libvirt-bin \ + virtinst \ + bridge-utils \ + libosinfo-bin \ + genisoimage \ + qemu-utils \ + unzip + + MAIN_INTF=$(ip link | awk '/^2:/ { split($2, a, ":"); print a[1]; }') + sed -i -e "s/\(.*$MAIN_INTF.*\)/#\1/" /etc/network/interfaces + + if ! grep 'auto br0' /etc/network/interfaces 2>&1>/dev/null; then + cat >> /etc/network/interfaces <> /etc/apt/apt.conf.d/10periodic +sed -i 's#//Unattended-Upgrade::Mail "root";#Unattended-Upgrade::Mail "mike@crute.us";#' /etc/apt/apt.conf.d/50unattended-upgrades +echo -e '\nUnattended-Upgrade::Sender "updates-no-reply@crute.me";' >> /etc/apt/apt.conf.d/50unattended-upgrades +sed -i 's#//Unattended-Upgrade::MailOnlyOnError "true";#Unattended-Upgrade::MailOnlyOnError "false";#' /etc/apt/apt.conf.d/50unattended-upgrades + +# Setup mcrute user +if ! id mcrute 2>&1>/dev/null; then + useradd -p '$6$qOlvVfUc$Ij86v15mQnvoPSv1KCStgEBCLvrbLLp6hszvvs857yTGfJ.tu4Qm1u1GONeJayfNAVEOF1CV9mClTlnuiR5KU.' -m -s /bin/bash -G sudo mcrute + mkdir ~mcrute/.ssh + cat > ~mcrute/.ssh/authorized_keys <