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

Revision 5364, 29.8 KB checked in by munepi, 12 years ago (diff)

updated vbootstrap.sh.in:

  • specify a location to fetch base packages;

updated vbuilder.sh.in:

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