1 | #!/bin/sh |
---|
2 | # $Id: local-lockers.sh,v 1.3 2002-12-03 00:10:15 rbasch Exp $ |
---|
3 | |
---|
4 | # local-lockers - Bring lockers local using athlsync |
---|
5 | |
---|
6 | conf=/etc/athena/local-lockers.conf |
---|
7 | localdir=/var/athena/local |
---|
8 | validdir=/var/athena/local-validated |
---|
9 | margin=524288 # Keep 512MB free |
---|
10 | |
---|
11 | umask 022 |
---|
12 | PATH=/bin/athena:/usr/athena/etc:$PATH |
---|
13 | |
---|
14 | if [ ! -r $conf ]; then |
---|
15 | exit |
---|
16 | fi |
---|
17 | |
---|
18 | mkdir -p $localdir $validdir |
---|
19 | cflist= |
---|
20 | for l in `awk '/^[^#]/ { print; }' $conf`; do |
---|
21 | case $l in |
---|
22 | */*) |
---|
23 | # "lockername/symname" means to read the symlink "symname" in the locker |
---|
24 | # "lockername" to find the locker to copy. This "indirect locker" |
---|
25 | # case is for IS-maintained third-party software lockers. |
---|
26 | il=`dirname $l` |
---|
27 | sym=`basename $l` |
---|
28 | path=`hesinfo "$il" filsys | sort -nk 5 | awk '/^AFS/ { print $2; exit; }'` |
---|
29 | if [ ! -n "$path" ] || [ ! -d "$path" ] || [ ! -h "$path/$sym" ]; then |
---|
30 | continue |
---|
31 | fi |
---|
32 | l=`ls -l "$path/$sym" | sed -e 's/.* -> //'` |
---|
33 | ;; |
---|
34 | esac |
---|
35 | |
---|
36 | # Keep a list of configured locker names so we don't nuke them later. |
---|
37 | cflist="$cflist $l " |
---|
38 | |
---|
39 | path=`hesinfo "$l" filsys | sort -nk 5 | awk '/^AFS/ { print $2; exit; }'` |
---|
40 | localpath=$localdir/$l |
---|
41 | validpath=$validdir/$l |
---|
42 | if [ -n "$path" ] && [ -d "$path" ]; then |
---|
43 | space=`athlsync -s "$path" "$localpath"` |
---|
44 | freespace=`df -k $localdir | awk '{ av = $(NF-2); } END { print av; }'` |
---|
45 | if [ -n "$space" ] && [ "$freespace" -ge `expr "$space" + $margin` ]; then |
---|
46 | # Sync and validate the local copy. |
---|
47 | if athlsync "$path" "$localpath"; then |
---|
48 | rm -f "$validpath" |
---|
49 | ln -s "$localpath" "$validpath" |
---|
50 | fi |
---|
51 | else |
---|
52 | # Not enough room. De-validate the local copy if there is one, |
---|
53 | # unless there were no changes to sync. |
---|
54 | [ "$space" = 0 ] || rm -f "$validpath" |
---|
55 | fi |
---|
56 | fi |
---|
57 | done |
---|
58 | |
---|
59 | for d in `ls $localdir` ; do |
---|
60 | case $cflist in |
---|
61 | *" $d "*) |
---|
62 | # This is one of the lockers we wanted local, so keep it. |
---|
63 | continue |
---|
64 | ;; |
---|
65 | esac |
---|
66 | if [ ! -h "/var/athena/attachtab/locker/$d" ]; then |
---|
67 | # Not attached and no longer wanted local; nuke it. |
---|
68 | rm -rf "$validdir/$d" "$localdir/$d" |
---|
69 | fi |
---|
70 | done |
---|