source: projects/vbootstrap/trunk/vbuilder.sh.in @ 3968

Revision 3968, 25.1 KB checked in by munepi, 13 years ago (diff)

updated vbuilder.sh.in: modified Usage()

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