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

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

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