summaryrefslogtreecommitdiff
path: root/moz-normalize-PKGBUILD
blob: 54f15a7e314e3ae11cbb4a51c4a7e7ced5559551 (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
#!/bin/bash

tempdir="$(mktemp -d --tmpdir mozilla-normalize.XXXXXXXXXXX)"

cat > "$tempdir/PKGBUILD"
for var in {make,check,}depends; do
	# extract, normalize the data 
	{
		sed -nr "
                    /^$var=\(/,/\)/{ # select the variable array
                        s/.*\(/  /   # remove the opening 'var=(' bit
                        s/\).*//     # remove the trailing ')' bit
                        s/\s+/\n  /g # delimit array elements with '\n  '
                        /./p         # print array elements
                    }" \
			| sed '/^\s*$/d' \
			| sort -u
	} < "$tempdir/PKGBUILD" > "$tempdir/$var"
	# remove it from the file
	sed -i -e "/^$var=(/i @$var@" -e "/^$var=/,/)/d" "$tempdir/PKGBUILD"
	# re-insert it into the file
	sed -i \
		-e "/^@$var@/a$var=(" \
		-e "/^@$var@/r$tempdir/$var" \
		-e "/^@$var@/a)" \
		-e "/^@$var@/d" \
		"$tempdir/PKGBUILD"	
done

# clean up whitespace
sed -ri 's/\s+$//' "$tempdir/PKGBUILD"

cat "$tempdir/PKGBUILD"
rm -rf "$tempdir"