-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathBuildEm.sh
executable file
·104 lines (91 loc) · 2.34 KB
/
BuildEm.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
#!/bin/sh
#
# Script to build the downloaded SRPMs
#
#################################################################
SAVEDIR="$(readlink -f $(dirname ${0}))"
RPMDEPS=(
rpm-build
dos2unix
)
BUILDROOT="${HOME}/rpmbuild"
# Set up RPM build environment
function PrepBuildDirs() {
# Ensure RPM build-tree exists
test -d ${BUILDROOT} || mkdir -p \
${BUILDROOT}/{BUILD,RPMS,SOURCES,SPECS,SRPMS} > /dev/null 2>&1
# Ensure RPM macro-definition file exists
test -f ${HOME}/.rpmmacros || echo '%_topdir %(echo $HOME)/rpmbuild' \
> ${HOME}/.rpmmacros
}
function ExtractSource() {
local EXTDIR="/tmp/srpm_extract"
test -d ${EXTDIR} || mkdir -p ${EXTDIR}
for SRPM in *.src.rpm
do
echo "Extracting ${SRPM}"
rpm2cpio ${SRPM} | ( cd ${EXTDIR} ; cpio -id )
done
}
# Move .spec files to ${BUILDROOT}/SPECS
function HomeSpecs() {
local SPECFILES="/tmp/srpm_extract/*.spec"
mv ${SPECFILES} ${BUILDROOT}/SPECS
}
# Move source files to ${BUILDROOT}/SOURCES
function HomeSources() {
(
cd /tmp/srpm_extract
# Move the non-archived sources
mv $(awk '/^Source/{print $2}' ${BUILDROOT}/SPECS/*.spec | sed '{
/tar.gz/d
/.tgz/d
/.zip/d
}') ${BUILDROOT}/SOURCES
# Move the archived sources
mv * ${BUILDROOT}/SOURCES
)
}
# Install any missing RPM dependencies
function GetMissingRPMS() {
for DEPEND in ${RPMDEPS[@]}
do
if [[ $(rpm --quiet -q ${DEPEND})$? -ne 0 ]]
then
ADDRPMS="${ADDRPMS} ${DEPEND}"
fi
if [[ "${ADDRPMS}" = "" ]]
then
echo "No missing RPMs detected"
else
yum install -q -y ${ADDRPMS}
fi
done
}
# Build the RPMs
function BuildRPMs() {
cd ${BUILDROOT}/SPECS
for SPEC in *.spec
do
ELEMENT=$(echo ${SPEC} | sed 's/.spec//')
echo "Building ${ELEMENT}..."
if [[ $(rpmbuild --quiet -ba ${SPEC} > /dev/null 2>&1)$? -ne 0 ]]
then
printf "\tBuild did not exit cleanly.\n" > /dev/stderr
else
printf "\tBuild exited cleanly.\n"
fi
done
}
#######################
## Main functionality
#######################
GetMissingRPMS
PrepBuildDirs
ExtractSource
HomeSpecs
HomeSources
BuildRPMs
# Copy built RPMs to project-dir
echo "Copying new RPMs to project directory".
mv $(find ${BUILDROOT}/RPMS/ -type f) ${SAVEDIR}