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

Revision 2468, 23.9 KB checked in by Takemikaduchi, 13 years ago (diff)

update vbuilder.sh.in: add /bin/sh option -l at chroot_sh

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