File: checkPerlOptionals.bash

package info (click to toggle)
haci 0.97c-2
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 1,816 kB
  • sloc: perl: 19,106; sh: 190; makefile: 8
file content (111 lines) | stat: -rwxr-xr-x 2,854 bytes parent folder | download | duplicates (2)
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
#!/usr/bin/env bash
#
# Checking for optional Perl module dependencies
# It can try to install them automatically on demand

modules="Cache::FastMmap Cache::FileCache DNS::ZoneParse IO::Socket::INET6 Math::BigInt::GMP Net::DNS Net::Ping Pod::WSDL SOAP::Transport::HTTP SQL::Translator#0.09000 SQL::Translator::Diff Text::CSV_XS Apache::DBI"
aptget=`which apt-get 2>/dev/null`
yast2=`which yast2 2>/dev/null`
zypper=`which zypper 2>/dev/null`
cpan=`which cpan 2>/dev/null`

checkModules() {
	index=0
	echo "Checking if all optional Perl dependencies are available..."
	for modt in  $modules
	do
		if echo $modt | grep -q '#'; then
			mod=`echo $modt|cut -d '#' -f 1`;
			ver=`echo $modt|cut -d '#' -f 2`;
		else 
			mod=$modt
			ver=''
		fi
		echo -n "$mod"
		if echo $modt | grep -q '#'; then echo -n " v$ver"; fi
		echo -n ': '

		if perl -e "use $mod $ver" 2>/dev/null; 
		then 
			echo "OK"; 
		else 
			echo "NO"; 
			failed[$index]=$mod
			((index++))
		fi
	done
	if [ "$index" -eq "0" ]
	then
		return 0
	else
		return 1
	fi
}

showMissing() {
	echo; echo "The following are missing:"
	modIndex=0
	while [ ${modIndex} -lt ${#failed[@]} ]
	do
		echo "${failed[$modIndex]}"
		modIndex=$((${modIndex}+1))
	done
}

checkModules
if [ "$?" -eq "0" ]; then echo; echo "Everything fine. All Dependencies are installed."; exit 0; fi

showMissing

if ( test -f /etc/debian_version && [ "$aptget" != "" ] && test -x $aptget); then bDebian=1; else bDebian=0; fi
if ( [ "$cpan" != "" ] && test -x $cpan); then bCpan=1; else bCpan=0; fi
if ( [ "$yast2" != "" ] && test -x $yast2); then bYast2=1; else bYast2=0; fi
if ( [ "$zypper" != "" ] && test -x $zypper); then bZypper=1; else bZypper=0; fi

if [ "$bDebian" -eq 0 ] && [ "$bCpan" -eq 0 ]
then
	echo; echo "Don't know how to install these modules. Please do it by hand"
	exit 0;
fi

echo; echo -n "Should I try to install them automatically? [y|N] "
read res
if [ "$res" != "y" ] && [ "$res" != "Y" ]; then exit 0; fi;

if [ "$bCpan" -eq 1 ];
then
	echo; echo -n "Should I use CPAN? Please note that you have to have a C-Compiler like gcc installed. [Y|n] "
	read res
	if [ "$res" != "y" ] && [ "$res" != "Y" ]  && [ "$res" != "" ]; then bCpan=0; fi;
fi

modIndex=0
while [ ${modIndex} -lt ${#failed[@]} ]
do
	echo "${failed[$modIndex]}"
	if [ "$bCpan" -eq 1 ];
	then
		$cpan ${failed[$modIndex]}
	elif [ "$bDebian" -eq 1 ];
	then
		debPack=${failed[$modIndex]}
		$aptget -y install lib${debPack//::/-}-perl
	elif [ "$bYast2" -eq 1 ];
	then
		yastPack=${failed[$modIndex]}
		$yast2 -i perl-${yastPack//::/-}
	else
		echo "Sorry, don't know how to get this module..."
	fi
	modIndex=$((${modIndex}+1))
done

checkModules
if [ "$?" -eq "1" ]; 
then 
	showMissing
	echo; echo "Sorry, could't install all Dependencies. Try it by Hand."
else
	echo; echo "Everything fine. All Dependencies are installed."
fi
exit 0