delete_status_network.sh 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #!/bin/bash
  2. # live fast! die young!
  3. set -e
  4. source /etc/statusnet/setup.cfg || (echo "Failed to read /etc/statusnet/setup.cfg"; exit -1)
  5. export nickname=$1
  6. if [ "x" == "x$nickname" ]
  7. then
  8. echo "Usage: delete_status_network.sh <site-nickname>"
  9. exit 1
  10. fi
  11. export database=$nickname$DBBASE
  12. # Pull the status_network record so we know which DB server to drop from...
  13. TARGET_DBHOST=`mysql -h $DBHOST -u $ADMIN --password=$ADMINPASS $SITEDB --batch --skip-column-names -e \
  14. "select dbhost from status_network where nickname='$nickname'"`
  15. if [ "x" == "x$TARGET_DBHOST" ]
  16. then
  17. echo "Aborting: Could not find status_network record for site $nickname"
  18. exit 1
  19. fi
  20. # Drop the database
  21. echo "Dropping $database from $TARGET_DBHOST..."
  22. mysqladmin -h $TARGET_DBHOST -u $ADMIN --password=$ADMINPASS -f drop $database || exit 1
  23. # Remove the status_network entry
  24. echo "Removing status_network entry for $nickname..."
  25. mysql -h $DBHOST -u $ADMIN --password=$ADMINPASS $SITEDB -e \
  26. "delete from status_network where nickname = '$nickname'" || exit 1
  27. # Remove uploaded file areas
  28. for top in $AVATARBASE $FILEBASE $BACKGROUNDBASE; do
  29. if [ "x" == "x$top" ]
  30. then
  31. echo "Skipping deletion due to broken config"
  32. else
  33. echo "Deleting $top/$nickname"
  34. rm -Rf "$top/$nickname"
  35. fi
  36. done
  37. echo "Done."