source: projects/vbootstrap/tags/0.0.47/vbuilder.sh.in @ 4622

Revision 4622, 25.5 KB checked in by munepi, 13 years ago (diff)

updated vbuilder.sh.in: Build() を最適化。vbuilder clean build しても、self-build-setup ぱっけーじをインストールしないように変更。self-build-setup は、self-build 関連パッケージをビルド、もしくは、インストールするときのみに、インストールするように変更。

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