1 | #!/bin/bash |
---|
2 | # -*- coding: utf-8-unix -*- |
---|
3 | |
---|
4 | TEXTDOMAIN=vbootstrap |
---|
5 | TEXTDOMAINDIR=/usr/share/locale |
---|
6 | |
---|
7 | Usage(){ |
---|
8 | cat<<EOF |
---|
9 | Usage: $(basename $0) {--version [version]} {--arch [arch]} {--category [categories]} {--dist-upgrade} {--target [target]} {--with-compat32} {--rpmbuild-define [macro_expr]} {--rpmbuild-with [bcond_with]} {--rpmbuild-without [bcond_with]} {--sign} {--no-install} {--bootstrap-dir [directory]} {--cache-dir [directory]} {--built-rpms-dir [directory]} {clean|build|build-rpm [src.rpm]|install-rpm [arch.rpm|package]|remove-rpm [package]|show-info} |
---|
10 | |
---|
11 | Options: |
---|
12 | --version: set [version] (default: ${DEFAULT_VERSION}) |
---|
13 | --arch: set [arch] (default: $(uname -i)) |
---|
14 | --category: set [categories] (default: ${CATEGORIES}) |
---|
15 | --dist-upgrade: make VineSeed bootstrap via ${STABLE_VERSION} |
---|
16 | --unionfs: cover a bootstrap with unionfs |
---|
17 | --target: build rpms with [target] |
---|
18 | --with-compat32: build rpms with compat32 on boostrap |
---|
19 | --rpmbuild-define: give a option --define [macro_expr] to rpmbuild |
---|
20 | --rpmbuild-with: give a option --with [bcond_with] to rpmbuild |
---|
21 | --rpmbuild-without: give a option --without [bcond_with] to rpmbuild |
---|
22 | --sign: sign built rpms |
---|
23 | --no-install: build only a source rpm - do NOT install a built rpm |
---|
24 | --bootstrap-dir: set a bootstrap directory (default: ${VBOOTSTRAP_DIR}) |
---|
25 | --cache-dir: set a directory to cache rpms (default: ${CACHE_DIR}) |
---|
26 | --built-rpms-dir: set a directory to store built rpms in chroot (default: ${BUILT_RPMS_DIR}) |
---|
27 | |
---|
28 | Actions: |
---|
29 | clean: clean the boostrap of [version] |
---|
30 | build: build a boostrap of [version] |
---|
31 | build-rpm: build [src.rpm] on a boostrap |
---|
32 | install-rpm: install [arch.rpm|package] on a boostrap |
---|
33 | remove-rpm: remove [package] on a boostrap |
---|
34 | show-info: show basic informations and logs in chroot |
---|
35 | |
---|
36 | For example, |
---|
37 | * make a clean/plain build environment on the current archtecture: |
---|
38 | $(basename $0) clean build |
---|
39 | * build rpms from the specified source rpm: |
---|
40 | $(basename $0) build-rpm [src.rpm] |
---|
41 | * make a plain build environment for Vine Linux 4.2: |
---|
42 | $(basename $0) --version 4.2 clean build |
---|
43 | * make a i386 chroot on x86_64: |
---|
44 | $(basename $0) --arch i386 clean build |
---|
45 | * build a kernel package with target i686: |
---|
46 | $(basename $0) --target i686 build-rpm [kernel src.rpm] |
---|
47 | * build a compat32 package: |
---|
48 | $(basename $0) --arch i386 --with-compat32 build-rpm [src.rpm] |
---|
49 | $(/usr/sbin/vbootstrap | sed -e s/^Usage:.*// -e s/^E:.*//) |
---|
50 | EOF |
---|
51 | } |
---|
52 | |
---|
53 | ############################################################################## |
---|
54 | |
---|
55 | check-parameter(){ |
---|
56 | [ -z "$*" ] && Usage && return 1 |
---|
57 | |
---|
58 | while [ ! -z "$*" ]; do |
---|
59 | case $1 in |
---|
60 | --help|help) |
---|
61 | Usage |
---|
62 | return 1 |
---|
63 | ;; |
---|
64 | --version|--arch|--category|--target|--rpmbuild-define|--rpmbuild-with|--rpmbuild-without|--bootstrap-dir|--cache-dir|--built-rpms-dir) |
---|
65 | [ $with_actions -eq 1 ] && \ |
---|
66 | echo $"E: You can give no more options after actions" && \ |
---|
67 | return 1 |
---|
68 | shift |
---|
69 | check-next-parameter $1 || return 1 |
---|
70 | ;; |
---|
71 | --dist-upgrade|--unionfs|--with-compat32|--sign|--no-install) |
---|
72 | [ $with_actions -eq 1 ] && \ |
---|
73 | echo $"E: You can give no more options after actions" && \ |
---|
74 | return 1 |
---|
75 | ;; |
---|
76 | --build-rpm|build-rpm|--install-rpm|install-rpm|--remove-rpm|remove-rpm) |
---|
77 | with_actions=1 |
---|
78 | shift |
---|
79 | check-next-parameter $1 || return 1 |
---|
80 | ;; |
---|
81 | --build|build|--clean|clean|--show-info|show-info) |
---|
82 | with_actions=1 |
---|
83 | ;; |
---|
84 | *) |
---|
85 | echo $"E: Missing some parameters after $1" |
---|
86 | return 1 |
---|
87 | ;; |
---|
88 | esac |
---|
89 | shift |
---|
90 | done |
---|
91 | |
---|
92 | [ $with_actions -eq 0 ] && \ |
---|
93 | echo $"E: You must give at least one action" && return 1 |
---|
94 | |
---|
95 | return 0 |
---|
96 | } |
---|
97 | |
---|
98 | check-next-parameter(){ |
---|
99 | [ -z "$1" ] && echo $"E: Missing some parameters after $1" && return 1 |
---|
100 | |
---|
101 | [ $(echo $1 | grep '^-') ] && \ |
---|
102 | echo $"E: Missing some parameters after $1" && return 1 |
---|
103 | |
---|
104 | return 0 |
---|
105 | } |
---|
106 | |
---|
107 | setup-vbuilder(){ |
---|
108 | ## load default settings |
---|
109 | VBUILDER_CONF=/etc/vbootstrap/vbuilder.conf |
---|
110 | if [ -r $VBUILDER_CONF ]; then |
---|
111 | . $VBUILDER_CONF |
---|
112 | [ $? -eq 1 ] && return 1 |
---|
113 | fi |
---|
114 | [ -z "${DEFAULT_VERSION}" ] && \ |
---|
115 | DEFAULT_VERSION=@@VBUILDER_DEFAULT_VERSION@@ |
---|
116 | [ -z "${CATEGORIES}" ] && \ |
---|
117 | CATEGORIES=@@VBUILDER_CATEGORIES@@ |
---|
118 | [ -z "${VBOOTSTRAP_DIR}" ] && \ |
---|
119 | VBOOTSTRAP_DIR=@@VBUILDER_VBOOTSTRAP_DIR@@ |
---|
120 | [ -z "${CACHE_DIR}" ] && \ |
---|
121 | CACHE_DIR=@@VBUILDER_CACHE_DIR@@ |
---|
122 | [ -z "${BUILT_RPMS_DIR}" ] && \ |
---|
123 | BUILT_RPMS_DIR=@@VBUILDER_BUILT_RPMS_DIR@@ |
---|
124 | |
---|
125 | ## set default version for vbootstrap |
---|
126 | VERSION=$DEFAULT_VERSION |
---|
127 | |
---|
128 | ## set current stable relase version |
---|
129 | STABLE_VERSION=@@VBUILDER_STABLE_VERSION@@ |
---|
130 | |
---|
131 | ## set boolian |
---|
132 | with_setup_vbootstrap=0 |
---|
133 | with_dist_upgrade=0 |
---|
134 | with_unionfs=0 |
---|
135 | with_sign=0 |
---|
136 | with_no_install=0 |
---|
137 | with_actions=0 |
---|
138 | with_ix86_on_x86_64=0 |
---|
139 | with_category_main=0 |
---|
140 | with_category_plus=0 |
---|
141 | with_category_nonfree=0 |
---|
142 | with_category_test=0 |
---|
143 | with_category_proposed_updates=0 |
---|
144 | with_category_security=0 |
---|
145 | |
---|
146 | return 0 |
---|
147 | } |
---|
148 | |
---|
149 | setup-vbootstrap(){ |
---|
150 | if [ ${with_setup_vbootstrap} -eq 0 ]; then |
---|
151 | with_setup_vbootstrap=1 |
---|
152 | |
---|
153 | ## check some directories |
---|
154 | ## Note: create $BUILT_RPMS_DIR in RPM_Build() |
---|
155 | [ -d $VBOOTSTRAP_DIR ] || mkdir -p $VBOOTSTRAP_DIR |
---|
156 | [ -d $CACHE_DIR ] || mkdir -p $CACHE_DIR |
---|
157 | |
---|
158 | ## check a chroot archtecture |
---|
159 | if [ -z ${VARCH} ]; then |
---|
160 | VARCH=$(uname -i) |
---|
161 | else |
---|
162 | case "${VARCH}" in |
---|
163 | i386|i686|x86_64) |
---|
164 | [ "$(uname -i)" = "ppc" ] && \ |
---|
165 | echo $"E: arch ${VARCH} is NOT supported on $(uname -i)" && return 1 |
---|
166 | ;; |
---|
167 | ppc) |
---|
168 | [ "$(uname -i)" = "i386" -o "$(uname -i)" = "i686" -o "$(uname -i)" = "x86_64" ] && \ |
---|
169 | echo $"E: arch ${VARCH} is NOT supported on $(uname -i)" && return 1 |
---|
170 | ;; |
---|
171 | esac |
---|
172 | fi |
---|
173 | |
---|
174 | ##!! 4.2 is NO support on VARCH=x86_64 |
---|
175 | if [ "${VERSION}" = "4.2" -a "${VARCH}" = "x86_64" ]; then |
---|
176 | echo $"E: ${VERSION} is NOT supported" |
---|
177 | return 1 |
---|
178 | fi |
---|
179 | |
---|
180 | ## support i386 chroot on x86_64 below: |
---|
181 | [ "${VARCH}" != "$(uname -i)" ] && \ |
---|
182 | VERSION=${VERSION}_${VARCH} && \ |
---|
183 | with_ix86_on_x86_64=1 |
---|
184 | |
---|
185 | ## check support ${VERSION} |
---|
186 | if [ -z "$(/usr/sbin/vbootstrap | sed -e s/^Usage:.*// -e s/^E:.*// | grep -m 1 ${VERSION})" ]; then |
---|
187 | echo $"E: ${VERSION} is NOT supported" |
---|
188 | return 1 |
---|
189 | fi |
---|
190 | |
---|
191 | ## check ${VERSION} equals VineSeed*, when with_dist_upgrade=1 |
---|
192 | if [ $with_dist_upgrade -eq 1 ]; then |
---|
193 | if [ "$(echo ${VERSION} | sed -e "s/\(VineSeed\).*/\1/")" != "VineSeed" ]; then |
---|
194 | echo $"E: version ${VERSION} does not support --dist-upgrade option" |
---|
195 | return 1 |
---|
196 | fi |
---|
197 | fi |
---|
198 | |
---|
199 | ## set ${MAJOR_VERSION} |
---|
200 | MAJOR_VERSION=$(echo ${VERSION} | sed -e "s/_i[0-9]86//") |
---|
201 | |
---|
202 | ## check apt categories |
---|
203 | ## "main" category is unconditionally permited |
---|
204 | with_category_main=1 |
---|
205 | for cat in $(echo ${CATEGORIES} | sed -e "s/,/ /"g); do |
---|
206 | case $cat in |
---|
207 | main) |
---|
208 | with_category_main=1 |
---|
209 | ;; |
---|
210 | plus) |
---|
211 | with_category_plus=1 |
---|
212 | ;; |
---|
213 | nonfree) |
---|
214 | with_category_nonfree=1 |
---|
215 | ;; |
---|
216 | test) |
---|
217 | ## "test" category only exists in VineSeed |
---|
218 | [ "${MAJOR_VERSION}" = "VineSeed" ] || \ |
---|
219 | echo $"E: No such category exists: $cat" && return 1 |
---|
220 | with_category_test=1 |
---|
221 | ;; |
---|
222 | proposed-updates) |
---|
223 | ##!! "proposed-updates" category does not exist in 4.2 |
---|
224 | [ "${MAJOR_VERSION}" = "4.2" ] && \ |
---|
225 | echo $"E: No such category exists: $cat" && return 1 |
---|
226 | |
---|
227 | with_category_proposed_updates=1 |
---|
228 | ;; |
---|
229 | security) |
---|
230 | ## "security" category does not exist in VineSeed |
---|
231 | [ "${MAJOR_VERSION}" = "VineSeed" ] && \ |
---|
232 | echo $"E: No such category exists: $cat" && return 1 |
---|
233 | with_category_security=1 |
---|
234 | ;; |
---|
235 | *) |
---|
236 | echo $"E: No such category exists: $cat" && return 1 |
---|
237 | ;; |
---|
238 | esac |
---|
239 | done |
---|
240 | |
---|
241 | ## check build target option ${TARGET} |
---|
242 | if [ ! -z "${TARGET}" ]; then |
---|
243 | RPM_TARGET_LIST="$(cat /usr/lib/rpm/rpmrc | grep arch_canon: | sed -e "s/arch_canon:[[:blank:]]*\(.*\):.*/\1/")" |
---|
244 | if [ -z "$(echo $RPM_TARGET_LIST | grep $TARGET)" ]; then |
---|
245 | echo $"E: rpm build target ${TARGET} is NOT supported" |
---|
246 | return 1 |
---|
247 | fi |
---|
248 | fi |
---|
249 | |
---|
250 | ## set ${RPM_PKG_ARCH_LIST} |
---|
251 | RPM_PKG_ARCH_LIST="RPMS/i386 RPMS/i686 RPMS/x86_64 RPMS/ppc RPMS/noarch SRPMS" |
---|
252 | [ -z "${TARGET}" ] || \ |
---|
253 | RPM_PKG_ARCH_LIST="RPMS/${TARGET} ${RPM_PKG_ARCH_LIST}" |
---|
254 | |
---|
255 | fi |
---|
256 | |
---|
257 | ## set global variables |
---|
258 | BUILD_ROOT=${VBOOTSTRAP_DIR}/${VERSION} |
---|
259 | BUILD_USER=vbuilder |
---|
260 | BUILD_DIR=/home/${BUILD_USER}/rpm |
---|
261 | UNIONFS_DIR=${VBOOTSTRAP_DIR}/unionfs/${VERSION} |
---|
262 | ARCHIVES_DIR=${BUILD_ROOT}/var/cache/apt/archives |
---|
263 | EXTERNAL_ARCHIVES_DIR=${CACHE_DIR}/${VERSION}/apt/archives |
---|
264 | VBUILDER_LOG=${BUILD_ROOT}/var/log/vbuilder.log |
---|
265 | |
---|
266 | __chroot_sh="/usr/sbin/chroot ${BUILD_ROOT} /bin/sh -c -l" |
---|
267 | |
---|
268 | mkdir -p $VBOOTSTRAP_DIR |
---|
269 | |
---|
270 | return 0 |
---|
271 | } |
---|
272 | |
---|
273 | setup-vbootstrap-rpm(){ |
---|
274 | setup-vbootstrap || return 1 |
---|
275 | |
---|
276 | ## check ${BUILD_ROOT} |
---|
277 | [ -d ${BUILD_ROOT} ] || Build |
---|
278 | ## setarch ix86 if ix86 chroot on x86_64 host |
---|
279 | [ $with_ix86_on_x86_64 -eq 1 ] && \ |
---|
280 | __chroot_sh="/usr/sbin/chroot ${BUILD_ROOT} setarch ${VARCH} /bin/sh -c -l" |
---|
281 | |
---|
282 | DIST_RELEASE=$(cat ${BUILD_ROOT}/etc/vine-release | cut -f3 -d" " | cut -f1 -d.) |
---|
283 | |
---|
284 | if [ -f $RPM_PKG ]; then |
---|
285 | BASE_RPM_PKG=$(basename $RPM_PKG) |
---|
286 | cp -f $RPM_PKG $BUILD_ROOT${BUILD_DIR} |
---|
287 | else |
---|
288 | BASE_RPM_PKG=$RPM_PKG |
---|
289 | fi |
---|
290 | |
---|
291 | return 0 |
---|
292 | } |
---|
293 | |
---|
294 | ## recover apt-get data on host/chroot |
---|
295 | apt-get-update(){ |
---|
296 | case $1 in |
---|
297 | --host) |
---|
298 | echo -n $"apt-get update on host ... " |
---|
299 | apt-get -qq update > /dev/null 2>&1 |
---|
300 | echo $"done." |
---|
301 | ;; |
---|
302 | --chroot) |
---|
303 | echo -n $"apt-get update on chroot ... " |
---|
304 | $__chroot_sh 'apt-get -qq update' > /dev/null 2>&1 |
---|
305 | echo $"done." |
---|
306 | ;; |
---|
307 | *) |
---|
308 | echo apt-get-update: unknown option $1 |
---|
309 | exit 1 |
---|
310 | ;; |
---|
311 | esac |
---|
312 | } |
---|
313 | |
---|
314 | ## mount-chroot {|--umount} [file system|name] |
---|
315 | ## support file systems: /home /tmp /sys /proc /dev/shm /dev/pts /dev |
---|
316 | ## support names: vfs archives_dir |
---|
317 | ## NOTE: /tmp needs for applications which use X |
---|
318 | ## vfs is virtual file systems |
---|
319 | ## archives_dir uses to mount ${EXTERNAL_ARCHIVES_DIR} to ${ARCHIVES_DIR} |
---|
320 | ## unionfs_dir covers ${BUILD_ROOT} with unionfs |
---|
321 | mount-chroot(){ |
---|
322 | if [ "$1" = "--umount" ]; then |
---|
323 | mount-chroot-umount $2 || return 1 |
---|
324 | else |
---|
325 | mount-chroot-mount $1 || return 1 |
---|
326 | fi |
---|
327 | return 0 |
---|
328 | } |
---|
329 | |
---|
330 | ## mount-chroot-umount [file system|name] |
---|
331 | mount-chroot-umount(){ |
---|
332 | local fs=$1 |
---|
333 | case $fs in |
---|
334 | /home|/tmp|/sys|/proc|/dev/shm|/dev/pts|/dev) |
---|
335 | [ -d ${BUILD_ROOT}${fs} ] || return 1 |
---|
336 | [ -z "$(mount | grep ${BUILD_ROOT}${fs})" ] || \ |
---|
337 | umount ${BUILD_ROOT}${fs} |
---|
338 | if [ ! -z "$(mount | grep ${BUILD_ROOT}${fs})" ]; then |
---|
339 | echo $"Retry lazy unmount ${BUILD_ROOT}${fs} ... " |
---|
340 | umount -l ${BUILD_ROOT}${fs} |
---|
341 | echo $"done." |
---|
342 | fi |
---|
343 | ;; |
---|
344 | vfs) |
---|
345 | # for dir in /sys /proc /dev/shm /dev/pts /dev; do |
---|
346 | # mount-chroot-umount ${dir} || return 1 |
---|
347 | # done |
---|
348 | [ -d ${BUILD_ROOT}/proc ] || return 1 |
---|
349 | [ -z "$(mount | grep ${BUILD_ROOT}/proc)" ] || \ |
---|
350 | umount ${BUILD_ROOT}/proc |
---|
351 | ;; |
---|
352 | archives_dir) |
---|
353 | [ -d ${ARCHIVES_DIR} ] || return 1 |
---|
354 | [ -z "$(mount | grep ${ARCHIVES_DIR})" ] || \ |
---|
355 | umount ${ARCHIVES_DIR} |
---|
356 | ;; |
---|
357 | unionfs_dir) |
---|
358 | [ -d ${BUILD_ROOT} ] || return 1 |
---|
359 | [ -z "$(mount | grep ${BUILD_ROOT} | grep unionfs)" ] || \ |
---|
360 | umount ${BUILD_ROOT} |
---|
361 | if [ ! -z "$(mount | grep ${BUILD_ROOT} | grep unionfs)" ]; then |
---|
362 | echo $"Retry lazy unmount ${BUILD_ROOT} ... " |
---|
363 | umount -l ${BUILD_ROOT} |
---|
364 | echo $"done." |
---|
365 | fi |
---|
366 | ;; |
---|
367 | *) |
---|
368 | echo mount-chroot-umount: unknown file system $fs |
---|
369 | exit 1 |
---|
370 | ;; |
---|
371 | esac |
---|
372 | return 0 |
---|
373 | } |
---|
374 | |
---|
375 | ## mount-chroot-mount [file system|name] |
---|
376 | mount-chroot-mount(){ |
---|
377 | local fs=$1 |
---|
378 | local mnt_opts="" |
---|
379 | |
---|
380 | case $fs in |
---|
381 | /home) |
---|
382 | mnt_opts="-o _netdev,rbind" |
---|
383 | ;; |
---|
384 | *) |
---|
385 | mnt_opts="--bind -o _netdev" |
---|
386 | ;; |
---|
387 | esac |
---|
388 | |
---|
389 | case $fs in |
---|
390 | /home|/tmp|/sys|/proc|/dev/shm|/dev/pts|/dev) |
---|
391 | [ -d ${BUILD_ROOT}${fs} ] || mkdir -p ${BUILD_ROOT}${fs} |
---|
392 | [ -z "$(mount | grep ${BUILD_ROOT}${fs})" ] && \ |
---|
393 | mount ${mnt_opts} ${fs} ${BUILD_ROOT}${fs} |
---|
394 | ;; |
---|
395 | vfs) |
---|
396 | # for dir in /dev /dev/pts /dev/shm /proc /sys; do |
---|
397 | # mount-chroot-mount ${dir} || return 1 |
---|
398 | # done |
---|
399 | mount-chroot-mount /proc || return 1 |
---|
400 | ;; |
---|
401 | archives_dir) |
---|
402 | [ -d ${EXTERNAL_ARCHIVES_DIR} ] || mkdir -p ${EXTERNAL_ARCHIVES_DIR} |
---|
403 | [ -d ${ARCHIVES_DIR} ] || mkdir -p ${ARCHIVES_DIR} |
---|
404 | [ -z "$(mount | grep ${ARCHIVES_DIR})" ] && \ |
---|
405 | mount ${mnt_opts} ${EXTERNAL_ARCHIVES_DIR} ${ARCHIVES_DIR} |
---|
406 | [ -d ${ARCHIVES_DIR}/partial ] || mkdir -p ${ARCHIVES_DIR}/partial |
---|
407 | ;; |
---|
408 | unionfs_dir) |
---|
409 | if [ $with_unionfs -eq 1 ]; then |
---|
410 | [ -d ${UNIONFS_DIR} ] || mkdir -p ${UNIONFS_DIR} |
---|
411 | [ -z "$(mount | grep ${BUILD_ROOT})" ] && \ |
---|
412 | mount -t unionfs -o dirs=${UNIONFS_DIR}=rw:${BUILD_ROOT}=ro unionfs ${BUILD_ROOT} |
---|
413 | unionctl ${BUILD_ROOT} --list |
---|
414 | fi |
---|
415 | ;; |
---|
416 | *) |
---|
417 | echo mount-chroot-mount: unknown file system $fs |
---|
418 | exit 1 |
---|
419 | ;; |
---|
420 | esac |
---|
421 | return 0 |
---|
422 | } |
---|
423 | |
---|
424 | write-vbuilder-log(){ |
---|
425 | HRULE="======================================================================" |
---|
426 | |
---|
427 | [ -d ${BUILD_ROOT} ] || return 1 |
---|
428 | |
---|
429 | if [ ! -f $VBUILDER_LOG ]; then |
---|
430 | cat<<EOF > $VBUILDER_LOG |
---|
431 | ${HRULE} |
---|
432 | VBUILDER REPORT |
---|
433 | DATE: $(LANG=C date) |
---|
434 | HOSTNAME: $(hostname) |
---|
435 | OS: $(echo $($__chroot_sh "cat /etc/vine-release")) |
---|
436 | %_arch: $(echo $($__chroot_sh "rpm --eval %_arch")) |
---|
437 | |
---|
438 | --version: ${VERSION} |
---|
439 | $(echo $([ -z "${VARCH}" ] || echo "--arch: ${VARCH}")) |
---|
440 | $(echo $([ -z "${CATEGORIES}" ] || echo "--category: ${CATEGORIES}")) |
---|
441 | $(echo $([ $with_dist_upgrade -eq 1 ] && echo "--dist-upgrade")) |
---|
442 | $(echo $([ $with_unionfs -eq 1 ] && echo "--unionfs")) |
---|
443 | $(echo $([ -z "${TARGET}" ] || echo "--target: ${TARGET}")) |
---|
444 | --bootstrap-dir: ${VBOOTSTRAP_DIR} |
---|
445 | --cache-dir: ${CACHE_DIR} |
---|
446 | --built-rpms-dir: ${BUILT_RPMS_DIR} |
---|
447 | ${HRULE} |
---|
448 | |
---|
449 | [$VBUILDER_CONF] |
---|
450 | $(cat $VBUILDER_CONF) |
---|
451 | |
---|
452 | [History] |
---|
453 | EOF |
---|
454 | else |
---|
455 | cat<<EOF >> $VBUILDER_LOG |
---|
456 | $* |
---|
457 | EOF |
---|
458 | fi |
---|
459 | |
---|
460 | return 0 |
---|
461 | } |
---|
462 | |
---|
463 | ## user_from_uid [uid] |
---|
464 | user_from_uid () { |
---|
465 | ## check whether or not $1 is a number |
---|
466 | ! echo $1 | egrep -q '[^0-9]' || return 1 |
---|
467 | |
---|
468 | # look for the corresponding name in /etc/passwd |
---|
469 | local IFS=":" |
---|
470 | while read name x uid the_rest; do |
---|
471 | [ "$1" = "$uid" ] && echo "$name" && return 0 |
---|
472 | done < /etc/passwd |
---|
473 | |
---|
474 | # if nothing was found, return false |
---|
475 | return 1 |
---|
476 | } |
---|
477 | |
---|
478 | |
---|
479 | ############################################################################## |
---|
480 | |
---|
481 | Clean(){ |
---|
482 | setup-vbootstrap || return 1 |
---|
483 | |
---|
484 | # # output end-of-line in $VBUILDER_LOG |
---|
485 | # [ -f $VBUILDER_LOG ] && write-vbuilder-log ${HRULE} |
---|
486 | # Show-Info |
---|
487 | |
---|
488 | # mount-chroot --umount /home |
---|
489 | # mount-chroot --umount /tmp |
---|
490 | mount-chroot --umount vfs |
---|
491 | mount-chroot --umount archives_dir |
---|
492 | mount-chroot --umount unionfs_dir |
---|
493 | apt-get-update --host |
---|
494 | |
---|
495 | if [ $with_unionfs -eq 1 ]; then |
---|
496 | if [ -d ${UNIONFS_DIR} ]; then |
---|
497 | echo -n $"Cleaning build root ${UNIONFS_DIR} via unionfs ... " |
---|
498 | rm -rf ${UNIONFS_DIR} |
---|
499 | echo $"done." |
---|
500 | fi |
---|
501 | else |
---|
502 | if [ -d ${BUILD_ROOT} ]; then |
---|
503 | echo -n $"Cleaning build root ${BUILD_ROOT} ... " |
---|
504 | rm -rf ${BUILD_ROOT} |
---|
505 | echo $"done." |
---|
506 | fi |
---|
507 | fi |
---|
508 | |
---|
509 | echo $"Cleanup a build farm for ${VERSION} done." |
---|
510 | return 0 |
---|
511 | } |
---|
512 | |
---|
513 | Build(){ |
---|
514 | setup-vbootstrap || return 1 |
---|
515 | |
---|
516 | if [ $with_dist_upgrade -eq 1 ]; then |
---|
517 | ## make bootstrap of ${STABLE_VERSION} |
---|
518 | /usr/sbin/vbootstrap \ |
---|
519 | $(echo ${VERSION} | sed -e "s/VineSeed/${STABLE_VERSION}/") \ |
---|
520 | ${BUILD_ROOT} |
---|
521 | |
---|
522 | ## aim apt-line to VineSeed |
---|
523 | sed -i "s/apt ${STABLE_VERSION}/apt VineSeed/g" \ |
---|
524 | ${BUILD_ROOT}/etc/apt/sources.list.d/main.list |
---|
525 | else |
---|
526 | /usr/sbin/vbootstrap ${VERSION} ${BUILD_ROOT} |
---|
527 | fi |
---|
528 | |
---|
529 | mount-chroot archives_dir |
---|
530 | mount-chroot vfs |
---|
531 | # mount-chroot /tmp |
---|
532 | # mount-chroot /home |
---|
533 | |
---|
534 | $__chroot_sh 'apt-get -qq update && apt-get -qq -y dist-upgrade' |
---|
535 | |
---|
536 | ##!! 4.2 has no apt-sourceslist-{plus,nonfree,proposed-updates} packages |
---|
537 | case ${MAJOR_VERSION} in |
---|
538 | 4.2) |
---|
539 | $__chroot_sh "sed -i -e 's/main plus updates nonfree *$/$(echo ${CATEGORIES} | sed -e "s/,/ /"g) updates/g' /etc/apt/sources.list" |
---|
540 | # [ $with_category_security -eq 1 ] && \ |
---|
541 | # echo |
---|
542 | ;; |
---|
543 | @@VBUILDER_STABLE_VERSION@@) |
---|
544 | [ $with_category_plus -eq 1 ] && \ |
---|
545 | $__chroot_sh 'apt-get -qq update && apt-get -qq -y install apt-sourceslist-plus' |
---|
546 | [ $with_category_nonfree -eq 1 ] && \ |
---|
547 | $__chroot_sh 'apt-get -qq update && apt-get -qq -y install apt-sourceslist-nonfree' |
---|
548 | [ $with_category_proposed_updates -eq 1 ] && \ |
---|
549 | $__chroot_sh 'apt-get -qq update && apt-get -qq -y install apt-sourceslist-proposed-updates' |
---|
550 | # [ $with_category_security -eq 1 ] && \ |
---|
551 | # echo |
---|
552 | ;; |
---|
553 | VineSeed) |
---|
554 | [ $with_category_plus -eq 1 ] && \ |
---|
555 | $__chroot_sh 'apt-get -qq update && apt-get -qq -y install apt-sourceslist-plus' |
---|
556 | [ $with_category_nonfree -eq 1 ] && \ |
---|
557 | $__chroot_sh 'apt-get -qq update && apt-get -qq -y install apt-sourceslist-nonfree' |
---|
558 | [ $with_category_test -eq 1 ] && \ |
---|
559 | $__chroot_sh 'apt-get -qq update && apt-get -qq -y install apt-sourceslist-test' |
---|
560 | ;; |
---|
561 | esac |
---|
562 | |
---|
563 | [ $with_dist_upgrade -eq 1 ] && \ |
---|
564 | $__chroot_sh 'apt-get -qq update && apt-get -qq -y dist-upgrade' |
---|
565 | |
---|
566 | $__chroot_sh 'apt-get -qq -y install build-essential' |
---|
567 | |
---|
568 | [ $with_category_nonfree -eq 1 ] && \ |
---|
569 | $__chroot_sh 'apt-get -qq -y install self-build-setup' |
---|
570 | |
---|
571 | $__chroot_sh 'apt-get -qq -y install etcskel shadow-utils' |
---|
572 | |
---|
573 | $__chroot_sh 'cd /dev && /sbin/MAKEDEV console' |
---|
574 | $__chroot_sh 'cd /dev && /sbin/MAKEDEV null' |
---|
575 | $__chroot_sh 'cd /dev && /sbin/MAKEDEV zero' |
---|
576 | $__chroot_sh 'cd /dev && /sbin/MAKEDEV random' |
---|
577 | $__chroot_sh 'cd /dev && /sbin/MAKEDEV urandom' |
---|
578 | |
---|
579 | $__chroot_sh '/usr/sbin/pwconv' |
---|
580 | $__chroot_sh "/usr/sbin/useradd ${BUILD_USER}" |
---|
581 | |
---|
582 | ##!! for rpm-4.8.0 or higher |
---|
583 | ##!! (See http://trac.vinelinux.org/wiki/Vine6/AboutUpdateToolchain) |
---|
584 | if [ "$(echo ${VERSION} | sed -e "s/\(VineSeed\).*/\1/")" = "VineSeed" ]; then |
---|
585 | $__chroot_sh "sed -i -e 's/^%_topdir/#%_topdir/' /home/${BUILD_USER}/.rpmmacros" |
---|
586 | fi |
---|
587 | |
---|
588 | ## output basic informations in chroot |
---|
589 | write-vbuilder-log |
---|
590 | write-vbuilder-log "build" |
---|
591 | |
---|
592 | # mount-chroot --umount /home |
---|
593 | # mount-chroot --umount /tmp |
---|
594 | mount-chroot --umount vfs |
---|
595 | mount-chroot --umount archives_dir |
---|
596 | apt-get-update --host |
---|
597 | |
---|
598 | echo $"Making a build farm for ${VERSION} done." |
---|
599 | return 0 |
---|
600 | } |
---|
601 | |
---|
602 | Show-Info(){ |
---|
603 | setup-vbootstrap || return 1 |
---|
604 | |
---|
605 | [ -f $VBUILDER_LOG ] && cat $VBUILDER_LOG |
---|
606 | |
---|
607 | return 0 |
---|
608 | } |
---|
609 | |
---|
610 | RPM_Remove(){ |
---|
611 | setup-vbootstrap-rpm || return 1 |
---|
612 | mount-chroot unionfs_dir |
---|
613 | mount-chroot archives_dir |
---|
614 | mount-chroot vfs |
---|
615 | apt-get-update --chroot |
---|
616 | |
---|
617 | [ -f $RPM_PKG ] && \ |
---|
618 | echo $"E: $RPM_PKG is not a package name" && return 1 |
---|
619 | $__chroot_sh "apt-get -y remove $BASE_RPM_PKG" |
---|
620 | |
---|
621 | write-vbuilder-log "remove-rpm $RPM_PKG" |
---|
622 | |
---|
623 | mount-chroot --umount vfs |
---|
624 | mount-chroot --umount archives_dir |
---|
625 | mount-chroot --umount unionfs_dir |
---|
626 | apt-get-update --host |
---|
627 | |
---|
628 | return 0 |
---|
629 | } |
---|
630 | |
---|
631 | RPM_Install(){ |
---|
632 | setup-vbootstrap-rpm || return 1 |
---|
633 | mount-chroot unionfs_dir |
---|
634 | mount-chroot archives_dir |
---|
635 | mount-chroot vfs |
---|
636 | apt-get-update --chroot |
---|
637 | |
---|
638 | $__chroot_sh "cd ${BUILD_DIR} && apt-get -y install $BASE_RPM_PKG" |
---|
639 | |
---|
640 | write-vbuilder-log "install-rpm $RPM_PKG" |
---|
641 | |
---|
642 | mount-chroot --umount vfs |
---|
643 | mount-chroot --umount archives_dir |
---|
644 | mount-chroot --umount unionfs_dir |
---|
645 | apt-get-update --host |
---|
646 | |
---|
647 | return 0 |
---|
648 | } |
---|
649 | |
---|
650 | RPM_Build(){ |
---|
651 | setup-vbootstrap-rpm || return 1 |
---|
652 | mount-chroot unionfs_dir |
---|
653 | mount-chroot archives_dir |
---|
654 | mount-chroot vfs |
---|
655 | apt-get-update --chroot |
---|
656 | |
---|
657 | [ ! -f $RPM_PKG ] && \ |
---|
658 | echo $"E: $RPM_PKG is not a source RPM package" && return 1 |
---|
659 | |
---|
660 | RPM_PKG_USER=$(stat -c %U $RPM_PKG) |
---|
661 | RPM_PKG_GROUP=$(stat -c %G $RPM_PKG) |
---|
662 | [ ! -z "${SUDO_UID}" ] && RPM_PKG_USER=${SUDO_UID} |
---|
663 | [ ! -z "${SUDO_GID}" ] && RPM_PKG_GROUP=${SUDO_GID} |
---|
664 | local __install="install -p -v -o ${RPM_PKG_USER} -g ${RPM_PKG_GROUP}" |
---|
665 | |
---|
666 | ## make src.rpm for $VERSION |
---|
667 | $__chroot_sh "cd ${BUILD_DIR} && su ${BUILD_USER} -c 'rpm -ivh $BASE_RPM_PKG'" |
---|
668 | $__chroot_sh "cd ${BUILD_DIR} && su ${BUILD_USER} -c 'rpmbuild -bs --nodeps --clean --rmsource --rmspec $RPM_OPTS ${BUILD_DIR}/SPECS/*.spec'" |
---|
669 | |
---|
670 | |
---|
671 | ## change ${DIST_RELEASE} |
---|
672 | BASE_RPM_PKG=$(echo $BASE_RPM_PKG | sed -e "s/vl[0-9]*\([A-Za-z]*\)\./vl${DIST_RELEASE}\1\./") |
---|
673 | |
---|
674 | ## rebuild $BASE_RPM_PKG on ${DIST_RELEASE} |
---|
675 | $__chroot_sh "cd ${BUILD_DIR}/SRPMS && apt-get -o APT::Install::Virtual=true -y build-dep $BASE_RPM_PKG" |
---|
676 | $__chroot_sh "cd ${BUILD_DIR}/SRPMS && su ${BUILD_USER} -c 'rpmbuild --rebuild $RPM_OPTS $BASE_RPM_PKG'" |
---|
677 | [ $with_no_install -eq 0 ] && \ |
---|
678 | $__chroot_sh "cd ${BUILD_DIR} && apt-get -y install $(find $BUILD_ROOT${BUILD_DIR}/RPMS -type f -regex '.*\.rpm' | sed -e s@${BUILD_ROOT}@@g -e 's|.*\/compat32-.*||g' -e 's|.*\/.*\.src\.rpm||g' -e 's/$/ \\/g')" |
---|
679 | |
---|
680 | ## copy built rpms to ${HOME}/rpm/ for each archtectures |
---|
681 | echo $"Copying built rpms to ${BUILT_RPMS_DIR} for each archtectures ... " |
---|
682 | for i in $RPM_PKG_ARCH_LIST; do \ |
---|
683 | if [ -d $BUILD_ROOT${BUILD_DIR}/${i} ]; then |
---|
684 | if [ ! -d ${BUILT_RPMS_DIR}/${MAJOR_VERSION}/${i} ]; then |
---|
685 | $__install -d ${BUILT_RPMS_DIR}/${MAJOR_VERSION}/${i}/ |
---|
686 | chown -R ${RPM_PKG_USER}:${RPM_PKG_GROUP} ${BUILT_RPMS_DIR} |
---|
687 | fi |
---|
688 | find $BUILD_ROOT${BUILD_DIR}/${i} -type f -regex '.*\.rpm' \ |
---|
689 | -exec $__install -m0644 {} ${BUILT_RPMS_DIR}/${MAJOR_VERSION}/${i}/ \; |
---|
690 | fi |
---|
691 | done |
---|
692 | |
---|
693 | write-vbuilder-log "build-rpm $RPM_PKG" |
---|
694 | |
---|
695 | mount-chroot --umount vfs |
---|
696 | mount-chroot --umount archives_dir |
---|
697 | mount-chroot --umount unionfs_dir |
---|
698 | apt-get-update --host |
---|
699 | |
---|
700 | echo $"done." |
---|
701 | return 0 |
---|
702 | } |
---|
703 | |
---|
704 | RPM_Sign(){ |
---|
705 | [ $with_sign -eq 1 ] || return 1 |
---|
706 | |
---|
707 | ## check $SUDO_USER and $USERHELPER_UID |
---|
708 | local RPM_SIGN_USER=$SUDO_USER |
---|
709 | if [ -z "${RPM_SIGN_USER}" ]; then |
---|
710 | RPM_SIGN_USER=$(user_from_uid $USERHELPER_UID) |
---|
711 | if [ -z "${RPM_SIGN_USER}" ]; then |
---|
712 | echo $"W: \$SUDO_USER and \$USERHELPER_UID are empty" |
---|
713 | return 1 |
---|
714 | fi |
---|
715 | fi |
---|
716 | |
---|
717 | setup-vbootstrap || return 1 |
---|
718 | |
---|
719 | [ -d ${BUILD_ROOT} ] || Build |
---|
720 | |
---|
721 | mount-chroot unionfs_dir |
---|
722 | |
---|
723 | echo $"Signing built rpms using ${RPM_SIGN_USER}'s key: " |
---|
724 | su $RPM_SIGN_USER -c "rpm --addsign $(for i in $RPM_PKG_ARCH_LIST; do find $BUILD_ROOT${BUILD_DIR}/${i} -type f -regex '.*\.rpm' 2>/dev/null; done | sed -e s,$BUILD_ROOT${BUILD_DIR},${BUILT_RPMS_DIR}/${MAJOR_VERSION},g -e 's/$/ \\/g')" |
---|
725 | |
---|
726 | mount-chroot --umount unionfs_dir |
---|
727 | |
---|
728 | return 0 |
---|
729 | } |
---|
730 | |
---|
731 | |
---|
732 | ############################################################################## |
---|
733 | |
---|
734 | setup-vbuilder || exit 1 |
---|
735 | |
---|
736 | check-parameter $* || exit 1 |
---|
737 | |
---|
738 | while [ $# -gt 0 ]; do |
---|
739 | tmpARG=$1 |
---|
740 | case $tmpARG in |
---|
741 | --version|--arch|--category|--target|--rpmbuild-define|--rpmbuild-with|--rpmbuild-without|--bootstrap-dir|--cache-dir|--built-rpms-dir) |
---|
742 | shift |
---|
743 | ;; |
---|
744 | --dist-upgrade|--unionfs|--with-compat32|--sign|--no-install) |
---|
745 | ;; |
---|
746 | --build-rpm|build-rpm|--install-rpm|install-rpm|--remove-rpm|remove-rpm) |
---|
747 | shift |
---|
748 | ;; |
---|
749 | --build|build|--clean|clean|--show-info|show-info) |
---|
750 | ;; |
---|
751 | *) |
---|
752 | echo unknown option $1 |
---|
753 | exit 1 |
---|
754 | ;; |
---|
755 | esac |
---|
756 | |
---|
757 | case $tmpARG in |
---|
758 | --version) |
---|
759 | VERSION=$1 |
---|
760 | ;; |
---|
761 | --arch) |
---|
762 | VARCH=$1 |
---|
763 | ;; |
---|
764 | --category) |
---|
765 | CATEGORIES=$1 |
---|
766 | ;; |
---|
767 | --dist-upgrade) |
---|
768 | with_dist_upgrade=1 |
---|
769 | ;; |
---|
770 | --unionfs) |
---|
771 | with_unionfs=1 |
---|
772 | ;; |
---|
773 | --target) |
---|
774 | TARGET=$1 |
---|
775 | RPM_OPTS="${RPM_OPTS} --target $TARGET" |
---|
776 | ;; |
---|
777 | --with-compat32) |
---|
778 | RPM_OPTS="${RPM_OPTS} --with compat32" |
---|
779 | ;; |
---|
780 | --rpmbuild-define) |
---|
781 | RPM_OPTS="${RPM_OPTS} --define $1" |
---|
782 | ;; |
---|
783 | --rpmbuild-with) |
---|
784 | RPM_OPTS="${RPM_OPTS} --with $1" |
---|
785 | ;; |
---|
786 | --rpmbuild-without) |
---|
787 | RPM_OPTS="${RPM_OPTS} --without $1" |
---|
788 | ;; |
---|
789 | --sign) |
---|
790 | with_sign=1 |
---|
791 | ;; |
---|
792 | --no-install) |
---|
793 | with_no_install=1 |
---|
794 | ;; |
---|
795 | --bootstrap-dir) |
---|
796 | VBOOTSTRAP_DIR=$1 |
---|
797 | ;; |
---|
798 | --cache-dir) |
---|
799 | CACHE_DIR=$1 |
---|
800 | ;; |
---|
801 | --built-rpms-dir) |
---|
802 | BUILT_RPMS_DIR=$1 |
---|
803 | ;; |
---|
804 | --build-rpm|build-rpm) |
---|
805 | RPM_PKG=$1 |
---|
806 | RPM_Build || exit 1 |
---|
807 | ;; |
---|
808 | --install-rpm|install-rpm) |
---|
809 | RPM_PKG=$1 |
---|
810 | RPM_Install || exit 1 |
---|
811 | ;; |
---|
812 | --remove-rpm|remove-rpm) |
---|
813 | RPM_PKG=$1 |
---|
814 | RPM_Remove || exit 1 |
---|
815 | ;; |
---|
816 | --show-info|show-info) |
---|
817 | Show-Info || exit 1 |
---|
818 | ;; |
---|
819 | --build|build) |
---|
820 | Build || exit 1 |
---|
821 | ;; |
---|
822 | --clean|clean) |
---|
823 | Clean || exit 1 |
---|
824 | ;; |
---|
825 | esac |
---|
826 | shift |
---|
827 | done |
---|
828 | |
---|
829 | RPM_Sign |
---|
830 | |
---|
831 | exit |
---|