source: projects/vbootstrap/tags/0.0.29/vbuilder.sh.in @ 1376

Revision 1376, 23.4 KB checked in by munepi, 14 years ago (diff)

tagging 0.0.29

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