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

Revision 4530, 25.2 KB checked in by munepi, 13 years ago (diff)

set STABLE_VERSION to 6.0

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'
[411]589
[791]590    [ $with_category_nonfree -eq 1 ] && \
591        $__chroot_sh 'apt-get -qq -y install self-build-setup'
592
[464]593    $__chroot_sh 'apt-get -qq -y install etcskel shadow-utils'
[118]594
[2662]595    $__chroot_sh 'cd /dev && /sbin/MAKEDEV console'
[2718]596    $__chroot_sh 'cd /dev && /sbin/MAKEDEV ptmx'
[2662]597    $__chroot_sh 'cd /dev && /sbin/MAKEDEV null'
598    $__chroot_sh 'cd /dev && /sbin/MAKEDEV zero'
599    $__chroot_sh 'cd /dev && /sbin/MAKEDEV random'
600    $__chroot_sh 'cd /dev && /sbin/MAKEDEV urandom'
[2718]601    $__chroot_sh 'cd /dev && mkdir -p shm && chmod 777 shm'
602    $__chroot_sh 'cd /dev && mkdir -p pts && chmod 755 pts'
[406]603
[453]604    $__chroot_sh '/usr/sbin/pwconv'
605    $__chroot_sh "/usr/sbin/useradd ${BUILD_USER}"
[323]606
[452]607    ##!! for rpm-4.8.0 or higher
608    ##!! (See http://trac.vinelinux.org/wiki/Vine6/AboutUpdateToolchain)
[3676]609    if [ "${VERSION}" = "VineSeed" ]; then
[453]610        $__chroot_sh "sed -i -e 's/^%_topdir/#%_topdir/' /home/${BUILD_USER}/.rpmmacros"
[452]611    fi
612
[454]613    # mount-chroot --umount /home
614    # mount-chroot --umount /tmp
[2718]615    mount-chroot --umount /dev/shm
616    mount-chroot --umount /dev/pts
[725]617    mount-chroot --umount archives_dir
[2718]618    mount-chroot --umount /proc
[413]619    apt-get-update --host
[412]620
[3676]621    echo $"Making a build farm for ${PROFILE} done."
[1240]622    return 0
[118]623}
624
625RPM_Remove(){
[1240]626    setup-vbootstrap-rpm || return 1
[485]627    mount-chroot unionfs_dir
[725]628    mount-chroot archives_dir
[3021]629    mount-chroot /proc
[2718]630    mount-chroot /dev/pts
631    mount-chroot /dev/shm
[628]632    apt-get-update --chroot
[118]633
[2516]634    [ -f $RPM_PKG ] && \
635        echo $"E: $RPM_PKG is not a package name" && return 1
[453]636    $__chroot_sh "apt-get -y remove $BASE_RPM_PKG"
[412]637
[2718]638    mount-chroot --umount /dev/shm
639    mount-chroot --umount /dev/pts
[3021]640    mount-chroot --umount /proc
[725]641    mount-chroot --umount archives_dir
[485]642    mount-chroot --umount unionfs_dir
[413]643    apt-get-update --host
[1240]644
645    return 0
[118]646}
647
648RPM_Install(){
[1240]649    setup-vbootstrap-rpm || return 1
[485]650    mount-chroot unionfs_dir
[725]651    mount-chroot archives_dir
[3021]652    mount-chroot /proc
[2718]653    mount-chroot /dev/pts
654    mount-chroot /dev/shm
655
[413]656    apt-get-update --chroot
[118]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'"
[1267]699    [ $with_no_install -eq 0 ] && \
700        $__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]701
[370]702    ## copy built rpms to ${HOME}/rpm/ for each archtectures
[2522]703    echo $"Copying built rpms to ${BUILT_RPMS_DIR} for each archtectures ... "
[4076]704    for i in $RPM_PKG_ARCH_LIST; do
705        [ -d $BUILD_ROOT${BUILD_DIR}/${i} ] || continue
706        if [ ! -d ${BUILT_RPMS_DIR}/${VERSION}/${i} ]; then
707            $__install -d ${BUILT_RPMS_DIR}/${VERSION}/${i}/
708            chown -R ${RPM_PKG_USER}:${RPM_PKG_GROUP} ${BUILT_RPMS_DIR}
[370]709        fi
[4076]710        find $BUILD_ROOT${BUILD_DIR}/${i} -type f -regex '.*\.rpm' \
711            -exec $__install -m0644 {} ${BUILT_RPMS_DIR}/${VERSION}/${i}/ \;
[370]712    done
[412]713
[2718]714    mount-chroot --umount /dev/shm
715    mount-chroot --umount /dev/pts
[3021]716    mount-chroot --umount /proc
[725]717    mount-chroot --umount archives_dir
[485]718    mount-chroot --umount unionfs_dir
[413]719    apt-get-update --host
[412]720
[2522]721    echo $"done."
[1240]722    return 0
[118]723}
724
[1240]725RPM_Sign(){
[1375]726    [ $with_sign -eq 1 ] || return 1
[118]727
[2668]728    setup-vbootstrap || return 1
729
730    [ -d ${BUILD_ROOT} ] || Build
731
732    mount-chroot unionfs_dir
733
[2662]734    echo $"Signing built rpms using ${RPM_SIGN_USER}'s key: "
[3676]735    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]736
[2668]737    mount-chroot --umount unionfs_dir
738
[1240]739    return 0
740}
741
[2718]742Login_Chroot(){
743    [ $with_login -eq 1 ] || return 1
[1240]744
[2718]745    setup-vbootstrap || return 1
746
747    __chroot="/usr/sbin/chroot ${BUILD_ROOT}"
748    ## setarch ix86 if ix86 chroot on x86_64 host
749    [ $with_ix86_on_x86_64 -eq 1 ] && \
750        __chroot="/usr/sbin/chroot ${BUILD_ROOT} setarch ${VARCH}"
751
752
753    mount-chroot unionfs_dir
754    mount-chroot archives_dir
[3021]755    mount-chroot /proc
[2718]756    mount-chroot /dev/pts
757    mount-chroot /dev/shm
758    mount-chroot /tmp
759    # mount-chroot /home
760    apt-get-update --chroot
761
762    ## copy host's configurations of /etc
763    #passwd shadow group gshadow
764    for i in resolv.conf hosts; do
765        cp -pf /etc/${i} ${BUILD_ROOT}/etc
766    done
767    cp -Ppf /etc/localtime ${BUILD_ROOT}/etc
768
[3678]769    $__chroot /bin/bash
[2718]770
771    # mount-chroot  --umount /home
772    mount-chroot  --umount /tmp
773    mount-chroot --umount /dev/shm
774    mount-chroot --umount /dev/pts
[3021]775    mount-chroot --umount /proc
[2718]776    mount-chroot --umount archives_dir
777    mount-chroot --umount unionfs_dir
778    apt-get-update --host
779
780    return 0
781}
782
783
[304]784##############################################################################
785
[1240]786setup-vbuilder || exit 1
[304]787
[416]788check-parameter $* || exit 1
789
[118]790while [ $# -gt 0 ]; do
[411]791    tmpARG=$1
792    case $tmpARG in
[2711]793        --version|--arch|--category|--target|--rpmbuild-define|--rpmbuild-with|--rpmbuild-without|--bootstrap-dir|--unionfs-dir|--cache-dir|--built-rpms-dir)
[406]794            shift
795            ;;
[2718]796        --dist-upgrade|--unionfs|--with-compat32|--sign|--no-install|--login|--debug)
[406]797            ;;
[725]798        --build-rpm|build-rpm|--install-rpm|install-rpm|--remove-rpm|remove-rpm)
799            shift
800            ;;
[3675]801        --build|build|--clean|clean)
[725]802            ;;
[406]803        *)
[416]804            echo unknown option $1
[406]805            exit 1
806            ;;
807    esac
808
[411]809    case $tmpARG in
[406]810        --version)
[118]811            VERSION=$1
812            ;;
813        --arch)
814            VARCH=$1
815            ;;
[791]816        --category)
817            CATEGORIES=$1
818            ;;
[411]819        --dist-upgrade)
820            with_dist_upgrade=1
821            ;;
[485]822        --unionfs)
823            with_unionfs=1
824            ;;
[406]825        --target)
826            TARGET=$1
827            RPM_OPTS="${RPM_OPTS} --target $TARGET"
828            ;;
[118]829        --with-compat32)
[406]830            RPM_OPTS="${RPM_OPTS} --with compat32"
[118]831            ;;
[2531]832        --rpmbuild-define)
833            RPM_OPTS="${RPM_OPTS} --define $1"
834            ;;
[1476]835        --rpmbuild-with)
836            RPM_OPTS="${RPM_OPTS} --with $1"
837            ;;
[2531]838        --rpmbuild-without)
839            RPM_OPTS="${RPM_OPTS} --without $1"
840            ;;
[1240]841        --sign)
842            with_sign=1
843            ;;
[1267]844        --no-install)
845            with_no_install=1
846            ;;
[2718]847        --login)
848            with_login=1
849            ;;
[709]850        --bootstrap-dir)
851            VBOOTSTRAP_DIR=$1
852            ;;
[2711]853        --unionfs-dir)
854            UNIONFS_DIR=$1
855            ;;
[725]856        --cache-dir)
857            CACHE_DIR=$1
858            ;;
[709]859        --built-rpms-dir)
860            BUILT_RPMS_DIR=$1
861            ;;
[2718]862        --debug)
863            with_debug=1
864            ;;
[679]865        --build-rpm|build-rpm)
[118]866            RPM_PKG=$1
[406]867            RPM_Build || exit 1
[118]868            ;;
[679]869        --install-rpm|install-rpm)
[118]870            RPM_PKG=$1
[406]871            RPM_Install || exit 1
[118]872            ;;
[679]873        --remove-rpm|remove-rpm)
[118]874            RPM_PKG=$1
[406]875            RPM_Remove || exit 1
[118]876            ;;
[679]877        --build|build)
[1240]878            Build || exit 1
[118]879            ;;
[679]880        --clean|clean)
[1240]881            Clean || exit 1
[118]882            ;;
883    esac
884    shift
885done
886
[3479]887RPM_Sign ||:
[1240]888
[3479]889Login_Chroot ||:
[2718]890
[118]891exit
Note: See TracBrowser for help on using the repository browser.