summaryrefslogtreecommitdiffstats
path: root/find-broken-perl-packages.sh
blob: edc7a55c344e0301fc4b7aadd9ef4163d8c56111 (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
#!/bin/bash

perllibpath="/usr/lib/perl5/vendor_perl/"
perllocallibpath="/usr/lib/perl5/site_perl/"

getmodule() {
	local path=$1
	local file=$2
	echo $file | sed \
		 -e "s|^${path}auto/||" \
		 -e "s|^$path||" \
		 -e 's|/|::|g' \
		 -e 's|.so$||' \
		 -e 's|\(.*\)::.*$|\1|'
}

testmodule() {
	local module=$1
	local prefix=$2
	local output=$(perl -M"$module" -e1 2>&1)
	local ret=$?
	if (($ret != 0)); then
		echo $file >> "$tmpdir/${prefix}raw.txt"
		echo "$module" >> "$tmpdir/${prefix}perl-modules.txt"
	elif grep -q "perl: symbol lookup error:" <<< $output; then
		sed -n 's|perl: symbol lookup error: \(.*\): undefined symbol: .*|\1|p' <<< $output >> "$tmpdir/${prefix}raw.txt"
		echo "$module" >> "$tmpdir/${prefix}perl-modules.txt"
	elif grep -q "Perl API version .* of .* does not match .*" <<< $output; then
		echo $file >> "$tmpdir/${prefix}raw.txt"
		echo "$module" >> "$tmpdir/${prefix}perl-modules.txt"
	elif grep -q "loadable library and perl binaries are mismatched" <<< $output; then
		echo $file >> "$tmpdir/${prefix}raw.txt"
		echo "$module" >> "$tmpdir/${prefix}perl-modules.txt"
	elif grep -q "you may need to install the .* module" <<< $output; then
		echo $file >> "$tmpdir/${prefix}raw.txt"
		sed -n 's|.*you may need to install the \(.*\) module.*|\1|p' <<< $output >> "$tmpdir/${prefix}perl-modules.txt"
	fi
}

tmpdir=$(mktemp -d /tmp/find-broken-perl-package.XXXXXXXX)
touch $tmpdir/{local-,}{raw,perl-modules}.txt

find "$perllibpath" -name "*.so" |
	while read file; do
		module=$(getmodule "$perllibpath" "$file")
		testmodule "$module" ""
	done

if [[ -d $perllocallibpath ]]; then
	find "$perllocallibpath" -name "*.so" |
		while read file; do
			module=$(getmodule "$perllocallibpath" "$file")
			testmodule "$module" "local-"
		done
fi

pacman -Qqo $(<"$tmpdir/raw.txt") | sort -u >"$tmpdir/pacman.txt"
module-to-dist.pl <"$tmpdir/perl-modules.txt" >"$tmpdir/perl-dists.txt"
module-to-dist.pl <"$tmpdir/local-perl-modules.txt" >"$tmpdir/local-perl-dists.txt"

echo "results are in \"$tmpdir\""
echo " - {local-,}raw.txt is a list of files that caused errors"
echo " - pacman.txt is a list of packages that need to be rebuilt. Those are likely AUR packages"
echo " - local-perl-dists.txt is a list of cpan distributions installed to site_perl. Use cpan to rebuild them"
echo ""
echo "additional files:"
echo " - {local-,}perl-modules.txt is a list of cpan modules that caused errors"
echo " - perl-dists.txt is a list of cpan distributions that caused errors"