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

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

updated vbuilder.sh.in: modified Usage()

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