freedombone-utils-gpg 2.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #!/bin/bash
  2. #
  3. # .---. . .
  4. # | | |
  5. # |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
  6. # | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
  7. # ' ' --' --' -' - -' ' ' -' -' -' ' - --'
  8. #
  9. # Freedom in the Cloud
  10. #
  11. # gpg functions
  12. #
  13. # License
  14. # =======
  15. #
  16. # Copyright (C) 2016 Bob Mottram <bob@freedombone.net>
  17. #
  18. # This program is free software: you can redistribute it and/or modify
  19. # it under the terms of the GNU Affero General Public License as published by
  20. # the Free Software Foundation, either version 3 of the License, or
  21. # (at your option) any later version.
  22. #
  23. # This program is distributed in the hope that it will be useful,
  24. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  25. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  26. # GNU Affero General Public License for more details.
  27. #
  28. # You should have received a copy of the GNU Affero General Public License
  29. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  30. function gpg_pubkey_from_email {
  31. key_owner_username=$1
  32. key_email_address=$2
  33. key_id=
  34. if [[ $key_owner_username != "root" ]]; then
  35. key_id=$(su -c "gpg --list-keys $key_email_address | grep 'pub '" - $key_owner_username | head -n 1 | awk -F ' ' '{print $2}' | awk -F '/' '{print $2}')
  36. else
  37. key_id=$(gpg --list-keys $key_email_address | grep 'pub ' | head -n 1 | awk -F ' ' '{print $2}' | awk -F '/' '{print $2}')
  38. fi
  39. echo $key_id
  40. }
  41. function enable_email_encryption_at_rest {
  42. for d in /home/*/ ; do
  43. USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
  44. if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
  45. if grep '#| /usr/bin/gpgit.pl' /home/$USERNAME/.procmailrc; then
  46. sed -i 's@#| /usr/bin/gpgit.pl@| /usr/bin/gpgit.pl@g' /home/$USERNAME/.procmailrc
  47. sed -i 's|#:0 f|:0 f|g' /home/$USERNAME/.procmailrc
  48. fi
  49. fi
  50. done
  51. if grep '#| /usr/bin/gpgit.pl' /etc/skel/.procmailrc; then
  52. sed -i 's@#| /usr/bin/gpgit.pl@| /usr/bin/gpgit.pl@g' /etc/skel/.procmailrc
  53. sed -i 's|#:0 f|:0 f|g' /etc/skel/.procmailrc
  54. fi
  55. }
  56. function disable_email_encryption_at_rest {
  57. for d in /home/*/ ; do
  58. USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
  59. if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
  60. if ! grep '#| /usr/bin/gpgit.pl' /home/$USERNAME/.procmailrc; then
  61. sed -i 's@| /usr/bin/gpgit.pl@#| /usr/bin/gpgit.pl@g' /home/$USERNAME/.procmailrc
  62. sed -i 's|:0 f|#:0 f|g' /home/$USERNAME/.procmailrc
  63. fi
  64. fi
  65. done
  66. if ! grep '#| /usr/bin/gpgit.pl' /etc/skel/.procmailrc; then
  67. sed -i 's@| /usr/bin/gpgit.pl@#| /usr/bin/gpgit.pl@g' /etc/skel/.procmailrc
  68. sed -i 's|:0 f|#:0 f|g' /etc/skel/.procmailrc
  69. fi
  70. }
  71. # NOTE: deliberately no exit 0