source: projects/vbootstrap/tags/0.0.36/vbuilder.sh.in @ 2664

Revision 2664, 23.0 KB checked in by munepi, 13 years ago (diff)

tagging 0.0.36

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