forked from Kong/kong
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpackage-build.sh
executable file
·152 lines (122 loc) · 3.92 KB
/
package-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 -o errexit
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
echo "Current directory is: "$DIR
if [ "$DIR" == "/" ]; then
DIR=""
fi
OUT=$DIR/build/out
TMP=$DIR/build/tmp
echo "Cleaning directories"
rm -rf $OUT
rm -rf $TMP
echo "Preparing environment"
mkdir -p $OUT
mkdir -p $TMP
# Load dependencies versions
source ./versions.sh
PACKAGE_TYPE=""
LUA_MAKE=""
OPENRESTY_CONFIGURE=""
FPM_PARAMS=""
if [ "$(uname)" = "Darwin" ]; then
PACKAGE_TYPE="osxpkg"
LUA_MAKE="macosx"
# Install PCRE
cd $TMP
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-$PCRE_VERSION.tar.gz
tar xzf pcre-$PCRE_VERSION.tar.gz
cd pcre-$PCRE_VERSION
./configure
make
make install DESTDIR=$OUT
cd $OUT
OPENRESTY_CONFIGURE="--with-cc-opt=-I$OUT/usr/local/include --with-ld-opt=-L$OUT/usr/local/lib"
FPM_PARAMS="--osxpkg-identifier-prefix org.getkong"
elif hash yum 2>/dev/null; then
if [[ $EUID -eq 0 ]]; then
# If already root, install sudo just in case (Docker)
yum -y install sudo
sed -i "s/^.*requiretty/#Defaults requiretty/" /etc/sudoers
fi
sudo yum -y install epel-release
sudo yum -y install wget tar make ldconfig gcc readline-devel perl pcre-devel openssl-devel ldconfig unzip git rpm-build ncurses-devel
PACKAGE_TYPE="rpm"
LUA_MAKE="linux"
elif hash apt-get 2>/dev/null; then
if [[ $EUID -eq 0 ]]; then
# If already root, install sudo just in case (Docker)
apt-get update && apt-get install sudo
fi
sudo apt-get update && sudo apt-get -y install wget tar make gcc libreadline-dev libncurses5-dev libpcre3-dev libssl-dev perl unzip git
PACKAGE_TYPE="deb"
LUA_MAKE="linux"
else
echo "Unsupported platform"
exit 1
fi
cd $TMP
wget http://cache.ruby-lang.org/pub/ruby/2.1/ruby-2.1.2.tar.gz
tar xvfvz ruby-2.1.2.tar.gz
cd ruby-2.1.2
./configure
make
sudo make install
sudo gem update --system
sudo gem install fpm
# Starting building stuff
cd $TMP
wget http://www.lua.org/ftp/lua-$LUA_VERSION.tar.gz
tar xzf lua-$LUA_VERSION.tar.gz
cd lua-$LUA_VERSION
make $LUA_MAKE
make install INSTALL_TOP=$OUT/usr/local
cd $OUT
ln -s $OUT/usr/local/bin/lua $OUT/usr/local/bin/lua5.1
export PATH=$PATH:${OUT}/usr/local/bin
export LUA_PATH=${OUT}/usr/local/share/lua/5.1/?.lua
cd $TMP
wget http://luarocks.org/releases/luarocks-$LUAROCKS_VERSION.tar.gz
tar xzf luarocks-$LUAROCKS_VERSION.tar.gz
cd luarocks-$LUAROCKS_VERSION
./configure --with-lua-include=$OUT/usr/local/include
make build
make install DESTDIR=$OUT
cd $OUT
cd $TMP
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-$PCRE_VERSION.tar.gz
tar xzf pcre-$PCRE_VERSION.tar.gz
cd $OUT
cd $TMP
wget http://openresty.org/download/ngx_openresty-$OPENRESTY_VERSION.tar.gz
tar xzf ngx_openresty-$OPENRESTY_VERSION.tar.gz
cd ngx_openresty-$OPENRESTY_VERSION
./configure --with-pcre-jit --with-ipv6 --with-http_realip_module --with-http_ssl_module --with-http_stub_status_module ${OPENRESTY_CONFIGURE}
make
make install DESTDIR=$OUT
cd $OUT
rocks_config=$(mktemp -t rocks_config.XXX.lua)
echo "
rocks_trees = {
{ name = [[system]], root = [[${OUT}/usr/local]] }
}
" > $rocks_config
export LUAROCKS_CONFIG=$rocks_config
$OUT/usr/local/bin/luarocks install kong $KONG_VERSION
sed -i.bak s@${OUT}@@g $OUT/usr/local/bin/kong
rm $OUT/usr/local/bin/kong.bak
mkdir -p $OUT/etc/kong
cp $OUT/usr/local/lib/luarocks/rocks/kong/$KONG_VERSION/conf/kong.yml $OUT/etc/kong/kong.yml
# Make the package
post_install_script=$(mktemp -t post_install_script.XXX.sh)
printf "#!/bin/sh\nsudo mkdir -p /etc/kong\nsudo cp /usr/local/lib/luarocks/rocks/kong/$KONG_VERSION/conf/kong.yml /etc/kong/kong.yml" > $post_install_script
cd $OUT
fpm -a all -f -s dir -t $PACKAGE_TYPE -n "kong" -v ${KONG_VERSION} ${FPM_PARAMS} \
--iteration 1 \
--description 'Kong is an open distributed platform for your APIs, focused on high performance and reliability.' \
--vendor Mashape \
--license MIT \
--url http://getkong.org/ \
--after-install $post_install_script \
usr
echo "DONE"