-
Notifications
You must be signed in to change notification settings - Fork 0
/
makerpm.sh
executable file
·99 lines (77 loc) · 2.19 KB
/
makerpm.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
#!/bin/bash
if [ ! -d /data ] ; then
echo "usage: docker run -it --rm -v <rpmbuild-dir>:/data -v <repo-dir>:/data/REPO grossws/makerpm pkg1.spec|pkg1.src.rpm pkg2.spec|pkg2.src.rpm ..."
echo " \`rpmbuild-dir\` should contain at least SPECS dir with specs mentioned"
echo " if some local SOURCES are required for building rpm they should be present in /data/SOURCES"
exit 1
fi
set -e
BASE=/data
RPMB=/makerpm/rpmbuild
cd /makerpm
cleantree() {
rm -rf ${RPMB}
su - makerpm -c 'rpmdev-setuptree'
}
cleantree
# internal repo
REPO_ID=$(source /etc/os-release ; echo ${ID}/${VERSION_ID})
REPO=/makerpm/repo/${REPO_ID}/$(uname -m)
mkdir -p ${REPO}
createrepo ${REPO}
echo <<EOF > /etc/yum.repos.d/makerpm.repo
[makerpm]
name = makerpm local repo
baseurl = file://${REPO}
enabled = 1
protect = 0
gpgcheck = 0
EOF
# output dirs
OUT=${BASE}/REPO/${REPO_ID}
OUT_RPMS=${OUT}/$(uname -m)
OUT_SRPMS=${OUT}/SRPMS
mkdir -p ${OUT_RPMS}
mkdir -p ${OUT_SRPMS}
buildspec() {
spec=$1
echo "Copy spec and sources"
cp -f ${BASE}/SPECS/${spec} ${RPMB}/SPECS/
if [ -d ${BASE}/SOURCES ] ; then
cp -rf ${BASE}/SOURCES/* ${RPMB}/SOURCES/
fi
chown -R makerpm:users ~makerpm
echo "Building ${spec}"
su - makerpm -c "spectool -g -R rpmbuild/SPECS/${spec}"
yum-builddep -y rpmbuild/SPECS/${spec}
su - makerpm -c "rpmbuild -ba rpmbuild/SPECS/${spec}"
echo "Finished building ${spec}"
}
buildsrpm() {
srpm=$1
echo "Building ${srpm}"
yum-builddep -y ${BASE}/${srpm}
su - makerpm -c "rpmbuild --rebuild ${BASE}/${srpm}"
echo "Finished building ${srpm}"
}
for pkg in "$@" ; do
if [[ "$pkg" == *.src.rpm ]] ; then
buildsrpm "$pkg"
elif [[ "$pkg" == *.spec ]] ; then
buildspec "${pkg##*/}"
else
echo "Unknown package type: $pkg"
exit 1
fi
echo "Copy rpms and srpms"
find ${RPMB}/RPMS/ -name '*.rpm' -print0 | xargs -0 -r cp -vft ${OUT_RPMS}/
find ${RPMB}/SRPMS/ -name '*.rpm' -print0 | xargs -0 -r cp -vft ${OUT_SRPMS}/
echo "Rebuild makerpm repo"
find ${RPMB}/RPMS/ -name '*.rpm' -print0 | xargs -0 -r cp -ft ${REPO}/
createrepo ${REPO}
cleantree
done
echo "Making repo in ${OUT_RPMS} and ${OUT_SRPMS}"
createrepo ${OUT_RPMS}
createrepo ${OUT_SRPMS}
echo "Done"