#!/bin/bash

GVACCT="yourname@gmail.com"
GVPASS="yourpassword"
MSGSUBJECT="Little League Alert"

# SMS Message Blaster 2.0 (c) Copyright 2012, Ward Mundy & Associates LLC. All Rights Reserved.
#
#             SMS Message Blaster 2.0 is licensed under the GPL2 license
#
#  For a copy of license, visit http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
#
#  For additional information, contact us: http://pbxinaflash.com/about/comment.php


# ----------- INSTRUCTIONS ------------------------------

# This script sends SMS/Email messsage stored in smsmsg.txt
# to a list of recipients stored in smslist.txt. No error
# checking is provided. pygooglevoice is required to send.
# Insert your Google Voice account credentials above.
# smsmsg.txt should be the plain text message to be sent.
# The plain text message should be limited to 158 characters
# minus the length of your MSGSUBJECT from setting above.
# smslist.txt is the list of recipients for this SMS message.
# Each line of smslist.txt must contain a 10-digit number
# or a valid email address: joeschmo@somedomain.com.
# Optionally, you may add a space after the entry and
# include a name associated with that phone number.
# These name entries are not used in the message blasting.
# They simply make it easier for you to maintain your list.


# ----------- Don't make code changes below here --------

SMSLIST="smslist.txt"
SMSMSG=`cat smsmsg.txt`

index=0

while read -a ACCOUNT
 do
 if [ -n "${ACCOUNT[0]}" ]
 then
  if [ "${ACCOUNT[0]:0:1}" != "#" ]
  then
   NUM2CALL[$index]="${ACCOUNT[0]}"
   index=$(($index+1))
  fi
 fi
 done < $SMSLIST

echo "$index SMS messages to process:"

for SMSNUM in "${NUM2CALL[@]}"
do
 if [[ $SMSNUM =~ ^[0-9]+$ ]]; then
   echo "Sending SMS message to: $SMSNUM"
   gvoice -e $GVACCT -p $GVPASS send_sms $SMSNUM "$MSGSUBJECT: $SMSMSG"
 else
   echo "Sending Email message to: $SMSNUM"
   echo $SMSMSG | mail -s "$MSGSUBJECT" $SMSNUM
 fi
done

