blob: 938a7a8496022903095af4c3ea42d16e24bbb391 (
plain)
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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
|
#!/bin/sh
DESTDIR=/tmp/$0.$UID.build
CLEAN=0
DIST=fedora-18-local-x86_64
SYSTEM=Fedora
PACKAGE_PATH_BASE=$HOME/.specs
VERBOSE=0
MAKEREPO=
NOTIFY=0
ARGS="$0 $@"
BRANCH=
MOCKDIR=/var/lib/mock
MOCKCONF=/etc/mock
PACKAGES=
function die
{
echo $@ >&2
exit 1
}
function get_mock_path
{
FILE="$MOCKCONF/$1.cfg"
NAME=$(sed -n "s,^config_opts\['root'\]\s*=\s*'\(.*\)'.*$,\1,p" $FILE)
echo $MOCKDIR/$NAME
}
function alert
{
notify-send --urgency=low -- "$1" "$2"
}
function make_repo
{
REPODIR=$1
SCANPATH=$2
if [ ! -d $REPODIR ]
then
mkdir -p $REPODIR
fi
if [ ! -w $REPODIR ]
then
echo "You don't have access to $REPODIR" >&2
return 1
fi
rm -rf $REPODIR/*
find $SCANPATH \( -name '*.rpm' -a ! -path '*/.repo/*' \) -exec cp {} $REPODIR \;
createrepo -o $REPODIR $REPODIR
ls -lahR $REPODIR > $REPODIR/files.txt
}
while [ $# -gt 0 ]
do
OPTION=$1
shift
case $OPTION in
--base-path)
PACKAGE_PATH_BASE=$1
shift
;;
-b|--build)
DESTDIR=$1
shift
;;
-c|--clean)
CLEAN=1
;;
-d|--dist)
DIST=$1
shift
;;
--list-pkgs)
for path in $(find $PACKAGE_PATH_BASE -maxdepth 2 -name '*.spec')
do
echo $(basename $(dirname $path))
done
exit 0
;;
--list-dists)
for profile in $(find $MOCKCONF -name '*.cfg' -printf '%f\n')
do
echo ${profile:0: -4}
done
exit 0
;;
-v|--verbose)
VERBOSE=1
;;
-m|--make-repo)
MAKEREPO=$1
shift
;;
-N|--notify)
NOTIFY=1
;;
--branch)
BRANCH=$1
shift
;;
-h|--help)
echo "Build SPEC file from a package in $PACKAGE_PATH_BASE
usage: $0 [ options ] < package name >
options:
--base-path Specify base path for spec searches (default: $PACKAGE_PATH_BASE)
-b --build Specify output for source/built RPMs (default: $DESTDIR)
--branch Change branch before building
-c --clean Clean build directory before building
-d --dist Specify distribution (mock profile name) (default: $DIST)
--list-pkgs List packages that can be built
--list-dists List available distributions
-v --verbose Enable verbose run
-m --make-repo Add build results to given repository
-N --notify Send DBus notification when done
-h --help Show this help file"
exit 1
;;
--)
PACKAGES="$PACKAGES $@"
break
;;
-*)
echo "Unkown option $OPTION" >&2
exit 1
;;
*)
PACKAGES="$PACKAGES $OPTION"
;;
esac
done
[ "x$PACKAGES" = "x" ] && die Missing package name
[ $VERBOSE -ne 0 ] && set -x
if [ $CLEAN -eq 1 ]
then
rm -rf $DESTDIR/*
fi
if [ -e $DESTDIR ]
then
if [ ! -d $DESTDIR ]
then
die "$DESTDIR not a directory"
fi
if [ ! -w $DESTDIR ]
then
die "You don't have access to $DESTDIR"
fi
fi
mkdir -p $DESTDIR/srpm
mkdir -p $DESTDIR/rpm
BASE_DIR=$(pwd)
cd $DESTDIR
DESTDIR=$(pwd)
cd $BASE_DIR
for PACKAGE in $PACKAGES
do
PACKAGE_PATH=$PACKAGE_PATH_BASE/$PACKAGE
if [ ! -d $PACKAGE_PATH ]
then
echo "$PACKAGE_PATH not found"
continue
fi
SPECFILE=$(find $PACKAGE_PATH/ -name '*.spec' | head -1)
if [ "x$SPECFILE" = "x" ]
then
echo "$PACKAGE_PATH contains no spec file"
continue
fi
if [ "x$BRANCH" != "x" ]
then
cd $PACKAGE_PATH
git checkout $BRANCH
CODE=$?
cd -
if [ $CODE -ne 0 ]
then
echo "$PACKAGE_PATH has no branch $BRANCH; skipping" >&2
continue
fi
fi
mock --buildsrpm --spec $SPECFILE --sources $PACKAGE_PATH -r $DIST
if [ $? -ne 0 ]
then
echo "Mock failed to create srpm from $SPECFILE"
continue
fi
DISTPATH=$(get_mock_path $DIST)/result
SRPM=$(find $DISTPATH -name '*.src.rpm' -printf '%f\n' | head -1)
cp $DISTPATH/$SRPM $DESTDIR/srpm
mock -r $DIST --rebuild $DESTDIR/srpm/$SRPM
if [ $? -ne 0 ]
then
echo "Mock failed to build $SRPM"
continue
fi
find $DISTPATH \( -name '*.rpm' -a ! -name '*.src.rpm' \) -exec cp {} $DESTDIR/rpm \;
cd $BASE_DIR
done
if [ "x$MAKEREPO" != "x" ]
then
make_repo $MAKEREPO $DISTPATH
fi
if [ $NOTIFY -ne 0 ]
then
alert "Build complete" "$ARGS"
fi
|