#!/bin/bash

# USAGE: assn1_check.bash

# PURPOSE: To collect information to be sent to instructor
# Author: Murray Saul
# Date: Feb 29, 2012

userName=$(whoami)

if [ "$userName" != "root" ] 2> /dev/null
then
  clear
  cat <<+
$(echo -e "\e[0;31mWARNING:\e[m")

You must run this shell script as "root".

For Example:

su
./assn1_check.bash

Please run these two commands (one after each other)
to properly run this submission preparation program...

+
  exit 1
fi

clear
cat <<+
$(echo -e "\e[0;33mOPS235 ASSIGNMENT #1 - PREPARATION PROGRAM\e[m")

This program is designed to "assemble" information in
your fedora2 VM into a file called "/root/assn1.txt"
that you will then manually e-mail as an attachment
to your OPS235 instructor.

Press ENTER to continue
+
read null

vmName=$(hostname)

if [ "$vmName" != "fedora2" ] 2> /dev/null
then
   clear
   cat <<+
$(echo -e "\e[0;31mWARNING: \e[mMake certain Your Virtual Machine is \"fedora2\".")

You MUST run this shell script in your "fedora2"
virtual machine. Failure to use the "fedora2" VM for
this assignment will result in a loss of marks for
this assignment.
 
+
fi

read -p "Do you want to proceed? (y/n): " response

if [ "$response" = "y" ] 2> /dev/null
then

read -p "Enter your Full Name: " fullName
read -p "Did you perform BONUS for \"sudo\" Section? (y/n): " bonusChoice

if [ "$bonusChoice" = "y" ] 2> /dev/null
then
  cat <<+

Transfer your document (for your bonus) in the
home directory for your unpriviledged account.

+

fi


cat > /root/assn1.txt <<+
OPS235 - ASSIGNMENT 1 - AUTOMATIC SUBMISSION

Name: $fullName

Submission Date: $(date +"%A %b %d, %Y")

Performed Bonus: $bonusChoice

SUDO:

CONTENTS OF /etc/sudoers FILE:

+
cat /etc/sudoers >> /root/assn1.txt
cat >> /root/assn1.txt <<+

SYSADMIN:

A. SCRIPT CONTENTS:

+
cat /bin/snapshot >> /root/assn1.txt
cat >> /root/assn1.txt <<+

B. CONTENTS OF /var/log/snapshot.txt FILE:

+
cat /var/log/snapshot.txt >> /root/assn1.txt
cat >> /root/assn1.txt <<+

C. SCHEDULED TO RUN DEC 25th:

+
cat /var/spool/cron/atjobs >> /root/assn1.txt

else
  clear
  cat <<+
$(echo -e "\e[0;31m*** PROGRAM ABORTED ***\e[m")

You have aborted your submission program.
Please make fixes, and then re-run this
program...

+
  exit 1
fi

clear
cat <<+
$(echo -e "\e[0;32m*** INFORMATION FILE CREATED ***\e[m")

A file called "/root/assn1.txt" has been
created that contains information for marking
purposes.

Copy this file to your unpriviledged account's home directory
+
if [ "$bonusChoice" = "y" ] 2> /dev/null
then
  cat <<+
and make certain your bonus file is in that home directory,
+
fi
cat <<+
and then send an e-mail message via your learn webmail
(using a web-browser in your fedora2 VM) to your instructor
using the information below:

   Instructor e-mail: $(echo -e "\e[0;32mmurray.saul@senecac.on.ca\e[m")
   Subject line:      $(echo -e "\e[0;32mAssn1\e[m")
   File Attachments: $(echo -e "\e[0;32m/home/your_user_id/assn1.txt\e[m")
+
if [ "$bonusChoice" = "y" ] 2> /dev/null
then
  cat <<+
                     $(echo -e "\e[0;32m/home/your_user_id/bonus_document_name\e[m")
+
fi
cat <<+

... Press ENTER to exit this program and proceed with
    sending e-mail to your instructor ...
+
read null


