-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild_all.sh
executable file
·200 lines (159 loc) · 6.2 KB
/
build_all.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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
#!/bin/bash
################################################################################
# Copyright : (C) 2013
# Author : Andrei Costin ([email protected]) ([email protected])
# Date : 20130907
# Desc : This is custom script to build PostgreSQL plugin/shared-module.
# We have to do this 'hack' because tested sdhash/libsdbf 3.3 is
# not being built and distributed as a proper shared library with
# includes and all the stuff
# Usage : ./build_sdhash_psql.sh
# License : GPLv3
################################################################################
read -e -p "Enter work and build dir: " -i "$PWD/psql_fuzzy" DEST_DIR
echo $DEST_DIR
mkdir -p $DEST_DIR
PSQL_DIR="postgresql-9.2.4"
WGET_PSQL="ftp://ftp.postgresql.org/pub/source/v9.2.4/$PSQL_DIR.tar.gz"
SDHASH_DIR="sdhash-3.3"
WGET_SDHASH="http://roussev.net/sdhash/releases/packages/$SDHASH_DIR.tar.gz"
SSDEEP_PSQL_DIR="ssdeep_psql"
GIT_SSDEEP_PSQL="https://github.com/bernerdschaefer/$SSDEEP_PSQL_DIR.git"
SDHASH_PSQL_DIR="sdhash_psql"
GIT_SDHASH_PSQL="https://github.com/eurecom-s3/$SDHASH_PSQL_DIR.git"
################################################################################
echo "Preparing and building PostgreSQL"
cd $DEST_DIR
wget $WGET_PSQL
tar -xzvf $PSQL_DIR.tar.gz
cd $PSQL_DIR
./configure
if [ $? -ne 0 ];
then
echo "Error: configure failed for $PSQL_DIR"
exit 1
fi
# Patch PostgreSQL to be able to link agains C++ object-files/libraries
# http://postgresql.1045698.n5.nabble.com/Mostly-Harmless-Welcoming-our-C-friends-td2011266.html
# http://www.linuxquestions.org/questions/programming-9/how-to-make-g-behave-like-gcc-in-this-case-795524/
# HACK: though this is a dirty hack for now, let it work until the proper patch is in the PostgreSQL main branch
FILE_BUILTINS_H="./src/include/utils/builtins.h"
if [ `grep '__cplusplus' $FILE_BUILTINS_H | wc -l` -ne 2 ];
then
sed -i 's@#define BUILTINS_H@#define BUILTINS_H\n\n#ifdef __cplusplus\nextern "C" {\n#endif\n@g' $FILE_BUILTINS_H
sed -i 's@#endif /\* BUILTINS_H \*/@\n#ifdef __cplusplus\n}; /* extern "C" */\n#endif\n\n#endif /* BUILTINS_H */@g' $FILE_BUILTINS_H
fi
FILE_PALLOC_H="./src/include/utils/palloc.h"
if [ `grep '__cplusplus' $FILE_PALLOC_H | wc -l` -ne 2 ];
then
sed -i 's@#define PALLOC_H@#define PALLOC_H\n\n#ifdef __cplusplus\nextern "C" {\n#endif\n@g' $FILE_PALLOC_H
sed -i 's@#endif /\* PALLOC_H \*/@\n#ifdef __cplusplus\n}; /* extern "C" */\n#endif\n\n#endif /* PALLOC_H */@g' $FILE_PALLOC_H
fi
FILE_FMGR_H="./src/include/fmgr.h"
if [ `grep '__cplusplus' $FILE_FMGR_H | wc -l` -ne 2 ];
then
sed -i 's@#define FMGR_H@#define FMGR_H\n\n#ifdef __cplusplus\nextern "C" {\n#endif\n@g' $FILE_FMGR_H
sed -i 's@#endif /\* FMGR_H \*/@\n#ifdef __cplusplus\n}; /* extern "C" */\n#endif\n\n#endif /* FMGR_H */@g' $FILE_FMGR_H
fi
make
if [ $? -ne 0 ];
then
echo "Error: build failed for $PSQL_DIR"
exit 1
fi
# This tests the PostreSQL core
make check
# TODO: add error handling in case tests failed
################################################################################
echo "Preparing SDHASH_PSQL"
cd $DEST_DIR/$PSQL_DIR/contrib
git clone $GIT_SDHASH_PSQL
cd $SDHASH_PSQL_DIR
# Patch over version "sdhash-3.3" to have "sdbf(char *str)" constructor as well to read a formatted sdbf from a C-string
# NOTE: remove this once the patch is integrated in new sdhash versions and the new versions are used herein
cp -f sdbf_class.* $DEST_DIR/$SDHASH_DIR/sdbf/
################################################################################
echo "Preparing and building SDHASH"
cd $DEST_DIR
wget $WGET_SDHASH
tar -xzvf $SDHASH_DIR.tar.gz
cd $SDHASH_DIR
# Patch for 32bit systems
PLATFORM=`getconf LONG_BIT`
if [ $PLATFORM -eq 32 ];
then
grep "D_M_IX86" Makefile
if [ $? -ne 0 ];
then
cp Makefile Makefile.original
sed 's@CFLAGS = @CFLAGS = -D_M_IX86 @g' -i Makefile
fi
grep "//local_cpuid" ./sdbf/sdbf_conf.cc
if [ $? -ne 0 ];
then
cp ./sdbf/sdbf_conf.cc ./sdbf/sdbf_conf.cc.original
sed 's@local_cpuid@//local_cpuid@g' -i ./sdbf/sdbf_conf.cc
fi
fi
# Patch for 64bit platforms (works well on 32bit platforms as well) to properly
# build of static version of sdhash-supplied boost library on
FILE_SDHASH_MAKEFILE="Makefile"
if [ `grep "link=static" $FILE_SDHASH_MAKEFILE | grep "fPIC" | wc -l` -eq 0 ];
then
sed -i 's@b2 link=static@b2 link=static cxxflags=-fPIC cflags=-fPIC@g' $FILE_SDHASH_MAKEFILE
fi
make
if [ $? -ne 0 ];
then
echo "Error: build failed for $SDHASH_DIR"
exit 1
fi
################################################################################
echo "Preparing and building SSDEEP_PSQL"
cd $DEST_DIR/$PSQL_DIR/contrib
git clone $GIT_SSDEEP_PSQL
cd $SSDEEP_PSQL_DIR
make
if [ $? -ne 0 ];
then
echo "Error: build failed for $SSDEEP_PSQL_DIR"
exit 1
fi
################################################################################
echo "Building SDHASH_PSQL"
cd $DEST_DIR/$PSQL_DIR/contrib
cd $SDHASH_PSQL_DIR
ln -s $DEST_DIR/$SDHASH_DIR sdhash-dist
./build_sdhash_psql.sh
################################################################################
echo "Testing PostgreSQL plugins"
cd $DEST_DIR/$PSQL_DIR/contrib
# Patch $DEST_DIR/$PSQL_DIR/contrib/Makefile to contain fuzzy-hashing plugins:
# ssdeep_psql
# sdhash_psql
# HACK: though this is a dirty hack for now
FILE_CONTRIB_MAKEFILE="Makefile"
if [ `egrep -e "(ssdeep_psql)|(sdhash_psql)" $FILE_CONTRIB_MAKEFILE | wc -l` -ne 2 ];
then
sed -i 's@SUBDIRS = \\@SUBDIRS = \\\n\t\tssdeep_psql\t\\\n\t\tsdhash_psql\t\\@g' $FILE_CONTRIB_MAKEFILE
fi
make
if [ $? -ne 0 ];
then
echo "Error: build failed for $PSQL_DIR/contrib"
exit 1
fi
# This builds the plugins from './contrib' of PostreSQL
cd $DEST_DIR/$PSQL_DIR
make world
# This tests the plugins from './contrib' of PostreSQL
cd $DEST_DIR/$PSQL_DIR
make check-world
# TODO: add error handling in case tests failed
################################################################################
echo "Installing PostgreSQL and PostgreSQL plugins"
cd $DEST_DIR/$PSQL_DIR
# This installs the PostreSQL
sudo make install
# This installs the plugins from './contrib' of PostreSQL
sudo make install-world