summaryrefslogtreecommitdiff
path: root/qa/src/mkpermslist
blob: 4738eec66c465471c0d13d2ff815832b213bdb6f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
#!/bin/sh
#
# Build a new QA permslist file by descend the source tree finding
# install lines for files with non-default mode (not 0644 for files or
# 0755 for directories) and/or non-default user and group (not root)
#

. /etc/pcp.env

tmp=/var/tmp/$$
sts=0
TOP=../..
trap "rm -f $tmp.*; exit \$sts" 0 1 2 3 15

cat <<End-of-File >$tmp.new
# Control file of targets from the PCP source code that are installed
# with non-default mode and/or owner and/or group permissions.
# Generate by qa/src/mkpermslist on `date`
#
End-of-File

rm -f tmp.debug.*
( cd $TOP ; find GNU* src -type f -name "GNU*" ) \
| while read makefile
do
    rm -f $tmp.raw
    grep -i 'INSTALL' $TOP/$makefile >$tmp.tmp
    #debug# cat $tmp.tmp >>tmp.debug.0
    # check for -m xxx for xxx not 644 or 755
    #
    sed -n <$tmp.tmp >>$tmp.raw \
	-e '/-m[ 	][ 	]*/{
/-m[ 	][ 	]*644/d
/-m[ 	][ 	]*755/d
s/\(-[a-z]\)[ 	][ 	]*/\1/g
p
}'
    # check for -g or -o
    #
    sed -n <$tmp.tmp >>$tmp.raw \
	-e '/-[og][ 	][ 	]*/{
