create-user: Add sanity check in case shared spam dir is really FUBAR
[clinton/scripts.git] / apache-sync-logs
CommitLineData
d2462e94 1#!/bin/bash
2
3# invoke this as root on mire
4
5exec 2>&1
6
7# drop any tokens; use only users' cgi tokens
b7036601 8kdestroy > /dev/null 2>&1
d2462e94 9unlog
10
b7036601 11#VERBOSE=true
12VERBOSE=false
13
14LOCAL_LOG_DIR=/var/log/apache2
15KEYTAB_DIR=/etc/keytabs/user.daemon
16AFS_USER_DIR=/afs/hcoop.net/user
19b04bd3 17ERROR=no
b7036601 18
19for A in $(find $LOCAL_LOG_DIR/user -mindepth 3 -maxdepth 3 -print); do
20 USER=`basename $A`
21 PATHBITS=`echo $USER | head -c 1`/`echo $USER | head -c 2`/$USER
6d0a0367 22 LOG_SRC=$A/apache/log
b7036601 23 LOG_DEST=$AFS_USER_DIR/$PATHBITS/logs/apache/
6d0a0367 24 TMP_DEST=$LOG_SRC.tmp
b7036601 25
26 if [ "$VERBOSE" = "true" ]; then
27 echo
28 echo "=============================================================================="
29 echo "syncing logs for $USER from $A"
30 echo " to $LOG_DEST ..."
31 fi
32
b7036601 33 if [ ! -d "$LOG_DEST" ]; then
34 echo "Error: $LOG_DEST does not exist, please make it"
19b04bd3 35 ERROR=yes
b7036601 36 else
6d0a0367 37 rm -fr $TMP_DEST
38 cp -a $LOG_SRC $TMP_DEST
39 chown -R $USER $TMP_DEST
6b6c39d0 40 chmod -R u=rwX,go=X $TMP_DEST
b7036601 41 k5start -qtU -f $KEYTAB_DIR/$USER \
6d0a0367 42 -- su $USER -c "rsync -a $TMP_DEST/ $LOG_DEST/"
43 rm -fr $TMP_DEST
b7036601 44 [ "$VERBOSE" = "true" ] && echo " done."
45 fi
d2462e94 46done
19b04bd3 47
48if [ "$ERROR" = "yes" ]; then
49 exit 1
50else
51 exit 0
52fi
53