LinuxInstallation: install_perl_modules.sh

File install_perl_modules.sh, 3.2 kB (added by thekashyap, 1 year ago)

Sample script to install downloaded perl modules.

Line 
1 #!/bin/bash
2
3 if [ $# -lt 1 ]; then
4         echo -e "usage: `basename $0` <in dir>\n    <in dir> - Directory containing tar.gz files for\n               all perl modules, distributions you want to install"
5         exit 1
6 else
7         IND=$1
8         LOGD=`pwd`/perl_module_installation_logs
9 fi
10
11 echo "Input directory: $IND"
12 echo "Log directory: $LOGD"
13
14 TD=/tmp/.pm_perlmod_installer
15 rm -rf $TD $LOGD
16 mkdir -p $TD $LOGD
17
18 # Some modules' make or make install asks some questions.
19 # Hopefully all of them have a default value so if you press
20 # enter it should work. "< response_file" simulates that.
21 # No one asks more than 2 questions but we give 10 "enters"
22 # just to be safe.
23 RESP_FILE=/tmp/.pm_perlmod_installer_resp_file
24 cat <<EOFILE > $RESP_FILE
25
26
27
28
29
30
31
32
33
34
35 EOFILE
36
37 echo "gunzipping n untarring from $IND to $TD."
38 for targz in $IND/*.tar.gz
39 do
40         gunzip $targz
41         tar -C $TD -xf ${targz/.gz/}
42 done
43
44 echo "gzipping..."
45 gzip $IND/*.tar
46
47 # Given that we don't know the correct sequence
48 # as per the dependencies among these modules, we
49 # keep trying in a loop.
50 # Max number of retries = total num of modules
51 cd $TD
52 num_succ_modules=0
53 num_retries=0
54 echo "Number of modules to install = `ls -1 $TD | wc -l`"
55 while true
56 do
57         num_modules=`ls -1 $TD | wc -l`
58         if [ $num_modules -eq 0 ]; then
59                 echo "Unbeleivable.. all modules installed successfully. Congratulations."
60                 break;
61         fi
62
63         if [ $num_retries -gt $num_modules ]; then
64                 echo "Tried $num_retries times, but looks like the $IND contains modules which depend on some modules which are neither installed nor inside $IND."
65                 rm -rf $TD
66                 exit 1;
67         fi
68
69         echo "-----------------Try number: $num_retries-----------------"
70         cd $TD
71         for f in *
72         do
73                 LOGF=$LOGD/$f.log
74                 echo "Installing $f"
75                 echo "------------------------------------------------------------" >> $LOGF
76                 echo "-----------------Retry number: $num_retries-----------------" >> $LOGF
77                 echo "------------------------------------------------------------" >> $LOGF
78                 cd $TD/$f
79                 # some modules provide a difference installation interface.. :-(((
80                 if [ -f Makefile.PL ]; then
81                         step_one="perl Makefile.PL"
82                         step_two="make"
83                         step_three="make install"
84                 else
85                         step_one="perl Build.PL"
86                         step_two="perl ./Build"
87                         step_three="perl ./Build install"
88                 fi
89                 echo "---------------------------$step_one---------------------------" >> $LOGF
90                 $step_one < $RESP_FILE >> $LOGF 2>&1
91                 if [ $? -ne 0 ]; then
92                         echo "\"$step_one\" phase for $f failed."
93                 else
94                         echo "---------------------------$step_two---------------------------" >> $LOGF
95                         $step_two < $RESP_FILE >> $LOGF 2>&1
96                         if [ $? -ne 0 ]; then
97                                 echo "\"$step_two\" phase for $f failed."
98                         else
99                                 echo "---------------------------$step_three---------------------------" >> $LOGF
100                                 $step_three < $RESP_FILE >> $LOGF 2>&1
101                                 if [ $? -ne 0 ]; then
102                                         echo "\"$step_three\" phase for $f failed."
103                                 else
104                                         # if it was installed remove it,
105                                         # so we save some time in next parse.
106                                         echo "$f installed SUCCESSFULLY."
107                                         rm -rf $TD/$f
108                                         num_succ_modules=`expr $num_succ_modules + 1`
109                                 fi
110                         fi
111                 fi
112         # for f in *
113         done
114         num_retries=`expr $num_retries + 1`
115 # while true
116 done
117
118 rm -rf $TD
119 echo "All done. Logs available in: $LOGD"
120
121 exit 0;