#!/bin/bash

ISUCS="$(hostname |grep ucs -c)"

if [ $ISUCS -ne 0 ]; then
	echo "Do not run this on ucs host. Exiting..."
	exit 1
fi


########################################
#Common to all systems
########################################


#Fix timezone

unlink /etc/localtime
ln -s /usr/share/zoneinfo/America/Chicago /etc/localtime

MGMT_INT=$(netstat -rn|grep 0.0.0.0|head -n1|awk '{print $NF}')
PFV_MGMT_IP=$(ifconfig $MGMT_INT|grep inet|grep 10.251 -c)
OVH_MGMT_IP=$(ifconfig $MGMT_INT|grep inet|grep 10.253 -c)

if [ $PFV_MGMT_IP -eq 1 ]; then
	tsysSysLocation=pfv
fi

if [ $OVH_MGMT_IP -eq 1 ]; then
	tsysSysLocation=ovh
fi



#Step 1: Update the cache and apply all vendor patches
echo "Running apt-get update"
export DEBIAN_FRONTEND="noninteractive" && apt-get -qq --yes update

echo "Running apt-get dist-upgrade"
export DEBIAN_FRONTEND="noninteractive" && apt-get -qq --yes dist-upgrade

echo "Running apt-get upgrade"
export DEBIAN_FRONTEND="noninteractive" && apt-get -qq --yes upgrade


echo "Running apt-get purge"
export DEBIAN_FRONTEND="noninteractive" && apt-get -qq --purge autoremove --yes


#Step 2: Cleanup default cruft
echo "removing evil from the world, one nano install at a time"
export DEBIAN_FRONTEND="noninteractive" && apt-get -qq --yes --purge remove nano

if [ $UBUNTU_SERVER -eq 0 ]; then
sed -i "s/dns=dnsmasq/#dns=dnsmasq/" /etc/NetworkManager/NetworkManager.conf
fi

unlink /etc/resolv.conf
ln -s /etc/tplab-resolv.conf /etc/resolv.conf

#Step 3: The usual suspects
export DEBIAN_FRONTEND="noninteractive" && apt-get -qq --yes -o Dpkg::Options::="--force-confold" install snmpd sssd sssd-ad ncdu iftop nethogs screen acct tshark tcpdump glances dstat htop sysdig sysstat rsync clamav logwatch zsh sl postfix molly-guard git mailutils ladvd etckeeper auditd rkhunter rsyslog ngrep ntp

#Turn on process accounting
echo "Turning on process accounting..."
accton on

newaliases

slack tsys-$tsysSysLocation
