freedombone-rmuser 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. #!/bin/bash
  2. #
  3. # .---. . .
  4. # | | |
  5. # |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
  6. # | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
  7. # ' ' --' --' -' - -' ' ' -' -' -' ' - --'
  8. #
  9. # Freedom in the Cloud
  10. #
  11. # Removes a user from the system
  12. # License
  13. # =======
  14. #
  15. # Copyright (C) 2015-2016 Bob Mottram <bob@robotics.uk.to>
  16. #
  17. # This program is free software: you can redistribute it and/or modify
  18. # it under the terms of the GNU Affero General Public License as published by
  19. # the Free Software Foundation, either version 3 of the License, or
  20. # (at your option) any later version.
  21. #
  22. # This program is distributed in the hope that it will be useful,
  23. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  24. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  25. # GNU Affero General Public License for more details.
  26. #
  27. # You should have received a copy of the GNU Affero General Public License
  28. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  29. PROJECT_NAME='freedombone'
  30. export TEXTDOMAIN=${PROJECT_NAME}-rmuser
  31. export TEXTDOMAINDIR="/usr/share/locale"
  32. MY_USERNAME=$1
  33. COMPLETION_FILE=$HOME/${PROJECT_NAME}-completed.txt
  34. if [ ! $MY_USERNAME ]; then
  35. echo $'Please specify a username to remove'
  36. exit 1
  37. fi
  38. if [[ $MY_USERNAME == 'git' || $MY_USERNAME == 'mirrors' ]]; then
  39. echo $'Cannot remove reserved users'
  40. exit 2
  41. fi
  42. if [ ! -d /home/$MY_USERNAME ]; then
  43. echo $"Home directory does not exist for $MY_USERNAME"
  44. exit 3
  45. fi
  46. if [ ! -f $COMPLETION_FILE ]; then
  47. echo $"$COMPLETION_FILE not found"
  48. exit 4
  49. fi
  50. if ! grep -q "Admin user" $COMPLETION_FILE; then
  51. echo $"No admin user specified in $COMPLETION_FILE"
  52. exit 5
  53. fi
  54. ADMIN_USERNAME=$(cat $COMPLETION_FILE | grep "Admin user" | awk -F ':' '{print $2}')
  55. if [ ! $ADMIN_USERNAME ]; then
  56. echo $"No admin username specified in $COMPLETION_FILE"
  57. exit 6
  58. fi
  59. if [[ $MY_USERNAME == $ADMIN_USERNAME ]]; then
  60. echo $"The administrator user cannot be removed"
  61. exit 7
  62. fi
  63. echo $'>>> REMOVE USER <<<'
  64. read -p $"Do you really wish to remove the user '$MY_USERNAME' (y/n) ?" yn
  65. if [[ $yn != 'y' && $yn != 'Y' && $yn != 'yes' && $yn != 'Yes' && $yn != 'YES' ]]; then
  66. echo $"User $MY_USERNAME was not removed"
  67. exit 8
  68. fi
  69. if grep -q "install_xmpp" $COMPLETION_FILE; then
  70. ${PROJECT_NAME}-rmxmpp -e "$MY_USERNAME@$HOSTNAME"
  71. fi
  72. if grep -q "Blog domain" $COMPLETION_FILE; then
  73. FULLBLOG_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Blog domain" | awk -F ':' '{print $2}')
  74. if [ -f /var/www/$FULLBLOG_DOMAIN_NAME/htdocs/config/users/$MY_USERNAME.ini ]; then
  75. rm /var/www/$FULLBLOG_DOMAIN_NAME/htdocs/config/users/$MY_USERNAME.ini
  76. fi
  77. fi
  78. if grep -q "install_sip" $COMPLETION_FILE; then
  79. ${PROJECT_NAME}-rmsipuser $MY_USERNAME
  80. fi
  81. if grep -q "GNU Social domain" $COMPLETION_FILE; then
  82. MICROBLOG_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "GNU Social domain" | awk -F ':' '{print $2}')
  83. if [ -d /var/www/$MICROBLOG_DOMAIN_NAME ]; then
  84. cd /var/www/$MICROBLOG_DOMAIN_NAME/htdocs
  85. php scripts/deleteprofile.php -n $MY_USERNAME -y
  86. echo $'Removed GNU Social user'
  87. fi
  88. fi
  89. if [ -f /etc/nginx/.htpasswd ]; then
  90. if grep "${MY_USERNAME}:" /etc/nginx/.htpasswd; then
  91. htpasswd -D /etc/nginx/.htpasswd $MY_USERNAME
  92. fi
  93. fi
  94. # remove user from SIP TURN/STUN
  95. if [ -d /etc/turnserver ]; then
  96. sed -i "/${MY_USERNAME}:/d" /etc/turnserver/turnusers.txt
  97. fi
  98. # remove gpg keys
  99. if [ -d /home/$MY_USERNAME/.gnupg ]; then
  100. shred -zu /home/$MY_USERNAME/.gnupg/*
  101. fi
  102. # remove ssh keys
  103. if [ -d /home/$MY_USERNAME/.ssh ]; then
  104. shred -zu /home/$MY_USERNAME/.ssh/*
  105. fi
  106. # remove tox indentity
  107. if [ -d /home/$MY_USERNAME/.config/tox ]; then
  108. if [ -d /home/$MY_USERNAME/.config/tox/chatlogs ]; then
  109. shred -zu /home/$MY_USERNAME/.config/tox/chatlogs/*
  110. rm -rf /home/$MY_USERNAME/.config/tox/chatlogs
  111. fi
  112. shred -zu /home/$MY_USERNAME/.config/tox/*
  113. fi
  114. userdel -r $MY_USERNAME
  115. if [ -d /home/$MY_USERNAME ]; then
  116. rm -rf /home/$MY_USERNAME
  117. fi
  118. echo $"User $MY_USERNAME was removed"
  119. exit 0