summaryrefslogtreecommitdiff
path: root/scripts/delete_status_network.sh
blob: 4e91cd639071af760f2d4df7c88a56034d8cb602 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/bin/bash

# live fast! die young!

set -e

source /etc/statusnet/setup.cfg || (echo "Failed to read /etc/statusnet/setup.cfg"; exit -1)

export nickname=$1
if [ "x" == "x$nickname" ]
then
    echo "Usage: delete_status_network.sh <site-nickname>"
    exit 1
fi

export database=$nickname$DBBASE

# Pull the status_network record so we know which DB server to drop from...
TARGET_DBHOST=`mysql -h $DBHOST -u $ADMIN --password=$ADMINPASS $SITEDB --batch --skip-column-names -e \
  "select dbhost from status_network where nickname='$nickname'"`

if [ "x" == "x$TARGET_DBHOST" ]
then
    echo "Aborting: Could not find status_network record for site $nickname"
    exit 1
fi

# Drop the database
echo "Dropping $database from $TARGET_DBHOST..."
mysqladmin -h $TARGET_DBHOST -u $ADMIN --password=$ADMINPASS -f drop $database || exit 1

# Remove the status_network entry
echo "Removing status_network entry for $nickname..."
mysql -h $DBHOST -u $ADMIN --password=$ADMINPASS $SITEDB -e \
    "delete from status_network where nickname = '$nickname'" || exit 1

# Remove uploaded file areas
for top in $AVATARBASE $FILEBASE $BACKGROUNDBASE; do
    if [ "x" == "x$top" ]
    then
        echo "Skipping deletion due to broken config"
    else
        echo "Deleting $top/$nickname"
        rm -Rf "$top/$nickname"
    fi
done

echo "Done."