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

Revision 1524, 23.6 KB checked in by munepi, 14 years ago (diff)

updated vbuilder.sh.in: fixed around --rpmbuild-with option

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