-
Notifications
You must be signed in to change notification settings - Fork 25
/
Build.rpmpkg
executable file
·230 lines (189 loc) · 8.01 KB
/
Build.rpmpkg
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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
#!/usr/bin/env bash
#
# Written by:
# Jerry Benton < mailscanner@mailborder.com >
# 13 FEB 2015
# 18 April 2016 - Updated
#
# This script will build the latest RPM install
# package and put it in /msbuilds/rpm
# make sure this is run from the base directory
if [ ! -d 'RPM.files' ]; then
echo 'This script must be executed from the base directory.';
echo './RPM.files was not found. Exiting ...';
echo;
exit 192
fi
# directory we are in
THISCURDIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
# if not set from the "Build.all" script
if [ -z "$RPMOUT" ]; then
RPMOUT="$HOME/msbuilds/rpm";
export RPMOUT;
fi
# check to see if the output directory exists
if [ ! -d "$RPMOUT" ]; then
mkdir -p $RPMOUT
fi
# if not set from the "Build.all" script
if [ -z "$MSVERSION" ]; then
echo "Please tell me the version number (x.xx.x): ";
read MSVERSION
export MSVERSION
fi
# if not set from the "Build.all" script
if [ -z "$MSBUILD" ]; then
echo "And the build number (-x): ";
read MSBUILD
export MSBUILD
fi
# if not set from the "Build.all" script
if [ -z "$FULLMSVER" ]; then
FULLMSVER=$MSVERSION-$MSBUILD
export FULLMSVER
fi
# if not set from the "Build.all" script
if [ -z "$DEVBASEDIR" ]; then
DEVBASEDIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
#echo "You current directory is $THISCURDIR"; echo;
#echo "Enter the parent directory of RPM.files without the trailing slash: ";
#read DEVBASEDIR
export DEVBASEDIR
fi
# create this if missing
#if [ ! -f '/tmp/MailScanner.conf.index.html' ]; then
sh $DEVBASEDIR/config.index/make.sh
#fi
# the source directory
SRCDIR=$DEVBASEDIR/RPM.files/RHEL
# version info
BUILD=$MSBUILD
VERSION=$MSVERSION-$BUILD
export VERSION BUILD
# setup rpm development dirs
mkdir -p ~/rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS}
# create build output base dir
mkdir -p $RPMOUT
# the work directory
WORK="/tmp/mailscanner-$MSVERSION";
# delete work tmp if already exists
if [ -d $WORK ]; then
rm -rf $WORK
fi
# make working dir and subs
mkdir -p $WORK
mkdir -p ${WORK}/doc
mkdir -p ${WORK}/cron
mkdir -p ${WORK}/etc/rc.d/init.d
mkdir -p ${WORK}/usr/sbin/
mkdir -p ${WORK}/usr/share/man/{man8,man5}
mkdir -p ${WORK}/etc/MailScanner{conf.d,rules,mcp}
mkdir -p ${WORK}/etc/{cron.hourly,cron.daily,sysconfig,logcheck/ignore.d.workstation,logcheck/ignore.d.server}
mkdir -p ${WORK}/usr/share/MailScanner/reports/{hu,de,se,ca,cy+en,pt_br,fr,es,en,cz,it,dk,nl,ro,sk}
mkdir -p ${WORK}/usr/share/MailScanner/perl/{MailScanner,custom}
mkdir -p ${WORK}/var/{lib/MailScanner/wrapper,spool/MailScanner/archive,spool/MailScanner/quarantine,spool/MailScanner/incoming/Locks,spool/mqueue,spool/mqueue.in,run}
# base
cp $DEVBASEDIR/mailscanner/bin/check_mailscanner $WORK/usr/sbin/check_MailScanner
cp $DEVBASEDIR/Redhat.files/etc/cron.daily/mailscanner $WORK/etc/cron.daily/MailScanner
cp $DEVBASEDIR/Redhat.files/etc/cron.hourly/mailscanner $WORK/etc/cron.hourly/MailScanner
cp $DEVBASEDIR/Redhat.files/etc/rc.d/init.d/MailScanner $WORK/etc/rc.d/init.d/MailScanner
cp $DEVBASEDIR/Redhat.files/etc/sysconfig/mailscanner $WORK/etc/sysconfig/MailScanner
cp $DEVBASEDIR/RPM.files/common/update_virus_scanners.cron $WORK/cron
cp $DEVBASEDIR/RPM.files/common/update_phishing_sites.cron $WORK/cron
cp $DEVBASEDIR/RPM.files/common/update_bad_phishing_sites.cron $WORK/cron
cp $DEVBASEDIR/RPM.files/common/clean.quarantine.cron $WORK/cron
cp $DEVBASEDIR/RPM.files/common/update_spamassassin.cron $WORK/cron
cp $DEVBASEDIR/RPM.files/common/processing_messages_alert.cron $WORK/cron
# doc dir
cp $DEVBASEDIR/man/*[12345678] $WORK/doc/
cp $DEVBASEDIR/COPYING $WORK/doc/
cp /tmp/MailScanner.conf.index.html $WORK/doc/
# lib dir
cp $DEVBASEDIR/mailscanner/lib/*{wrapper,update} $WORK/lib/
cp $DEVBASEDIR/mailscanner/lib/kaspersky.prf $WORK/lib/
# etc dir
for F in filename.rules.conf filetype.rules.conf archives.filename.rules.conf archives.filetype.rules.conf spam.assassin.prefs.conf spam.lists.conf virus.scanners.conf phishing.safe.sites.conf phishing.bad.sites.conf country.domains.conf
do
cp $DEVBASEDIR/mailscanner/etc/$F $WORK/etc/
done
cp $DEVBASEDIR/mailscanner/etc/mailscanner.conf $WORK/etc/MailScanner.conf
cp $DEVBASEDIR/mailscanner/etc/conf.d/README $WORK/etc/conf.d/
(cd $DEVBASEDIR/mailscanner/etc&& tar cf - reports rules mcp ) | ( cd $WORK/etc && tar xBpf - )
# bin dir
cp $DEVBASEDIR/mailscanner/bin/Quick.Peek $WORK/bin/
cp $DEVBASEDIR/mailscanner/bin/df2mbox $WORK/bin/
cp $DEVBASEDIR/mailscanner/bin/d2mbox $WORK/bin/
cp $DEVBASEDIR/mailscanner/bin/CheckModuleVersion $WORK/bin/
cp $DEVBASEDIR/mailscanner/bin/getPERLLIB $WORK/bin/
cp $DEVBASEDIR/mailscanner/bin/mailscanner_create_locks $WORK/bin/
cp $DEVBASEDIR/mailscanner/bin/update_virus_scanners $WORK/bin/
cp $DEVBASEDIR/mailscanner/bin/update_spamassassin $WORK/bin/
cp $DEVBASEDIR/mailscanner/bin/update_phishing_sites $WORK/bin/
cp $DEVBASEDIR/mailscanner/bin/update_bad_phishing_sites $WORK/bin/
cp $DEVBASEDIR/mailscanner/bin/processing_messages_alert $WORK/bin/
cp $DEVBASEDIR/mailscanner/bin/analyse_SpamAssassin_cache $WORK/bin/
cp $DEVBASEDIR/mailscanner/bin/upgrade_MailScanner_conf $WORK/bin/
cp $DEVBASEDIR/mailscanner/bin/mailscanner.sbin $WORK/bin/mailscanner
# links
cd $WORK/bin
ln -sf analyse_SpamAssassin_cache analyze_SpamAssassin_cache
ln -sf upgrade_MailScanner_conf upgrade_languages_conf
# set attributes
chmod a+rx *
# return to where i started
cd $THISCURDIR
# copy remaining pm items
cp $DEVBASEDIR/mailscanner/bin/MailScanner.pm $WORK/bin/
cp $DEVBASEDIR/mailscanner/bin/MailScanner/*pm $WORK/bin/MailScanner
cp $DEVBASEDIR/mailscanner/bin/MailScanner/*pl $WORK/bin/MailScanner
cp $DEVBASEDIR/mailscanner/bin/MailScanner/CustomFunctions/*pm $WORK/bin/MailScanner/CustomFunctions
# set conf file permissions
chmod 0644 $WORK/etc/*.conf
# Insert the version number we are building
perl -pi -e 's/VersionNumberHere/'$MSVERSION'/;' $WORK/etc/MailScanner.conf
# do the same for the mailscanner.sbin
perl -pi -e 's/VersionNumberHere/'$MSVERSION'/;' $WORK/bin/mailscanner
# do the same for MailScanner4.spec
cp -f $DEVBASEDIR/RPM.files/RHEL/MailScanner4.spec ~/rpmbuild/SPECS/mailscanner.spec
perl -pi -e 's/VersionNumberHere/'$MSVERSION'/;' ~/rpmbuild/SPECS/mailscanner.spec
perl -pi -e 's/ReleaseNumberHere/'$MSBUILD'/;' ~/rpmbuild/SPECS/mailscanner.spec
# remove svn and git and mac stuff
find $WORK -name '.svn' -exec rm -rf {} \;
find $WORK -name '.git' -exec rm -rf {} \;
find $WORK -name '*.DS_Store' -exec rm -rf {} \;
find $WORK -depth -name '__MACOSX' -exec rm -rf {} \;
# permissions
find $WORK -name '*.pm' -exec chmod 644 {} \;
find $WORK -name '*.conf' -exec chmod 644 {} \;
find $WORK -name '*.txt' -exec chmod 644 {} \;
find $WORK -name '*.rules' -exec chmod 644 {} \;
find $WORK -name 'README' -exec chmod 644 {} \;
find $WORK -name 'EXAMPLES' -exec chmod 644 {} \;
find $WORK -name 'COPYING' -exec chmod 644 {} \;
# Build the src tarball for RPM construction
cd $WORK
cd ..
tar czf ~/rpmbuild/SOURCES/mailscanner-${MSVERSION}.tgz mailscanner-${MSVERSION}
# return to where i started
cd $THISCURDIR
# create the output dir in $RPMOUT
rm -rf $RPMOUT/MailScanner-$VERSION
mkdir -p $RPMOUT/MailScanner-$VERSION
# copy some file we need
cp $SRCDIR/install.sh $RPMOUT/MailScanner-$VERSION/
cp $SRCDIR/README $RPMOUT/MailScanner-$VERSION/
cp $DEVBASEDIR/QuickInstall.txt $RPMOUT/MailScanner-$VERSION/
find $RPMOUT/MailScanner-$VERSION -name 'install.sh' -exec chmod 655 {} \;
find $RPMOUT/MailScanner-$VERSION -name '*.txt' -exec chmod 644 {} \;
find $RPMOUT/MailScanner-$VERSION -name 'README' -exec chmod 644 {} \;
# Build the RPM and SRPMS
# extra define statements help make the rpm backwards compatible
rpmbuild -ba --sign --define "_binary_filedigest_algorithm 1" --define "_binary_payload 1" ~/rpmbuild/SPECS/mailscanner.spec
# copy the rpm built to the output dir
cp ~/rpmbuild/RPMS/noarch/mailscanner-${VERSION}.noarch.rpm $RPMOUT/MailScanner-$VERSION
cd $RPMOUT
tar czf MailScanner-${VERSION}.rpm.tar.gz MailScanner-$VERSION
rm -rf $RPMOUT/MailScanner-$VERSION
rm -rf $work
echo;
echo "Completed: $RPMOUT/MailScanner-${VERSION}.rpm.tar.gz";