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

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

fixed Login_Chroot() in vbuilder.sh.in

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]
19        --with-compat32:        build rpms with compat32 on boostrap
[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:
[687]34        clean:                  clean the boostrap of [version]
35        build:                  build a boostrap of [version]
36        build-rpm:              build [src.rpm] on a boostrap
37        install-rpm:            install [arch.rpm|package] on a boostrap
38        remove-rpm:             remove [package] on a boostrap
[118]39
40For example,
[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
[3352]115        RPM_SIGN_USER=$(getent passwd $USERHELPER_UID | cut -d":" -f1)
116        if [ -z "${RPM_SIGN_USER}" ]; then
[3343]117            echo $"W: \$SUDO_USER and \$USERHELPER_UID are empty"
118            return 1
119        fi
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/")"
298            if [ -z "$(echo $RPM_TARGET_LIST | grep $TARGET)" ]; then
[2516]299                echo $"E: rpm build target ${TARGET} is NOT supported"
300                return 1
[407]301            fi
[406]302        fi
303
[1240]304        ## set ${RPM_PKG_ARCH_LIST}
[2718]305        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]306        [ -z "${TARGET}" ] || \
307            RPM_PKG_ARCH_LIST="RPMS/${TARGET} ${RPM_PKG_ARCH_LIST}"
308
[135]309    fi
[323]310
[1240]311    ## set global variables
[3676]312    BUILD_ROOT=${VBOOTSTRAP_DIR}/${PROFILE}
[296]313    BUILD_USER=vbuilder
314    BUILD_DIR=/home/${BUILD_USER}/rpm
[3676]315    UNIONFS_ROOT=${UNIONFS_DIR}/${PROFILE}
[452]316    ARCHIVES_DIR=${BUILD_ROOT}/var/cache/apt/archives
[3676]317    EXTERNAL_ARCHIVES_DIR=${CACHE_DIR}/${PROFILE}/apt/archives
[135]318
[2468]319    __chroot_sh="/usr/sbin/chroot ${BUILD_ROOT} /bin/sh -c -l"
[453]320
[135]321    mkdir -p $VBOOTSTRAP_DIR
[1240]322
323    return 0
[118]324}
325
[412]326setup-vbootstrap-rpm(){
[1240]327    setup-vbootstrap || return 1
[412]328
329    ## check ${BUILD_ROOT}
330    [ -d ${BUILD_ROOT} ] || Build
[2324]331    ## setarch ix86 if ix86 chroot on x86_64 host
332    [ $with_ix86_on_x86_64 -eq 1 ] && \
[2468]333        __chroot_sh="/usr/sbin/chroot ${BUILD_ROOT} setarch ${VARCH} /bin/sh -c -l"
[412]334
335    DIST_RELEASE=$(cat ${BUILD_ROOT}/etc/vine-release | cut -f3 -d" " | cut -f1 -d.)
336
337    if [ -f $RPM_PKG ]; then
338        BASE_RPM_PKG=$(basename $RPM_PKG)
339        cp -f $RPM_PKG $BUILD_ROOT${BUILD_DIR}
340    else
341        BASE_RPM_PKG=$RPM_PKG   
342    fi
[1240]343
344    return 0
[412]345}
346
[413]347## recover apt-get data on host/chroot
348apt-get-update(){
349    case $1 in
350        --host)
[2522]351            echo -n $"apt-get update on host ... "
[464]352            apt-get -qq update > /dev/null 2>&1
[2522]353            echo $"done."
[413]354            ;;
355        --chroot)
[2522]356            echo -n $"apt-get update on chroot ... "
[464]357            $__chroot_sh 'apt-get -qq update' > /dev/null 2>&1
[2522]358            echo $"done."
[413]359            ;;
360        *)
361            echo apt-get-update: unknown option $1
362            exit 1
363            ;;
364    esac
365}
366
[454]367## mount-chroot {|--umount} [file system|name]
368## support file systems: /home /tmp /sys /proc /dev/shm /dev/pts /dev
[2654]369## support names: vfs archives_dir
[454]370## NOTE: /tmp needs for applications which use X
371##       vfs is virtual file systems
[851]372##       archives_dir uses to mount ${EXTERNAL_ARCHIVES_DIR} to ${ARCHIVES_DIR}
373##       unionfs_dir covers ${BUILD_ROOT} with unionfs
[454]374mount-chroot(){
[412]375    if [ "$1" = "--umount" ]; then
[454]376        mount-chroot-umount $2 || return 1
[412]377    else
[454]378        mount-chroot-mount $1 || return 1
[412]379    fi
[454]380    return 0
[412]381}
382
[454]383## mount-chroot-umount [file system|name]
384mount-chroot-umount(){
385    local fs=$1
386    case $fs in
387        /home|/tmp|/sys|/proc|/dev/shm|/dev/pts|/dev)
388            [ -d ${BUILD_ROOT}${fs} ] || return 1
389            [ -z "$(mount | grep ${BUILD_ROOT}${fs})" ] || \
390                umount ${BUILD_ROOT}${fs}
[2654]391            if [ ! -z "$(mount | grep ${BUILD_ROOT}${fs})" ]; then
392                echo $"Retry lazy unmount ${BUILD_ROOT}${fs} ... "
393                umount -l ${BUILD_ROOT}${fs}
394                echo $"done."
395            fi
[454]396            ;;
397        vfs)
[2718]398            for dir in /sys /proc /dev/shm /dev/pts /dev; do
399                mount-chroot-umount ${dir} || return 1
400            done
[454]401            ;;
[725]402        archives_dir)
[454]403            [ -d ${ARCHIVES_DIR} ] || return 1
404            [ -z "$(mount | grep ${ARCHIVES_DIR})" ] || \
405                umount ${ARCHIVES_DIR}
406            ;;
[485]407        unionfs_dir)
408            [ -d ${BUILD_ROOT} ] || return 1
409            [ -z "$(mount | grep ${BUILD_ROOT} | grep unionfs)" ] || \
410                umount ${BUILD_ROOT}
411            if [ ! -z "$(mount | grep ${BUILD_ROOT} | grep unionfs)" ]; then
[2654]412                echo $"Retry lazy unmount ${BUILD_ROOT} ... "
[485]413                umount -l ${BUILD_ROOT}
[2522]414                echo $"done."
[485]415            fi
416            ;;
[454]417        *)
418            echo mount-chroot-umount: unknown file system $fs
419            exit 1
420            ;;
421    esac
[1240]422    return 0
[412]423}
424
[454]425## mount-chroot-mount [file system|name]
426mount-chroot-mount(){
427    local fs=$1
[412]428
[454]429    case $fs in
430        /home)
[2718]431            [ -d ${BUILD_ROOT}${fs} ] || mkdir -p ${BUILD_ROOT}${fs}
432            [ -z "$(mount | grep ${BUILD_ROOT}${fs})" ] && \
433                mount -o _netdev,rbind ${fs} ${BUILD_ROOT}${fs}
[454]434            ;;
[2718]435        /tmp|/dev)
436            [ -d ${BUILD_ROOT}${fs} ] || mkdir -p ${BUILD_ROOT}${fs}
437            [ -z "$(mount | grep ${BUILD_ROOT}${fs})" ] && \
438                mount --bind -o _netdev ${fs} ${BUILD_ROOT}${fs}
[454]439            ;;
[2718]440        /sys)
[454]441            [ -d ${BUILD_ROOT}${fs} ] || mkdir -p ${BUILD_ROOT}${fs}
442            [ -z "$(mount | grep ${BUILD_ROOT}${fs})" ] && \
[2718]443                mount -o _netdev -t sysfs vbuildersysfs ${BUILD_ROOT}${fs}
[454]444            ;;
[2718]445        /proc)
446            [ -d ${BUILD_ROOT}${fs} ] || mkdir -p ${BUILD_ROOT}${fs}
447            [ -z "$(mount | grep ${BUILD_ROOT}${fs})" ] && \
448                mount -o _netdev -t proc vbuilderproc ${BUILD_ROOT}${fs}
449            ;;
450        /dev/shm)
451            [ -d ${BUILD_ROOT}${fs} ] || mkdir -p ${BUILD_ROOT}${fs}
452            [ -z "$(mount | grep ${BUILD_ROOT}${fs})" ] && \
453                mount -o _netdev -t tmpfs vbuildertmpfs ${BUILD_ROOT}${fs}
454            ;;
455        /dev/pts)
456            [ -d ${BUILD_ROOT}${fs} ] || mkdir -p ${BUILD_ROOT}${fs}
457            [ -z "$(mount | grep ${BUILD_ROOT}${fs})" ] && \
458                mount -o gid=5,mode=620,_netdev -t devpts vbuilderdevpts ${BUILD_ROOT}${fs}
459            ;;
[454]460        vfs)
[2718]461            for dir in /dev /dev/pts /dev/shm /proc /sys; do
462                mount-chroot-mount ${dir} || return 1
463            done
[454]464            ;;
[725]465        archives_dir)
466            [ -d ${EXTERNAL_ARCHIVES_DIR} ] || mkdir -p ${EXTERNAL_ARCHIVES_DIR}
[454]467            [ -d ${ARCHIVES_DIR} ] || mkdir -p ${ARCHIVES_DIR}
468            [ -z "$(mount | grep ${ARCHIVES_DIR})" ] && \
[2718]469                mount --bind -o _netdev ${EXTERNAL_ARCHIVES_DIR} ${ARCHIVES_DIR}
[454]470            [ -d ${ARCHIVES_DIR}/partial ] || mkdir -p ${ARCHIVES_DIR}/partial
471            ;;
[485]472        unionfs_dir)
473            if [ $with_unionfs -eq 1 ]; then
[2711]474                [ -d ${UNIONFS_ROOT} ] || mkdir -p ${UNIONFS_ROOT}
[2766]475                [ -z "$(mount | grep ${UNIONFS_ROOT})" ] && \
[2711]476                    mount -t unionfs -o dirs=${UNIONFS_ROOT}=rw:${BUILD_ROOT}=ro unionfs ${BUILD_ROOT}
[485]477                unionctl ${BUILD_ROOT} --list
478            fi
479            ;;
[455]480        *)
481            echo mount-chroot-mount: unknown file system $fs
482            exit 1
483            ;;
[454]484    esac
[1240]485    return 0
[452]486}
[412]487
[791]488
[118]489##############################################################################
490
491Clean(){
[1240]492    setup-vbootstrap || return 1
[118]493
[454]494    # mount-chroot --umount /home
[2718]495    mount-chroot --umount /tmp
496    mount-chroot --umount /dev/shm
497    mount-chroot --umount /dev/pts
[3021]498    mount-chroot --umount /proc
[725]499    mount-chroot --umount archives_dir
[485]500    mount-chroot --umount unionfs_dir
[413]501    apt-get-update --host
[406]502
[2770]503    ## We remark that we first remove /, and secondly remove /.
[2769]504    ## If we directly remove /, we obtained some non-empty directories:
505    ##   /dev/.udev/rules.d.
[485]506    if [ $with_unionfs -eq 1 ]; then
[2711]507        if [ -d ${UNIONFS_ROOT} ]; then
508            echo -n $"Cleaning build root ${UNIONFS_ROOT} via unionfs ... "
[2770]509            rm -rf ${UNIONFS_ROOT} 2>/dev/null
[2711]510            rm -rf ${UNIONFS_ROOT}
[2522]511            echo $"done."
[485]512        fi
513    else
514        if [ -d ${BUILD_ROOT} ]; then
[2522]515            echo -n $"Cleaning build root ${BUILD_ROOT} ... "
[2770]516            rm -rf ${BUILD_ROOT} 2>/dev/null
[485]517            rm -rf ${BUILD_ROOT}
[2522]518            echo $"done."
[485]519        fi
[323]520    fi
[412]521
[3676]522    echo $"Cleanup a build farm for ${PROFILE} done."
[1240]523    return 0
[118]524}
525
526Build(){
[1240]527    setup-vbootstrap || return 1
[118]528
[411]529    if [ $with_dist_upgrade -eq 1 ]; then
530        ## make bootstrap of ${STABLE_VERSION}
531        /usr/sbin/vbootstrap \
[3676]532            $(echo ${PROFILE} | sed -e "s/VineSeed/${STABLE_VERSION}/") \
[411]533            ${BUILD_ROOT}
[118]534
[411]535        ## aim apt-line to VineSeed
536        sed -i "s/apt ${STABLE_VERSION}/apt VineSeed/g" \
537            ${BUILD_ROOT}/etc/apt/sources.list.d/main.list
538    else
[3676]539        /usr/sbin/vbootstrap ${PROFILE} ${BUILD_ROOT}
[411]540    fi
541
[2718]542    mount-chroot /proc
[725]543    mount-chroot archives_dir
[2718]544    mount-chroot /dev/pts
545    mount-chroot /dev/shm
[454]546    # mount-chroot /tmp
547    # mount-chroot /home
[118]548
[464]549    $__chroot_sh 'apt-get -qq update && apt-get -qq -y dist-upgrade'
[411]550
[791]551    ##!! 4.2 has no apt-sourceslist-{plus,nonfree,proposed-updates} packages
[3676]552    case ${VERSION} in
[791]553        4.2)
554            $__chroot_sh "sed -i -e 's/main plus updates nonfree *$/$(echo ${CATEGORIES} | sed -e "s/,/ /"g) updates/g' /etc/apt/sources.list"
[800]555            # [ $with_category_security -eq 1 ] && \
556            #   echo
[791]557            ;;
558        @@VBUILDER_STABLE_VERSION@@)
559            [ $with_category_plus -eq 1 ] && \
560                $__chroot_sh 'apt-get -qq update && apt-get -qq -y install apt-sourceslist-plus'
561            [ $with_category_nonfree -eq 1 ] && \
562                $__chroot_sh 'apt-get -qq update && apt-get -qq -y install apt-sourceslist-nonfree'
563            [ $with_category_proposed_updates -eq 1 ] && \
564                $__chroot_sh 'apt-get -qq update && apt-get -qq -y install apt-sourceslist-proposed-updates'
[800]565            # [ $with_category_security -eq 1 ] && \
566            #   echo
[791]567            ;;
568        VineSeed)
569            [ $with_category_plus -eq 1 ] && \
570                $__chroot_sh 'apt-get -qq update && apt-get -qq -y install apt-sourceslist-plus'
571            [ $with_category_nonfree -eq 1 ] && \
572                $__chroot_sh 'apt-get -qq update && apt-get -qq -y install apt-sourceslist-nonfree'
[800]573            [ $with_category_test -eq 1 ] && \
574                $__chroot_sh 'apt-get -qq update && apt-get -qq -y install apt-sourceslist-test'
[791]575            ;;
576    esac
[423]577
[791]578    [ $with_dist_upgrade -eq 1 ] && \
[464]579        $__chroot_sh 'apt-get -qq update && apt-get -qq -y dist-upgrade'
[791]580
[464]581    $__chroot_sh 'apt-get -qq -y install build-essential'
[411]582
[791]583    [ $with_category_nonfree -eq 1 ] && \
584        $__chroot_sh 'apt-get -qq -y install self-build-setup'
585
[464]586    $__chroot_sh 'apt-get -qq -y install etcskel shadow-utils'
[118]587
[2662]588    $__chroot_sh 'cd /dev && /sbin/MAKEDEV console'
[2718]589    $__chroot_sh 'cd /dev && /sbin/MAKEDEV ptmx'
[2662]590    $__chroot_sh 'cd /dev && /sbin/MAKEDEV null'
591    $__chroot_sh 'cd /dev && /sbin/MAKEDEV zero'
592    $__chroot_sh 'cd /dev && /sbin/MAKEDEV random'
593    $__chroot_sh 'cd /dev && /sbin/MAKEDEV urandom'
[2718]594    $__chroot_sh 'cd /dev && mkdir -p shm && chmod 777 shm'
595    $__chroot_sh 'cd /dev && mkdir -p pts && chmod 755 pts'
[406]596
[453]597    $__chroot_sh '/usr/sbin/pwconv'
598    $__chroot_sh "/usr/sbin/useradd ${BUILD_USER}"
[323]599
[452]600    ##!! for rpm-4.8.0 or higher
601    ##!! (See http://trac.vinelinux.org/wiki/Vine6/AboutUpdateToolchain)
[3676]602    if [ "${VERSION}" = "VineSeed" ]; then
[453]603        $__chroot_sh "sed -i -e 's/^%_topdir/#%_topdir/' /home/${BUILD_USER}/.rpmmacros"
[452]604    fi
605
[454]606    # mount-chroot --umount /home
607    # mount-chroot --umount /tmp
[2718]608    mount-chroot --umount /dev/shm
609    mount-chroot --umount /dev/pts
[725]610    mount-chroot --umount archives_dir
[2718]611    mount-chroot --umount /proc
[413]612    apt-get-update --host
[412]613
[3676]614    echo $"Making a build farm for ${PROFILE} done."
[1240]615    return 0
[118]616}
617
618RPM_Remove(){
[1240]619    setup-vbootstrap-rpm || return 1
[485]620    mount-chroot unionfs_dir
[725]621    mount-chroot archives_dir
[3021]622    mount-chroot /proc
[2718]623    mount-chroot /dev/pts
624    mount-chroot /dev/shm
[628]625    apt-get-update --chroot
[118]626
[2516]627    [ -f $RPM_PKG ] && \
628        echo $"E: $RPM_PKG is not a package name" && return 1
[453]629    $__chroot_sh "apt-get -y remove $BASE_RPM_PKG"
[412]630
[2718]631    mount-chroot --umount /dev/shm
632    mount-chroot --umount /dev/pts
[3021]633    mount-chroot --umount /proc
[725]634    mount-chroot --umount archives_dir
[485]635    mount-chroot --umount unionfs_dir
[413]636    apt-get-update --host
[1240]637
638    return 0
[118]639}
640
641RPM_Install(){
[1240]642    setup-vbootstrap-rpm || return 1
[485]643    mount-chroot unionfs_dir
[725]644    mount-chroot archives_dir
[3021]645    mount-chroot /proc
[2718]646    mount-chroot /dev/pts
647    mount-chroot /dev/shm
648
[413]649    apt-get-update --chroot
[118]650
[453]651    $__chroot_sh "cd ${BUILD_DIR} && apt-get -y install $BASE_RPM_PKG"
[412]652
[2718]653    mount-chroot --umount /dev/shm
654    mount-chroot --umount /dev/pts
[3021]655    mount-chroot --umount /proc
[725]656    mount-chroot --umount archives_dir
[485]657    mount-chroot --umount unionfs_dir
[413]658    apt-get-update --host
[1240]659
660    return 0
[118]661}
662
663RPM_Build(){
[1240]664    setup-vbootstrap-rpm || return 1
[485]665    mount-chroot unionfs_dir
[725]666    mount-chroot archives_dir
[3021]667    mount-chroot /proc
[2718]668    mount-chroot /dev/pts
669    mount-chroot /dev/shm
[628]670    apt-get-update --chroot
[118]671
[2516]672    [ ! -f $RPM_PKG ] && \
673        echo $"E: $RPM_PKG is not a source RPM package" && return 1
[370]674   
675    RPM_PKG_USER=$(stat -c %U $RPM_PKG)
[371]676    RPM_PKG_GROUP=$(stat -c %G $RPM_PKG)
[520]677    [ ! -z "${SUDO_UID}" ] && RPM_PKG_USER=${SUDO_UID}
678    [ ! -z "${SUDO_GID}" ] && RPM_PKG_GROUP=${SUDO_GID}
[371]679    local __install="install -p -v -o ${RPM_PKG_USER} -g ${RPM_PKG_GROUP}"
[370]680
681    ## make src.rpm for $VERSION
[453]682    $__chroot_sh "cd ${BUILD_DIR} && su ${BUILD_USER} -c 'rpm -ivh $BASE_RPM_PKG'"
[1524]683    $__chroot_sh "cd ${BUILD_DIR} && su ${BUILD_USER} -c 'rpmbuild -bs --nodeps --clean --rmsource --rmspec $RPM_OPTS ${BUILD_DIR}/SPECS/*.spec'"
[370]684
[396]685
686    ## change ${DIST_RELEASE}
[2532]687    BASE_RPM_PKG=$(echo $BASE_RPM_PKG | sed -e "s/vl[0-9]*\([A-Za-z]*\)\./vl${DIST_RELEASE}\1\./")
[396]688
689    ## rebuild $BASE_RPM_PKG on ${DIST_RELEASE}
[969]690    $__chroot_sh "cd ${BUILD_DIR}/SRPMS && apt-get -o APT::Install::Virtual=true -y build-dep $BASE_RPM_PKG"
[453]691    $__chroot_sh "cd ${BUILD_DIR}/SRPMS && su ${BUILD_USER} -c 'rpmbuild --rebuild $RPM_OPTS $BASE_RPM_PKG'"
[1267]692    [ $with_no_install -eq 0 ] && \
693        $__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]694
[370]695    ## copy built rpms to ${HOME}/rpm/ for each archtectures
[2522]696    echo $"Copying built rpms to ${BUILT_RPMS_DIR} for each archtectures ... "
[370]697    for i in $RPM_PKG_ARCH_LIST; do \
698        if [ -d $BUILD_ROOT${BUILD_DIR}/${i} ]; then
[3676]699            if [ ! -d ${BUILT_RPMS_DIR}/${VERSION}/${i} ]; then
700                $__install -d ${BUILT_RPMS_DIR}/${VERSION}/${i}/
[516]701                chown -R ${RPM_PKG_USER}:${RPM_PKG_GROUP} ${BUILT_RPMS_DIR}
702            fi
[370]703            find $BUILD_ROOT${BUILD_DIR}/${i} -type f -regex '.*\.rpm' \
[3676]704                -exec $__install -m0644 {} ${BUILT_RPMS_DIR}/${VERSION}/${i}/ \;
[370]705        fi
706    done
[412]707
[2718]708    mount-chroot --umount /dev/shm
709    mount-chroot --umount /dev/pts
[3021]710    mount-chroot --umount /proc
[725]711    mount-chroot --umount archives_dir
[485]712    mount-chroot --umount unionfs_dir
[413]713    apt-get-update --host
[412]714
[2522]715    echo $"done."
[1240]716    return 0
[118]717}
718
[1240]719RPM_Sign(){
[1375]720    [ $with_sign -eq 1 ] || return 1
[118]721
[2668]722    setup-vbootstrap || return 1
723
724    [ -d ${BUILD_ROOT} ] || Build
725
726    mount-chroot unionfs_dir
727
[2662]728    echo $"Signing built rpms using ${RPM_SIGN_USER}'s key: "
[3676]729    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]730
[2668]731    mount-chroot --umount unionfs_dir
732
[1240]733    return 0
734}
735
[2718]736Login_Chroot(){
737    [ $with_login -eq 1 ] || return 1
[1240]738
[2718]739    setup-vbootstrap || return 1
740
741    __chroot="/usr/sbin/chroot ${BUILD_ROOT}"
742    ## setarch ix86 if ix86 chroot on x86_64 host
743    [ $with_ix86_on_x86_64 -eq 1 ] && \
744        __chroot="/usr/sbin/chroot ${BUILD_ROOT} setarch ${VARCH}"
745
746
747    mount-chroot unionfs_dir
748    mount-chroot archives_dir
[3021]749    mount-chroot /proc
[2718]750    mount-chroot /dev/pts
751    mount-chroot /dev/shm
752    mount-chroot /tmp
753    # mount-chroot /home
754    apt-get-update --chroot
755
756    ## copy host's configurations of /etc
757    #passwd shadow group gshadow
758    for i in resolv.conf hosts; do
759        cp -pf /etc/${i} ${BUILD_ROOT}/etc
760    done
761    cp -Ppf /etc/localtime ${BUILD_ROOT}/etc
762
[3678]763    $__chroot /bin/bash
[2718]764
765    # mount-chroot  --umount /home
766    mount-chroot  --umount /tmp
767    mount-chroot --umount /dev/shm
768    mount-chroot --umount /dev/pts
[3021]769    mount-chroot --umount /proc
[2718]770    mount-chroot --umount archives_dir
771    mount-chroot --umount unionfs_dir
772    apt-get-update --host
773
774    return 0
775}
776
777
[304]778##############################################################################
779
[1240]780setup-vbuilder || exit 1
[304]781
[416]782check-parameter $* || exit 1
783
[118]784while [ $# -gt 0 ]; do
[411]785    tmpARG=$1
786    case $tmpARG in
[2711]787        --version|--arch|--category|--target|--rpmbuild-define|--rpmbuild-with|--rpmbuild-without|--bootstrap-dir|--unionfs-dir|--cache-dir|--built-rpms-dir)
[406]788            shift
789            ;;
[2718]790        --dist-upgrade|--unionfs|--with-compat32|--sign|--no-install|--login|--debug)
[406]791            ;;
[725]792        --build-rpm|build-rpm|--install-rpm|install-rpm|--remove-rpm|remove-rpm)
793            shift
794            ;;
[3675]795        --build|build|--clean|clean)
[725]796            ;;
[406]797        *)
[416]798            echo unknown option $1
[406]799            exit 1
800            ;;
801    esac
802
[411]803    case $tmpARG in
[406]804        --version)
[118]805            VERSION=$1
806            ;;
807        --arch)
808            VARCH=$1
809            ;;
[791]810        --category)
811            CATEGORIES=$1
812            ;;
[411]813        --dist-upgrade)
814            with_dist_upgrade=1
815            ;;
[485]816        --unionfs)
817            with_unionfs=1
818            ;;
[406]819        --target)
820            TARGET=$1
821            RPM_OPTS="${RPM_OPTS} --target $TARGET"
822            ;;
[118]823        --with-compat32)
[406]824            RPM_OPTS="${RPM_OPTS} --with compat32"
[118]825            ;;
[2531]826        --rpmbuild-define)
827            RPM_OPTS="${RPM_OPTS} --define $1"
828            ;;
[1476]829        --rpmbuild-with)
830            RPM_OPTS="${RPM_OPTS} --with $1"
831            ;;
[2531]832        --rpmbuild-without)
833            RPM_OPTS="${RPM_OPTS} --without $1"
834            ;;
[1240]835        --sign)
836            with_sign=1
837            ;;
[1267]838        --no-install)
839            with_no_install=1
840            ;;
[2718]841        --login)
842            with_login=1
843            ;;
[709]844        --bootstrap-dir)
845            VBOOTSTRAP_DIR=$1
846            ;;
[2711]847        --unionfs-dir)
848            UNIONFS_DIR=$1
849            ;;
[725]850        --cache-dir)
851            CACHE_DIR=$1
852            ;;
[709]853        --built-rpms-dir)
854            BUILT_RPMS_DIR=$1
855            ;;
[2718]856        --debug)
857            with_debug=1
858            ;;
[679]859        --build-rpm|build-rpm)
[118]860            RPM_PKG=$1
[406]861            RPM_Build || exit 1
[118]862            ;;
[679]863        --install-rpm|install-rpm)
[118]864            RPM_PKG=$1
[406]865            RPM_Install || exit 1
[118]866            ;;
[679]867        --remove-rpm|remove-rpm)
[118]868            RPM_PKG=$1
[406]869            RPM_Remove || exit 1
[118]870            ;;
[679]871        --build|build)
[1240]872            Build || exit 1
[118]873            ;;
[679]874        --clean|clean)
[1240]875            Clean || exit 1
[118]876            ;;
877    esac
878    shift
879done
880
[3479]881RPM_Sign ||:
[1240]882
[3479]883Login_Chroot ||:
[2718]884
[118]885exit
Note: See TracBrowser for help on using the repository browser.