apache-sync-logs: Skip people who do not have keytabs
[hcoop/scripts.git] / apache-sync-logs
1 #!/bin/bash
2
3 # invoke this as root on mire
4
5 exec 2>&1
6
7 # drop any tokens; use only users' cgi tokens
8 kdestroy > /dev/null 2>&1
9 unlog
10
11 #VERBOSE=true
12 VERBOSE=false
13
14 LOCAL_LOG_DIR=/var/log/apache2/user
15 KEYTAB_DIR=/etc/keytabs/user.daemon
16 AFS_USER_DIR=/afs/hcoop.net/user
17 ERROR=no
18
19 # Sanify permissions so that we can safely create tmp directories and
20 # run rsync.
21 chmod -R u=rwX,g=rX,o=X $LOCAL_LOG_DIR
22
23 # Iterate through logs for each user
24 for A in $(find $LOCAL_LOG_DIR -mindepth 3 -maxdepth 3 -print); do
25 USER=`basename $A`
26 PATHBITS=`echo $USER | head -c 1`/`echo $USER | head -c 2`/$USER
27 LOG_SRC=$A/apache/log
28 LOG_DEST=$AFS_USER_DIR/$PATHBITS/.logs/apache/
29 TMP_DEST=$LOG_SRC.tmp
30
31 # Skip deleted or empty log directories
32 if test ! -d "$LOG_SRC" || ! ls "$LOG_SRC"/*/*/*.log >/dev/null 2>&1; then
33 continue
34 fi
35
36 # Skip people who do not have keytabs
37 if test ! -f "$KEYTAB_DIR/$USER"; then
38 continue
39 fi
40
41 if test "$VERBOSE" = "true"; then
42 echo
43 echo "=============================================================================="
44 echo "syncing logs for $USER from $A"
45 echo " to $LOG_DEST ..."
46 fi
47
48 if test ! -d "$LOG_DEST"; then
49 echo "Error: $LOG_DEST does not exist, please make it"
50 ERROR=yes
51 else
52 rm -fr $TMP_DEST
53 cp -r $LOG_SRC $TMP_DEST
54 chown -R $USER:nogroup $TMP_DEST
55 chmod -R u=rwX,go=X $TMP_DEST
56 k5start -qtU -f $KEYTAB_DIR/$USER \
57 -- su $USER -c "rsync -a $TMP_DEST/ $LOG_DEST/"
58 rm -fr $TMP_DEST
59 test "$VERBOSE" = "true" && echo " done."
60 fi
61 done
62
63 if test "$ERROR" = "yes"; then
64 exit 1
65 else
66 exit 0
67 fi
68