#!/bin/bash

# create .ssh/config file with host entries for both classes
# cd /home/student/.ssh

# sudo bash -c 'cat << EOF >>/home/student/.ssh/config
# Host github.com
#         User git
#         IdentityFile /home/student/.ssh/SANS-AUD507-Workbook-J
# EOF'

# sudo chown student:student /home/student/.ssh/config
# sudo chmod 600 /home/student/.ssh/config

# # TODO: Move the deploy keys into packer and copy them over
# # download the deploy keys for the class
# wget -q http://ch.car3.co:8000/github/SANS-AUD507-Workbook-J
# sudo chmod 600 SANS-AUD507-Workbook-J
# wget -q http://ch.car3.co:8000/github/SANS-AUD507-Workbook-J.pub

# ssh-keyscan github.com >> /home/student/.ssh/known_hosts
# save github scripts which will be run by student during lab 0
sudo chown -R student /var/www/html
sudo rm -fr /var/www/html/*
sudo rm -fr /var/www/html/.git

#create bogus index file to be used before lab 0
sudo bash -c 'echo "<html><title>AUD1 Ubuntu default page</title>Welcome to the AUD1 web server!" > /var/www/html/index.html'

echo '******************************************************'
echo Cloning student lab files
echo '******************************************************'

cd /home/student
sudo rm -fR /home/student/labFiles

mkdir labFiles
git clone --branch AUD1 https://github.com/RCI-Classes/LabFilesUbuntu.git labFiles

# echo Cloning EWB repo
# git clone ssh://github.com/sans-course-workbooks/aud507-j01-workbook /var/www/html/workbook/

# echo alias workbook-update=\'/bin/bash /var/www/html/workbook/resources/workbook-update.sh\' >> /home/student/.bash_aliases

# /bin/bash /var/www/html/workbook/resources/workbook-update.sh

# echo Enabling service
# sudo systemctl enable /var/www/html/workbook/resources/ewb-update.service
# sudo systemctl start ewb-update.service

# #TODO: May not need this any more
# echo '******************************************************'
# echo Setting up systemd service to edit the issue file with the IP address of the EWB
# echo '******************************************************'

# cp /home/student/labFiles/scripts/issue-file.sh /home/student
# sudo chmod a+x /home/student/issue-file.sh

# sudo bash -c 'cat << EOF > /etc/systemd/system/issue-file.service
# [Unit]
# After=network.target

# [Service]
# ExecStart=/home/student/issue-file.sh

# [Install]
# WantedBy=default.target
# EOF'

# sudo systemctl daemon-reload
# sudo systemctl enable issue-file.service
# sudo systemctl start issue-file.service
