source: projects/vbootstrap/trunk/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 関連パッケージをビルド、もしくは、インストールするときのみに、インストールするように変更。

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