Changes by docelic.
[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
d8d03ff4 14LOCAL_LOG_DIR=/var/log/apache2/user
b7036601 15KEYTAB_DIR=/etc/keytabs/user.daemon
16AFS_USER_DIR=/afs/hcoop.net/user
19b04bd3 17ERROR=no
b7036601 18
d8d03ff4 19# Sanify permissions so that we can safely create tmp directories and
20# run rsync.
21chmod -R u=rwX,g=rX,o=X $LOCAL_LOG_DIR
22
23# Iterate through logs for each user
24for A in $(find $LOCAL_LOG_DIR -mindepth 3 -maxdepth 3 -print); do
b7036601 25 USER=`basename $A`
26 PATHBITS=`echo $USER | head -c 1`/`echo $USER | head -c 2`/$USER
ba4e6c35 27 USER_HOME=$AFS_USER_DIR/$PATHBITS
6d0a0367 28 LOG_SRC=$A/apache/log
ba4e6c35 29 LOG_DEST=$USER_HOME/.logs/apache/
6d0a0367 30 TMP_DEST=$LOG_SRC.tmp
b7036601 31
be8e70a1 32 # Skip deleted or empty log directories
33 if test ! -d "$LOG_SRC" || ! ls "$LOG_SRC"/*/*/*.log >/dev/null 2>&1; then
d5a2aada 34 if test "$VERBOSE" = "true"; then
35 echo "Skipping $USER (deleted or empty log dir $LOG_SRC)"
36 fi
be8e70a1 37 continue
38 fi
39
ba4e6c35 40 # Skip people who have unreadable log subdirectories
41 if test -d "$USER_HOME/.logs" && \
42 ! ls "$USER_HOME/.logs" >/dev/null 2>&1; then
d5a2aada 43 if test "$VERBOSE" = "true"; then
44 echo "Skipping $USER (unreadable log dir $USER_HOME/.logs)"
45 fi
ba4e6c35 46 continue
47 fi
48
c14f6fa4 49 # Skip people who do not have keytabs
50 if test ! -f "$KEYTAB_DIR/$USER"; then
d5a2aada 51 if test "$VERBOSE" = "true"; then
52 echo "Skipping $USER (missing keytab $KEYTAB_DIR/$USER)"
53 fi
c14f6fa4 54 continue
55 fi
56
be8e70a1 57 if test "$VERBOSE" = "true"; then
b7036601 58 echo
59 echo "=============================================================================="
60 echo "syncing logs for $USER from $A"
61 echo " to $LOG_DEST ..."
62 fi
63
be8e70a1 64 if test ! -d "$LOG_DEST"; then
8513bbc6 65# echo "Error: $LOG_DEST does not exist, please make it"
66# ERROR=yes
67# We will assume that people know what they are doing when they
68# delete their ~/.logs/apache directory ....
69 continue
b7036601 70 else
6d0a0367 71 rm -fr $TMP_DEST
40cee8c1 72 cp -r $LOG_SRC $TMP_DEST
d8d03ff4 73 chown -R $USER:nogroup $TMP_DEST
6b6c39d0 74 chmod -R u=rwX,go=X $TMP_DEST
b7036601 75 k5start -qtU -f $KEYTAB_DIR/$USER \
199f2701 76 -- sudo -u $USER rsync -a $TMP_DEST/ $LOG_DEST/
6d0a0367 77 rm -fr $TMP_DEST
be8e70a1 78 test "$VERBOSE" = "true" && echo " done."
b7036601 79 fi
d2462e94 80done
19b04bd3 81
be8e70a1 82if test "$ERROR" = "yes"; then
19b04bd3 83 exit 1
84else
85 exit 0
86fi
87