Set +x on create-user-database script
[clinton/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 USER_HOME=$AFS_USER_DIR/$PATHBITS
28 LOG_SRC=$A/apache/log
29 LOG_DEST=$USER_HOME/.logs/apache/
30 TMP_DEST=$LOG_SRC.tmp
31
32 # Skip deleted or empty log directories
33 if test ! -d "$LOG_SRC" || ! ls "$LOG_SRC"/*/*/*.log >/dev/null 2>&1; then
34 if test "$VERBOSE" = "true"; then
35 echo "Skipping $USER (deleted or empty log dir $LOG_SRC)"
36 fi
37 continue
38 fi
39
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
43 if test "$VERBOSE" = "true"; then
44 echo "Skipping $USER (unreadable log dir $USER_HOME/.logs)"
45 fi
46 continue
47 fi
48
49 # Skip people who do not have keytabs
50 if test ! -f "$KEYTAB_DIR/$USER"; then
51 if test "$VERBOSE" = "true"; then
52 echo "Skipping $USER (missing keytab $KEYTAB_DIR/$USER)"
53 fi
54 continue
55 fi
56
57 if test "$VERBOSE" = "true"; then
58 echo
59 echo "=============================================================================="
60 echo "syncing logs for $USER from $A"
61 echo " to $LOG_DEST ..."
62 fi
63
64 if test ! -d "$LOG_DEST"; then
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 if test "$VERBOSE" = "true"; then
70 echo "Skipping $USER (no $LOG_DEST directory)"
71 fi
72 continue
73 else
74 rm -fr $TMP_DEST
75 cp -r $LOG_SRC $TMP_DEST
76 chown -R $USER:nogroup $TMP_DEST
77 chmod -R u=rwX,go=X $TMP_DEST
78 k5start -qtU -f $KEYTAB_DIR/$USER \
79 -- sudo -u $USER rsync -a $TMP_DEST/ $LOG_DEST/
80 rm -fr $TMP_DEST
81 test "$VERBOSE" = "true" && echo " done."
82 fi
83 done
84
85 if test "$ERROR" = "yes"; then
86 exit 1
87 else
88 exit 0
89 fi
90