#!/bin/bash
# Script to run, just after a kickstart, which will start things rolling.
CDROM="/dev/sr0"
## change below line to /dev/sdb1 if single harddrive ###
#CDROM="/dev/sdb1"
if [ $# -eq 0 ]; then
	echo "Below is the usage info. Please note only the hostname is required."
        echo "Usage ksdaisy.sh {hostname} {ipaddr} {dnsaddr} {gateway} {netmask}"
        exit 1
fi
if [ "$2" == "" ]; then
	new_ip="192.168.1.21"
else
	new_ip="$2"
fi
if [ "$3" == "" ]; then
	new_dns="192.168.1.1"
else
	new_dns="$3"
fi
if [ "$4" == "" ]; then
	new_gateway="192.168.1.1"
else
	new_gateway="$4"
fi
if [ "$5" == "" ]; then
	new_netmask="255.255.255.0"
else
	new_netmask="$5"
fi
mount $CDROM /mnt
if [ $? -eq 0 ]; then
	umount $CDROM
	echo "CDROM mounting ok.....continuing"
else
	echo "CDROM could not be mounted.....exiting"
	exit 1
fi
ping -c 5 google.com
if [ $? -eq 0 ]; then
	echo "Internet connection working.....continuing"
else
	echo "Internet connection down.....exiting"
	exit 1
fi
echo "`date` -- Beginning Daisy Install ${1}.teleflora.com" >/tmp/verify.txt
cd /tmp
wget http://rtihardware.homelinux.com/ostools/ostools-1.15-latest.tar.gz
tar xvfz ostools-1.15-latest.tar.gz
./bin/install-ostools.pl ./ostools-1.15-latest.tar.gz --noharden-linux
/teleflora/ostools/bin/updateos.pl --ipaddr="$new_ip" --gateway="$new_gateway" --netmask="$new_netmask" --hostname=$1
service network restart
sleep 4
/teleflora/ostools/bin/updateos.pl --nameserver="$new_dns"
ping -c 5 google.com
if [ $? -eq 0 ]; then
	echo "Internet connection working.....continuing"
else
	echo "Internet connection down.....exiting"
	exit 1
fi
systemctl disable firewalld
systemctl enable iptables
yum -y remove firewalld
/teleflora/ostools/bin/harden_linux.pl --iptables
cd /tmp
wget http://rtihardware.homelinux.com/rhel7.7_64_daisy_efi/daisy_10.1.22_rhel7.iso
wget http://rtihardware.homelinux.com/rhel7.7_64_daisy_efi/daisy7-mig.sh
wget http://rtihardware.homelinux.com/support/utils.tar
wget http://rtihardware.homelinux.com/support/term.tar
wget http://rtihardware.homelinux.com/support/numlock
wget http://rtihardware.homelinux.com/support/crawlmenu_RH7test.tar
#wget http://rtihardware.homelinux.com/support/monitor_check.sh
#for x in {01..12}
#do
#systemctl enable getty@tty.service
#done
/teleflora/ostools/bin/updateos.pl --baremetal
/teleflora/ostools/bin/updateos.pl --ospatches
/teleflora/ostools/bin/updateos.pl --daisy8
mkdir /mnt/cdrom
mount -o loop /tmp/daisy_10.1.22_rhel7.iso /mnt/cdrom
cd /mnt/cdrom
systemctl disable getty@tty1
./install-daisy.pl /d/daisy
cd /tmp
umount /mnt/cdrom
mkdir /home/tfsupport/.ssh
chmod 700 /home/tfsupport/.ssh
chown tfsupport:daisy /home/tfsupport/.ssh
wget http://rtihardware.homelinux.com/t1800/tfsupport-authorized_keys
wget http://rtihardware.homelinux.com/t1800/twofactor-20090723.tar
tar xvf /tmp/twofactor-20090723.tar
chmod +x /tmp/*.pl
cp /tmp/tfsupport-authorized_keys /home/tfsupport/.ssh/authorized_keys
chmod 700 /home/tfsupport/.ssh/authorized_keys
chown tfsupport:root /home/tfsupport/.ssh/authorized_keys
rm -f /etc/cron.d/nightly-backup
rm -f /tmp/rtibackup.pl
echo "Installing Kaseya....."
wget http://rtihardware.homelinux.com/support/KcsSetup.sh
chmod +x /tmp/KcsSetup.sh
/tmp/KcsSetup.sh
echo "Installing base edir....."
cd /tmp
rm -f /tmp/edir_installbase.pl
wget http://rtihardware.homelinux.com/daisy/edir_installbase.pl
chmod +x /tmp/edir_installbase.pl
wget http://rtihardware.homelinux.com/daisy/edir_base_latest.tar.gz
/tmp/edir_installbase.pl /tmp/edir_base_latest.tar.gz
echo "edir base installed....."
yum -y remove NetworkManager
cd /d/daisy
./rbl 20
mv /d/menus/crawlmenu /d/menus/crawlmenu.stage
mv /d/startup/session /d/startup/session.stage
tar xvf /tmp/utils.tar --directory /d/utils
cp -rp /d/utils/crawlmenu /d/menus
cp -rp /d/utils/session /d/startup
cp -rp /tmp/numlock /usr/local/bin 
chmod a+x /usr/local/bin/numlock
/d/daisy/bin/dsyperms.pl
cd /tmp
tar xvfz ./ostools-1.15-latest.tar.gz
./bin/install-ostools.pl ./ostools-1.15-latest.tar.gz
echo "Enabling Virtual Consoles...."
for x in {1..12}
do
systemctl enable getty@tty$x.service
done
echo "`date` -- End Daisy Install ${1}.teleflora.com" >>/tmp/verify.txt
# Verify
/tmp/verify.sh
echo "Remove the DVD from the drive"
echo "Please reboot the system......ctl-alt-del"
