#!/bin/bash

###############################################################
# Description: Sets up automatic IP emailing on Raspberry Pi  #
# Usage: Takes one positional argument, WUSTL Key             #
# Authors: Ellen Dai (ellen.dai) and John Gibson (johngibson) #
###############################################################

sudo apt-get update && sudo apt-get install -y ssmtp
sudo apt-get install mailutils
echo $'\nAuthUser=ese205smtp@gmail.com\nAuthPass=ese205rulz\nFromLineOverride=YES\nmailhub=smtp.gmail.com:587\nUseSTARTTLS=YES' | sudo tee -a -i /etc/ssmtp/ssmtp.conf

sudo apt-get install chkconfig
sudo service sendmail stop
sudo chkconfig sendmail off
sudo mkdir /root/.bakup
sudo mv /usr/sbin/sendmail /root/.bakup
sudo ln -s /usr/local/ssmtp/sbin/ssmtp /usr/sbin/sendmail

echo $'#!/bin/bash\nifconfig -a | mail -s "RasPi IP" '"${1}"'@wustl.edu' | sudo tee -i /etc/ip_emailer.sh
sudo chmod +x /etc/ip_emailer.sh

(sudo crontab -l ; echo $'@reboot /etc/ip_emailer.sh') | sudo crontab -