Project

Profile

Help

Support #2625 » install.sh

Duygu Colak, 2016-02-18 12:31

 
1
#!/bin/bash
2

    
3
#
4
# SAXON-HE installator for PHP on 64bit debian based system
5
#
6
# @author Petr Zak(zak@cyberdeck.cz)
7
#
8

    
9
#basic variables used in this script (possible future feature - override from parametrs)
10
sourceDir=$(pwd);
11
phpConfDir=/etc/php.d/
12
export JAVA_HOME=/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.38
13

    
14
#try to detect, if this package is already installed
15
#if [ -f /usr/lib/libsaxon.so ]; then
16
#  echo "It seems that this package is already installed, run uninstall.sh first!"
17
#  exit 1
18
#fi
19

    
20
#detect if system is 64bit, 'cause this package is designed for 64bit systems
21
#if [ $(uname -m | grep "64" | wc -l) == 0 ]; then
22
#  echo "This package is used for 64bit system, but your system is only 32bit. Download saxon version for 32bit system."
23
#  exit 1
24
#fi
25

    
26

    
27

    
28
#detect if our apache webserver is called apache2 (deb based systems) or apache2 (rpm based systems)
29
if [ $(service apache2 status | grep "apache2 is" | wc -l) == 1  ]; then
30
  apacheServerName="apache2"
31
elif [ $(service httpd status |grep "httpd" | grep "is" | wc -l) == 1 ]; then
32
  apacheServerName="httpd"
33
else
34
  echo "Apache webserver (package apache2 or httpd) not found. Terminating"
35
  exit 1
36
fi
37

    
38
#notify user that script is running
39
echo ''
40
echo "libsaxon PHP installer. ";
41
echo ""
42

    
43
#test if is running under root user, it is required 'cause system service (webserver) handling, and some /usr/lib and /lib directories manipulation
44
if [[ $EUID -ne 0 ]]; then
45
  echo "This installator must be executed as a root.";
46
  exit 1;
47
fi
48

    
49
#function that detect id $param1 package is installed
50
#
51
# @param $1 package name
52
# @return void
53
#
54
function testPackageIsPresent {
55
  echo -ne "Checking if \"$1\" is installed............."
56
  #installed software detection depends on package system (rpm/deb)...
57
  if [ -f /bin/rpm ]; then
58
    inst=$(rpm -qa $1 $2 $3 $4 $5 $6| wc -l)
59
  elif [ -f /usr/bin/dpkg ]; then
60
    inst=$(dpkg -l $1 $2 $3 $4 $5 $6| grep "ii" | wc -l)
61
  else 
62
    echo "unknown package system, this installer needs dpkg or rpm";
63
    exit 1
64
  fi
65
  
66
  if [ $inst != 1 ]; then
67
    echo "failed"
68
    echo ""
69
    echo "Package \"$1 $2 $3 $4 $5 $6\" must be installed. Please install it manually and rerun this installer"
70
    echo ""
71
    exit 1
72
  else
73
    echo "OK"
74
  fi
75
}
76

    
77
#checking prerequeisites - installed packages, environment variables (JAVA_HOME...)
78
echo "Checking prerequesities... "
79

    
80
testPackageIsPresent make
81
testPackageIsPresent php-devel php5-dev php55-dev php55w-devel
82
testPackageIsPresent apache2 httpd
83
testPackageIsPresent gcc-c++ g++
84

    
85
 if [ -z ${JAVA_HOME} ]; then
86
  echo "JAVA_HOME not set, please set it and rerun this installer"
87
  exit 1
88
fi
89
  
90

    
91
#copying module libraries into system directories
92
echo ""
93
echo "Compiling module for php"
94
cp -r $sourceDir/rt/ /usr/lib/
95
cp libsaxon.so /usr/lib/
96
cd $sourceDir/Saxon-C-API/
97

    
98
#compilation of php module
99
phpize
100
./configure --enable-saxon
101
export LD_LIBRARY_PATH=/usr/lib/rt/lib/i386/jetvm:/usr/lib/rt/lib/i386:/usr/lib/rt:$JAVA_HOME/include/linux:$JAVA_HOME/include:$LD_LIBRARY_PATH
102

    
103
#in my case, c++ compiler requires include path to java header files during compilation, so according to http://www.network-theory.co.uk/docs/gccintro/gccintro_23.html,
104
# I add these dirs in my JAVA_HOME directory to this environment variable used by compiler.
105
CPLUS_INCLUDE_PATH=/usr/lib/rt:$JAVA_HOME/include/linux:$JAVA_HOME/include
106
export CPLUS_INCLUDE_PATH
107

    
108
make
109
make install
110

    
111
#add tell php/apache to load saxon module
112
echo ""
113
echo "Adding PHP module to PHP configuration"
114

    
115
if [ -d $phpConfDir ]; then #possible deb based systems, modules ini are symlinks
116
  echo "extension=saxon.so" >$phpConfDir/mods-available/saxon.ini
117
  ln -s $phpConfDir/mods-available/saxon.ini $phpConfDir/apache2/conf.d/90_saxon.ini
118
elif [ -d /etc/php.d ]; then
119
  echo "extension=saxon.so" > /etc/php.d/saxon.ini
120
else 
121
  echo "PHP configuration file not found, please add 'extension=saxon.so' to your php ini file manually"
122
fi
123

    
124
#create symlink to java virtual machine, it is not required to install/compile, but it's requirement to use it from PHP code.
125
if [ -d /lib ]; then
126
  ln -s  $JAVA_HOME/jre/lib/i386/server/libjvm.so /lib/libjvm.so
127
fi
128

    
129
if [ -d /lib64 ]; then
130
  ln -s  $JAVA_HOME/jre/lib/amd64/server/libjvm.so /lib64/libjvm.so
131
fi
132

    
133
#finally restart webserver 'cause adding new php module
134
service $apacheServerName restart
135

    
136
#finally DONE! time for beer :-)
137
echo "Saxon for PHP finally installed. Done."
138

    
(1-1/10)