Initial commit from project. lib dependencies need checking
[packeteer.git] / install_dependencies.sh
1 #!/bin/bash
2 # Download, configure, build and install the netfilters libnfnetlink and libnetfilter_queue libraries
3 LOG="${PWD}/install.log"
4 ERR="failed, please see $LOG status code="
5
6 OK="done"
7
8 # set -x
9
10 # universal error reporting and exit
11 # $1 exit code to return
12 # $2 textual error message
13 # $3 status returned by program that induced exit
14 function error_exit() {
15  echo "$2 $3"
16  exit $1
17 }
18
19 # download, configure, make, make install package
20 # $1 URL to downloaded archive file
21 function lib_install() {
22  # get filename from URL
23  filename=`expr "$1" : '.*\/\(.\+\)'`
24  # get stub for directory name
25  dir=`expr "${filename}" : '\(.\+\)\.tar\..\+'`
26  # get archive type
27  # default type is bzip2
28  type="j"
29  arc_type=`expr "${filename}" : '.*\.\(.\+\)'`
30  if [ "${arc_type}" = "bz2" ]; then
31   type="j"
32  elif [ "${arc_type}" = "gz" ]; then
33   type="z"
34  fi
35
36  echo -n "${filename}: downloading..."
37  wget $1 >>${LOG} 2>&1
38  STATUS=$?
39  if [ ${STATUS} -eq 0 ]; then
40   echo -n "${OK}, extracting..."
41   echo "Extracting" >>${LOG}
42
43   tar -x${type}f ${filename} >>${LOG} 2>&1
44   STATUS=$?
45   if [ ${STATUS} -eq 0 ]; then
46    # move into the package directory
47    cd ${dir} 
48
49    # if there is a ./configure script, run it
50    if [ -e "configure" ]; then
51     echo -n "${OK}, configuring..."
52     echo "Configuring" >>${LOG}
53     ./configure --prefix=/usr >>${LOG} 2>&1 
54     STATUS=$?
55     if [ ${STATUS} -ne 0 ]; then
56      error_exit 3 "${ERR}" ${STATUS}
57     fi
58    fi
59
60    echo -n "${OK}, building..."
61    echo "Building" >>${LOG}
62  
63    make >>${LOG} 2>&1 
64    STATUS=$?
65    if [ ${STATUS} -eq 0 ]; then
66     echo -n "${OK}, installing..."
67     echo "Installing" >>${LOG}
68
69     sudo sh -c "make install >>${LOG} 2>&1"
70     STATUS=$?
71     if [ ${STATUS} -eq 0 ]; then
72      echo "${OK}"
73     else # install failed
74      error_exit 4 "${ERR}" ${STATUS}
75     fi
76    else # make failed
77     error_exit 3 "${ERR}" ${STATUS}
78    fi
79
80    # return to parent directory
81    cd ..
82
83   else # extract failed
84    error_exit 2 "${ERR}" ${STATUS}
85   fi
86  else # download failed
87   error_exit 1 "${ERR}" ${STATUS}
88  fi
89
90  return 0
91 }
92
93 echo -n "Going to need to run sudo to do 'make install', please pre-authorise now..."
94 sudo echo -ne "accepted..."
95 if [ $? -eq 0 ]; then
96  echo -e "successful, thank-you.\n"
97
98  echo "Logging to ${LOG}"
99  echo "Starting at `date`" > ${LOG}
100  echo "Installing netfilter libraries"
101  lib_install "http://www.netfilter.org/projects/libnfnetlink/files/libnfnetlink-0.0.30.tar.bz2"
102  lib_install "http://www.netfilter.org/projects/libnetfilter_queue/files/libnetfilter_queue-0.0.15.tar.bz2"
103  lib_install "http://www.netfilter.org/projects/libnetfilter_conntrack/files/libnetfilter_conntrack-0.0.81.tar.bz2"
104  lib_install "http://belnet.dl.sourceforge.net/sourceforge/flex/flex-2.5.33.tar.bz2"
105  lib_install "http://ftp.gnu.org/gnu/bison/bison-2.3.tar.gz"
106  lib_install "http://www.tcpdump.org/release/libpcap-0.9.7.tar.gz"
107  # build packeteer
108  make
109  echo "Finished successfully. To run use ./packeteer"
110 else
111  echo "failed. Please review error reports; problems occurred"
112 fi
113 # expr "http://www.netfilter.org/projects/libnfnetlink/files/libnfnetlink-0.0.30.tar.bz2" : '.*\/\(.+\)$'
114 # echo "`expr "libnfnetlink-0.0.30.tar.bz2" : '.*\.\(.\+\)'`"