freedombone-usb-canary 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #!/bin/bash
  2. # _____ _ _
  3. # | __|___ ___ ___ _| |___ _____| |_ ___ ___ ___
  4. # | __| _| -_| -_| . | . | | . | . | | -_|
  5. # |__| |_| |___|___|___|___|_|_|_|___|___|_|_|___|
  6. #
  7. # Freedom in the Cloud
  8. #
  9. # Generate an email alert if a USB driver is inserted or removed
  10. #
  11. # License
  12. # =======
  13. #
  14. # Copyright (C) 2017-2018 Bob Mottram <bob@freedombone.net>
  15. #
  16. # This program is free software: you can redistribute it and/or modify
  17. # it under the terms of the GNU Affero General Public License as published by
  18. # the Free Software Foundation, either version 3 of the License, or
  19. # (at your option) any later version.
  20. #
  21. # This program is distributed in the hope that it will be useful,
  22. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. # GNU Affero General Public License for more details.
  25. #
  26. # You should have received a copy of the GNU Affero General Public License
  27. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  28. PROJECT_NAME=freedombone
  29. if [ ! -f /tmp/.upgrading ]; then
  30. UPTIME=$(awk -F '.' '{print $1}' < "/proc/uptime")
  31. if [ "$UPTIME" -gt 240 ]; then
  32. ADMIN_USER=$(grep 'Admin user' /root/${PROJECT_NAME}-completed.txt | awk -F ':' '{print $2}')
  33. MY_EMAIL_ADDRESS=${ADMIN_USER}@$(cat /etc/hostname)
  34. # Which devices have changed?
  35. devices_changed=
  36. if [ -f /tmp/.usb_devices ]; then
  37. lsusb -v > /tmp/.curr_usb_devices
  38. devices_changed=$(diff /tmp/.curr_usb_devices /tmp/.usb_devices)
  39. rm /tmp/.curr_usb_devices
  40. fi
  41. echo -e "USB device connected on ${DEVPATH}\\n\\n${devices_changed}" | mail -s "${PROJECT_NAME} USB canary" "${MY_EMAIL_ADDRESS}"
  42. echo "${ACTION}" > /tmp/usb-canary
  43. echo "${MY_EMAIL_ADDRESS}" >> /tmp/usb-canary
  44. date >> /tmp/usb-canary
  45. fi
  46. fi
  47. lsusb -v > /tmp/.usb_devices