d2462e94 |
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 |
b7036601 |
8 | kdestroy > /dev/null 2>&1 |
d2462e94 |
9 | unlog |
10 | |
b7036601 |
11 | #VERBOSE=true |
12 | VERBOSE=false |
13 | |
d8d03ff4 |
14 | LOCAL_LOG_DIR=/var/log/apache2/user |
b7036601 |
15 | KEYTAB_DIR=/etc/keytabs/user.daemon |
16 | AFS_USER_DIR=/afs/hcoop.net/user |
19b04bd3 |
17 | ERROR=no |
b7036601 |
18 | |
d8d03ff4 |
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 |
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 |
34 | continue |
35 | fi |
36 | |
ba4e6c35 |
37 | # Skip people who have unreadable log subdirectories |
38 | if test -d "$USER_HOME/.logs" && \ |
39 | ! ls "$USER_HOME/.logs" >/dev/null 2>&1; then |
40 | continue |
41 | fi |
42 | |
c14f6fa4 |
43 | # Skip people who do not have keytabs |
44 | if test ! -f "$KEYTAB_DIR/$USER"; then |
45 | continue |
46 | fi |
47 | |
be8e70a1 |
48 | if test "$VERBOSE" = "true"; then |
b7036601 |
49 | echo |
50 | echo "==============================================================================" |
51 | echo "syncing logs for $USER from $A" |
52 | echo " to $LOG_DEST ..." |
53 | fi |
54 | |
be8e70a1 |
55 | if test ! -d "$LOG_DEST"; then |
8513bbc6 |
56 | # echo "Error: $LOG_DEST does not exist, please make it" |
57 | # ERROR=yes |
58 | # We will assume that people know what they are doing when they |
59 | # delete their ~/.logs/apache directory .... |
60 | continue |
b7036601 |
61 | else |
6d0a0367 |
62 | rm -fr $TMP_DEST |
40cee8c1 |
63 | cp -r $LOG_SRC $TMP_DEST |
d8d03ff4 |
64 | chown -R $USER:nogroup $TMP_DEST |
6b6c39d0 |
65 | chmod -R u=rwX,go=X $TMP_DEST |
b7036601 |
66 | k5start -qtU -f $KEYTAB_DIR/$USER \ |
199f2701 |
67 | -- sudo -u $USER rsync -a $TMP_DEST/ $LOG_DEST/ |
6d0a0367 |
68 | rm -fr $TMP_DEST |
be8e70a1 |
69 | test "$VERBOSE" = "true" && echo " done." |
b7036601 |
70 | fi |
d2462e94 |
71 | done |
19b04bd3 |
72 | |
be8e70a1 |
73 | if test "$ERROR" = "yes"; then |
19b04bd3 |
74 | exit 1 |
75 | else |
76 | exit 0 |
77 | fi |
78 | |