summaryrefslogtreecommitdiff
path: root/sms.d/phone
blob: a56b74ff38c5e6b6440fb8e794329f776b861fd7 (plain)
  1. #!/bin/sh
  2. # if an error occurs, break immediately
  3. set -e
  4. # Variables from Kannel sms gateway
  5. sms_phone="$SMS_PHONE"
  6. sms_fromphone="$1"
  7. app="$2"
  8. shift 2
  9. msg="$*"
  10. # Settings for the "mail" outgoing email command
  11. export smtp=mail.bitbase.dk
  12. export from=hp@fossasia.org
  13. export sender="$from"
  14. file=/var/www/vhosts/www-sms/sms.localnet/index.txt
  15. mail_subject="[sms] phone $sms_fromphone"
  16. mail_recipients="hp@fossasia.org mb@fossasia.org"
  17. doit() {
  18. # Replace or append to phone list
  19. perl -i -s -p \
  20. -e 's/^(\Q$number\E) .*/$1 $name/ and $seen++;' \
  21. -e '$_ .= "$number $name\n" if (eof and !$seen);' \
  22. -- -number="$sms_fromphone" -name="$msg" "$file"
  23. # Send message (...to stdout if invoked from cmdline)
  24. if [ -n "$sms_phone" ]; then
  25. mail -s "$mail_subject" $mail_recipients
  26. else
  27. cat
  28. fi
  29. }
  30. # Check keyword and break after processing if it matches
  31. case "$app" in
  32. phone)
  33. cat <<EOF | doit
  34. Phone list auto-updated with this entry:
  35. $sms_fromphone $msg
  36. See the complete up-to-date phone list at http://sms.localnet/
  37. EOF
  38. exit 1
  39. ;;
  40. esac