]> andersk Git - moira.git/blob - gen/acl.sh
sync to version running on moira
[moira.git] / gen / acl.sh
1 #!/bin/sh
2 # $Id$
3
4 # The following exit codes are defined and MUST BE CONSISTENT with the
5 # error codes the library uses:
6 MR_MISSINGFILE=47836473
7 MR_MKCRED=47836474
8 MR_TARERR=47836476
9
10 status=0
11
12 PATH=/bin:/usr/bin
13 TARFILE=/var/tmp/acl.out
14
15 # Alert if the tar file does not exist
16 test -r $TARFILE || exit $MR_MISSINGFILE
17
18 # Make a temporary directory to unpack the tar file into
19 mkdir /var/tmp/acltmp || exit $MR_MKCRED
20 cd /var/tmp/acltmp || exit $MR_MKCRED
21 tar xpf $TARFILE || exit $MR_TARERR
22
23 # Copy over each file which is new or has changed
24 for file in `find . -type f -print | sed -e 's/^\.//'`; do
25     if [ $file = /etc/passwd -o $file = /etc/passwd.local ]; then
26         # Make sure that there is a head file, or that the generated
27         # file contains an entry for root.
28         if [ ! -f $file.head ]; then
29             if egrep -s ^root: .$file; then
30                 :
31             else
32                 status=MR_MISSINGFILE
33                 break
34             fi
35         fi
36     elif [ $file = /etc/group -o $file = /etc/group.local ]; then
37         # Make sure that there is a head file, or that the generated
38         # file contains a group with gid 0.
39         if [ ! -f $file.head ]; then
40             if awk -F: '$3 == "0" { exit 1; }'; then
41                 status=MR_MISSINGFILE
42                 break
43             fi
44         fi
45     fi
46
47     if [ -f $file.head ]; then
48         head=$file.head
49     else
50         head=
51     fi
52     if [ -f $file.tail ]; then
53         tail=$file.tail
54     else
55         tail=
56     fi
57
58     # Note that "$file" is a full pathname, and so ".$file" means
59     # the copy of file in the directory hierarchy rooted at ".",
60     # not "$file with a . prepended to its basename".
61
62     # Create a tmp file with the correct owner and mode
63     if [ -f $file ]; then
64         cp -p $file $file.$$
65     else
66         cp -p .$file $file.$$
67     fi
68
69     # Now dump the correct data into the tmp file without changing its
70     # owner and mode
71     cat $head .$file $tail > $file.$$
72
73     if cmp -s $file.$$ $file; then
74         rm -f $file.$$
75     else
76         mv $file.$$ $file
77     fi
78 done
79
80 # cleanup
81 cd /
82 rm -rf /var/tmp/acltmp
83 test -f $TARFILE && rm -f $TARFILE
84 test -f $0 && rm -f $0
85
86 exit $status
This page took 0.043933 seconds and 5 git commands to generate.