forked from bluesentry/bucket-antivirus-function
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_lambda.sh
executable file
·96 lines (74 loc) · 3.43 KB
/
build_lambda.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
#!/usr/bin/env bash
# Upside Travel, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
lambda_output_file=/opt/app/build/lambda.zip
set -e
echo -ne "$(date +"%F-%T") - Updating packages \t => "
yum update --assumeyes >> build.log 2>&1 && \
echo "Successful"
echo -ne "$(date +"%F-%T") - Installing additional system packages => "
yum install --assumeyes cpio python2-pip yum-utils zip https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm >> build.log 2>&1 && \
echo 'Successful'
echo -ne "$(date +"%F-%T") - Installing Python modules => "
pip install --no-cache-dir virtualenv >> build.log 2>&1 && \
echo 'Successful'
echo -ne "$(date +"%F-%T") - Creating a new Python VirtualEnv => "
virtualenv env >> build.log 2>&1 && \
echo 'Successful'
echo -ne "$(date +"%F-%T") - Activating new VirtualEnv => "
source env/bin/activate >> build.log 2>&1 && \
echo 'Successful'
echo -ne "$(date +"%F-%T") - Installing Python dependencies in VirtualEnv => "
pip install --no-cache-dir -r requirements.txt >> build.log 2>&1 && \
echo 'Successful'
echo -ne "$(date +"%F-%T") - Downloading rpm packages => "
pushd /tmp >> build.log 2>&1 && yumdownloader -x \*i686 --archlist=x86_64 clamav clamav-lib clamav-update json-c pcre2 >> build.log 2>&1 && \
echo 'Successful'
echo -ne "$(date +"%F-%T") - Extracting clamav-0*.rpm => "
rpm2cpio clamav-0*.rpm | cpio -idmv >> build.log 2>&1 && \
echo 'Successful'
echo -ne "$(date +"%F-%T") - Extracting clamav-lib*.rpm => "
rpm2cpio clamav-lib*.rpm | cpio -idmv >> build.log 2>&1 && \
echo 'Successful'
echo -ne "$(date +"%F-%T") - Extracting clamav-update*.rpm => "
rpm2cpio clamav-update*.rpm | cpio -idmv >> build.log 2>&1 && \
echo 'Successful'
echo -ne "$(date +"%F-%T") - Extracting json-c*.rpm => "
rpm2cpio json-c*.rpm | cpio -idmv >> build.log 2>&1 && \
echo 'Successful'
echo -ne "$(date +"%F-%T") - Extracting pcre*.rpm => "
rpm2cpio pcre*.rpm | cpio -idmv >> build.log 2>&1 && \
echo 'Successful'
echo -ne "$(date +"%F-%T") - Creating directory:bin => "
popd >> build.log 2>&1 && mkdir -pv bin >> build.log 2>&1 && \
echo 'Successful'
echo -ne "$(date +"%F-%T") - Copying binaries => "
cp -v /tmp/usr/bin/clamscan /tmp/usr/bin/freshclam /tmp/usr/lib64/* bin/. >> build.log 2>&1 && \
echo 'Successful'
echo -ne "$(date +"%F-%T") - Writing freshclam.conf => "
echo "DatabaseMirror database.clamav.net" > bin/freshclam.conf >> build.log 2>&1 && \
echo 'Successful'
echo -ne "$(date +"%F-%T") - Creating directory:build => "
mkdir -pv build >> build.log 2>&1 && \
echo 'Successful'
echo -ne "$(date +"%F-%T") - Packaging Lambda function => "
zip -r9 $lambda_output_file *.py >> build.log 2>&1 && \
echo 'Successful'
echo -ne "$(date +"%F-%T") - Packaging ClamAV binaries => "
zip -r9 $lambda_output_file bin >> build.log 2>&1 && \
echo 'Successful'
echo -ne "$(date +"%F-%T") - Packaging Python libraries => "
cd env/lib/python2.7/site-packages && zip -r9 $lambda_output_file * >> build.log 2>&1 && \
echo 'Successful'