-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.sh
executable file
·152 lines (130 loc) · 4.46 KB
/
build.sh
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#!/bin/bash
set -ex
# If running as root (e.g. under Docker)
if [[ $EUID -eq 0 ]]
then
SUDO=
RVM_SCRIPT=/etc/profile.d/rvm.sh
else
SUDO=sudo
RVM_SCRIPT=$HOME/.rvm/scripts/rvm
fi
# Build an HAProxy RPM with ssl and lua support
# Set the workspace directory if not set
if [ -z $WORKSPACE ]
then
WORKSPACE=$HOME
fi
INSTALL_ROOT="${INSTALL_ROOT:-${WORKSPACE}/oss}"
BUILD_ROOT="${BUILD_ROOT:-${WORKSPACE}/build}"
HAPROXY_VERSION="${HAPROXY_VERSION:-1.6.6}"
LUA_VERSION="${LUA_VERSION:-5.3.3}"
RVM_VERSION="${RVM_VERSION:-2.2.1}"
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
REDHAT_VERSION=$(sed -e "s/Linux//" /etc/redhat-release | awk '{print substr ($3, 0, 1)}')
# Install development tools and libraries
$SUDO yum -y groupinstall "Development tools"
$SUDO yum -y install openssl-devel pcre-devel zlib-devel readline-devel libtermcap-devel wget curl which
# Install fpm (this is used to build the RPM)
if [ ! -f $RVM_SCRIPT ]
then
if [ $REDHAT_VERSION -gt 5 ]
then
curl -sSL https://rvm.io/mpapis.asc | gpg --import -
#gpg2 --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
else
$SUDO yum -y install gpg
curl -sSL https://rvm.io/mpapis.asc | gpg --import -
#gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
fi
\curl -sSL https://get.rvm.io | bash -s -- --ignore-dotfiles
# set +e before sourceing the rvm script as it has none zero exits in the
# script somewhere (presumably a bug).
set +e
source $RVM_SCRIPT
rvm install $RVM_VERSION
rvm use $RVM_VERSION
set -e
gem install fpm
else
set +e
source $RVM_SCRIPT
rvm use $RVM_VERSION
set -e
fi
set -e
# Create empty INSTALL_ROOT - this is where we'll make install to.
if [ -d $INSTALL_ROOT ]
then
rm -rf $INSTALL_ROOT
fi
mkdir -p $INSTALL_ROOT
# Create empty BUILD_ROOT - this is where we'll download source and compile.
if [ -d $BUILD_ROOT ]
then
rm -rf $BUILD_ROOT
fi
mkdir $BUILD_ROOT
# Due to a bug in rvm, running `cd` results in a none zero exit.
# So from now on, we use `builtin cd`
# Build LUA
LUA_SRC="lua-${LUA_VERSION}"
builtin cd $BUILD_ROOT
wget http://www.lua.org/ftp/${LUA_SRC}.tar.gz
tar xzf $LUA_SRC.tar.gz
builtin cd $LUA_SRC
# Add -ltermcap to the Makefile on EL5 variants to fix
# undefined references in libreadline.so
if [ $REDHAT_VERSION -eq 5 ]
then
if ! grep -q ltermcap Makefile
then
sed -ie "s/-lreadline/-lreadline -ltermcap/" src/Makefile
fi
fi
make linux
make INSTALL_TOP=$INSTALL_ROOT/$LUA_SRC install
# Build HAProxy
builtin cd $BUILD_ROOT
HAPROXY_BRANCH=${HAPROXY_VERSION%.*}
HAPROXY_SRC="haproxy-${HAPROXY_VERSION}"
wget http://www.haproxy.org/download/$HAPROXY_BRANCH/src/$HAPROXY_SRC.tar.gz
tar xzf $HAPROXY_SRC.tar.gz
builtin cd $HAPROXY_SRC
LUA_ROOT="$INSTALL_ROOT/$LUA_SRC"
if [ $REDHAT_VERSION -eq 5 ]
then
make TARGET=linux26 USE_PCRE=1 USE_OPENSSL=1 USE_ZLIB=1 USE_DL=1 USE_LUA=1 LUA_LIB=$LUA_ROOT/lib LUA_INC=$LUA_ROOT/include LUA_LIB_NAME=lua CC="gcc -DLUA_32BITS"
else
make TARGET=linux26 USE_PCRE=1 USE_OPENSSL=1 USE_ZLIB=1 USE_DL=1 USE_LUA=1 LUA_LIB=$LUA_ROOT/lib LUA_INC=$LUA_ROOT/include LUA_LIB_NAME=lua
fi
if [ $REDHAT_VERSION -lt 7 ]
then
# Use system v init scripts
mkdir -p $INSTALL_ROOT/haproxy/etc/rc.d/init.d
else
# Use systemd
mkdir -p $INSTALL_ROOT/haproxy/usr/lib/systemd/system
fi
mkdir -p $INSTALL_ROOT/haproxy/etc/haproxy
mkdir -p $INSTALL_ROOT/haproxy/var/lib/haproxy
mkdir -p $INSTALL_ROOT/haproxy/etc/sysconfig
touch $INSTALL_ROOT/haproxy/etc/sysconfig/haproxy
chmod 700 $INSTALL_ROOT/haproxy/var/lib/haproxy
chown 644 $INSTALL_ROOT/haproxy/etc/sysconfig/haproxy
make install DESTDIR=$INSTALL_ROOT/haproxy PREFIX=/usr DOCDIR=/usr/share/doc/haproxy
# Create system v init script for EL versions < 7 and systemd service for EL >=7
if [ $REDHAT_VERSION -lt 7 ]
then
cp $SCRIPT_DIR/haproxy.sysv $INSTALL_ROOT/haproxy/etc/rc.d/init.d/haproxy
chmod 755 $INSTALL_ROOT/haproxy/etc/rc.d/init.d/haproxy
else
cp $SCRIPT_DIR/haproxy.service $INSTALL_ROOT/haproxy/usr/lib/systemd/system
cp haproxy-systemd-wrapper $INSTALL_ROOT/haproxy/usr/sbin
fi
builtin cd $WORKSPACE
rm -f *.rpm
fpm -s dir -t rpm -n haproxy -v $HAPROXY_VERSION --config-files /etc/haproxy/ -C ~/oss/haproxy/ usr etc var
[ ! -d /vagrant/rpms/el${REDHAT_VERSION} ] && mkdir -p /vagrant/rpms/el${REDHAT_VERSION}
cp -f haproxy-$HAPROXY_VERSION-1.x86_64.rpm /vagrant/rpms/el${REDHAT_VERSION}
echo "haproxy-$HAPROXY_VERSION-1.x86_64.rpm copied to /vagrant/rpms/el${REDHAT_VERSION}"