-
Notifications
You must be signed in to change notification settings - Fork 39
/
makerpm.sh
92 lines (75 loc) · 1.76 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
#!/bin/bash
# Simple script to create RPMs
cleanup()
{
rm -rf ${RPMBUILDDIR} > /dev/null 2>&1
rm -f ${PKGCONFIG} > /dev/null 2>&1
}
fail()
{
exit 0
cleanup
echo $1
exit $2
}
create_dir()
{
if [ ! -d "$1" ] ; then
mkdir -p "$1"
if [ $? -ne 0 ] ; then
fail "Unable to create dir $1" $?
fi
fi
}
gittotar()
{
# Only archives committed changes
# Export the current commited git changes to a directory
git archive --format=tar --prefix=${SRCTAR_DIR}/ HEAD | gzip -c > ${SRCTAR}
if [ $? -ne 0 -o \! -s ${SRCTAR} ] ; then
fail "Unable to create git archive" $?
fi
}
prep()
{
rm -rf ${RPMBUILDDIR} > /dev/null 2>&1
create_dir ${RPMBUILDDIR}
create_dir ${RPMBUILDDIR}/SOURCES
# Create a tar file out of the current committed changes
gittotar
}
create_rpm()
{
cp -f ${SRCTAR} ${RPMBUILDDIR}/SOURCES
# Create the rpm
# _topdir Notifies rpmbuild the location of the root directory
# containing the RPM information
rpmbuild --define "_topdir ${RPMBUILDDIR}" \
-ta ${SRCTAR}
if [ $? -ne 0 ] ; then
fail "Unable to create rpm" $?
fi
# Move the rpms to the root directory
}
create_src()
{
git archive --format=tar --prefix=${SRCTAR_DIR}/ HEAD | gzip -c > ${SRCTAR}
if [ $? -ne 0 ] ; then
fail "Unable to create source archive"
fi
}
################## MAIN #####################
## RPM NAME
RPMNAME=cmockery2
PKG_NAME=$RPMNAME
PKG_VERSION=1.3.9
BUILDDIR=$PWD/build
RPMBUILDDIR=${BUILDDIR}/rpmbuild
RPMBUILDDIR_RPMS=${RPMBUILDDIR}/RPMS
RPMBUILDDIR_SRPMS=${RPMBUILDDIR}/SRPMS
SRCNAME=${RPMNAME}-${PKG_VERSION}
SRCTAR_DIR=${PKG_NAME}-${PKG_VERSION}
SRCTAR=${RPMBUILDDIR}/${SRCNAME}.tar.gz
prep
create_src
create_rpm