vserver: Add a new script, vserver-hashify-all.
[matthijs/servers/tika.git] / usr / local / bin / vserver-hashify-all
1 #!/bin/sh
2
3 # The dir containing vserver configuration
4 VSERVERS_CONF="/etc/vservers"
5
6 for VDIR in "$VSERVERS_CONF"/*; do
7         NAME=`basename $VDIR`
8         # Check if its a config dir
9         if [ ! -d "$VDIR" ]; then
10                 continue;
11         fi
12         
13         if [ ! -d "$VDIR"/apps/vunify ]; then
14                 echo "Skipping vserver $NAME, hashify is disabled"
15                 continue
16         fi
17
18         echo "Hashifying vserver $NAME..."
19         sudo vserver "$NAME" hashify
20 done
21
22 # Change to /tmp, to minimize the chance for an error to damage the root fs
23 cd /tmp
24 echo "Cleaning up unused hashed files..."
25 for HASH_DIR in "$VSERVERS_CONF"/.defaults/apps/vunify/hash/*; do
26         if [ -L "$HASH_DIR" ]; then
27                 # All symbolic links 
28                 sudo find -H "$HASH_DIR" -type f -links 1 -print0 | sudo xargs --null --no-run-if-empty rm
29         fi
30 done