/-[og][ 	][ 	]*root/d
s/\(-[a-z]\)[ 	][ 	]*/\1/g
p
}'
    # expand PCP env vars we expect to find
    #
    sed <$tmp.raw >$tmp.tmp \
	-e 's/$(INSTALL)//' \
	-e "s@^@$makefile@"
    mv $tmp.tmp $tmp.raw

    # special cases ... these are makefile lines that do not match
    # the generic format and need special handling on a per makefile
    # basis
    #
    case "$makefile"
    in
	GNUmakefile)
	    # this INSTALL line is optional depending on packaging
	    # $(INSTALL) -m 775 -g $(PCP_GROUP) -d $(PCP_RUN_DIR)
	    #
	    sed -e '/PCP_RUN_DIR)$/s/$/|optional/' <$tmp.raw >$tmp.tmp
	    diff $tmp.raw $tmp.tmp >tmp.debug.2
	    mv $tmp.tmp $tmp.raw
	    ;;

	src/libpcp_pmcd/src/GNUmakefile)
	    # this INSTALL line is optional depending on platform and
	    # build options
	    # $(INSTALL) -m 444 pmcd.stp $(PCP_SHARE_DIR)/../systemtap/tapset/pmcd.stp
	    sed -e '/pmcd.stp$/s/$/|optional/' <$tmp.raw >$tmp.tmp
	    mv $tmp.tmp $tmp.raw
	    ;;

	src/perl/GNUmakefile)
	    # this INSTALL line is safe because mode is 0644 or 0755
	    #	if [ -x $$src ] ; then mode=0755; else mode=0644; fi; \
	    #	$(INSTALL) -m $$mode $$src $$dn/$$bn || exit 1; \
	    #
	    sed -e '/\$\$mode/d' <$tmp.raw >$tmp.tmp
	    mv $tmp.tmp $tmp.raw
	    ;;

	src/pmie/GNUmakefile)
	    # this INSTALL line is optional because there if conditional
	    # gmake control around it
	    #	$(INSTALL) -m 1777 -d $(PCP_TMP_DIR)/pmie
	    sed -e '/PCP_TMP_DIR)\/pmie$/s/$/|optional/' <$tmp.raw >$tmp.tmp
	    mv $tmp.tmp $tmp.raw
	    ;;

	src/pmlogger/GNUmakefile)
	    # this INSTALL line is optional because there if conditional
	    # gmake control around it
	    #	$(INSTALL) -m 1777 -d $(PCP_TMP_DIR)/pmlogger
	    sed -e '/PCP_TMP_DIR)\/pmlogger$/s/$/|optional/' <$tmp.raw >$tmp.tmp
	    mv $tmp.tmp $tmp.raw
	    ;;

	src/pmdas/bash/GNUmakefile)
	    # this INSTALL line is optional because there if conditional
	    # gmake control around it
	    # $(INSTALL) -m 1777 -d $(PCP_TMP_DIR)/pmdabash
	    #
	    sed -e '/PCP_TMP_DIR)\/pmdabash$/s/$/|optional/' <$tmp.raw >$tmp.tmp
	    mv $tmp.tmp $tmp.raw
	    ;;

	src/pmdas/mmv/GNUmakefile)
	    # this INSTALL line is optional because there if conditional
	    # gmake control around it
	    # $(INSTALL) -m 1777 -d $(PCP_TMP_DIR)/mmv
	    #
	    sed -e '/PCP_TMP_DIR)\/mmv$/s/$/|optional/' <$tmp.raw >$tmp.tmp
	    mv $tmp.tmp $tmp.raw
	    ;;

	src/pmwebapi/GNUmakefile)
	    # all the INSTALL lines here are conditional, including this one
	    # $(INSTALL) -m 775 -o $(PCP_USER) -g $(PCP_GROUP) -d $(PCP_LOG_DIR)/pmwebd
	    sed -e '/PCP_LOG_DIR)\/pmwebd$/s/$/|optional/' <$tmp.raw >$tmp.tmp
	    mv $tmp.tmp $tmp.raw
	    ;;

    esac

    # any left over $'s are bad ...
    #

    grep '\$' $tmp.raw | grep -v '\$(PCP_' >$tmp.tmp
    if [ -s $tmp.tmp ]
    then
	cat >&2 $tmp.tmp
	echo >&2 "Need fixup for shell variables or makefile macros in $makefile"
	rm -f $tmp.new
	break
    fi

    # translate into a generic format
    # makefile|mode|owner|group|target-file-name|optional
    #
    awk <$tmp.raw '
    { mode = ""; group = "root"; owner = "root"; list = ""
      for (i = 2; i <= NF; i++) {
	if ($i ~ /-m/) mode = substr($i, 3, length($i));
	else if ($i ~ /-g/) group = substr($i, 3, length($i));
	else if ($i ~ /-o/) owner = substr($i, 3, length($i));
	else if ($i ~ /-d/) {
	    dir = ""
	    list = substr($i, 3, length($i));
	}
	else if (i == NF) {
	    dir = $i
	}
	else if (list == "") {
	    list = $i
	}
	else {
	    list = list " " $i
	}
      }
      if (dir != "" && list == "") {
	print $1 "|" mode "|" owner "|" group "|" dir
      }
      else if (dir == "" && list != "") {
	print $1 "|" mode "|" owner "|" group "|" list
      }
      else {
	n = split(list, files)
	if (n == 1) {
	    print $1 "|" mode "|" owner "|" group "|" dir
	}
	else {
	    for (i = 0; i < n; i++)
		print $1 "|" mode "|" owner "|" group "|" dir "/" files[i]
	}
      }

    }'

done \
| sort | uniq >$tmp.new

if [ -s $tmp.new ]
then
    :
else
    sts=1
    exit
fi

if [ -f permslist ]
then
    sed -e '/^#/d' <permslist >$tmp.old.strip
    sed -e '/^#/d' <$tmp.new >$tmp.new.strip
    if cmp $tmp.old.strip $tmp.new.strip >/dev/null
    then
	echo "No changes."
    else
	diff -u permslist $tmp.new
	mv permslist permslist.old
	cp $tmp.new permslist
	echo "Updated (previous permslist saved as permslist.old)."
    fi
else
    echo "Created permslist."
    cp $tmp.new permslist
fi