source: projects/vbootstrap/tags/0.0.31/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

Line 
1#!/bin/bash
2# -*- coding: utf-8-unix -*-
3
4Usage_C(){
5    cat<<EOF
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}
7
8Options:
9        --version:              set [version] (default: ${DEFAULT_VERSION})
10        --arch:                 set [arch] (default: $(uname -i))
11        --category:             set [categories] (default: ${CATEGORIES})
12        --dist-upgrade:         make VineSeed bootstrap via ${STABLE_VERSION}
13        --unionfs:              cover a bootstrap with unionfs
14        --target:               build rpms with [target]
15        --with-compat32:        build rpms with compat32 on boostrap
16        --rpmbuild-with:        give a option --with [bcond_with] to rpmbuild
17        --sign:                 sign built rpms
18        --no-install:           build only a source rpm - do NOT install a built rpm
19        --bootstrap-dir:        set a bootstrap directory (default: ${VBOOTSTRAP_DIR})
20        --cache-dir:            set a directory to cache rpms (default: ${CACHE_DIR})
21        --built-rpms-dir:       set a directory to store built rpms in chroot (default: ${BUILT_RPMS_DIR})
22
23Actions:
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
29        show-info:              show basic informations and logs in chroot
30
31For example,
32* make a clean/plain build environment on the current archtecture:
33$(basename $0) clean build
34* build rpms from the specified source rpm:
35$(basename $0) build-rpm [src.rpm]
36* make a plain build environment for Vine Linux 4.2:
37$(basename $0) --version 4.2 clean build
38* make a i386 chroot on x86_64:
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]
42* build a compat32 package:
43$(basename $0) --arch i386 --with-compat32 build-rpm [src.rpm]
44$(/usr/sbin/vbootstrap | sed -e s/^Usage:.*// -e s/^E:.*//)
45EOF
46}
47
48Usage_ja(){
49    Usage_C
50}
51
52Msg_MissingParameter_C(){
53    local para=$1
54    cat<<EOF
55E: Missing some parameters after ${para}
56EOF
57}
58
59Msg_MissingParameter_ja(){
60    local para=$1
61    cat<<EOF
62E: ${para} 以後のいくつかの引数に間違いがあります
63EOF
64}
65
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
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
104Msg_NoSupportVARCH_C(){
105    cat<<EOF
106E: arch ${VARCH} is NOT supported on $(uname -i)
107EOF
108}
109
110Msg_NoSupportVARCH_ja(){
111    cat<<EOF
112E: ${VARCH} アーキテクチャは $(uname -i) 上で非サポートです
113EOF
114}
115
116Msg_NoSupportVERSION_C(){
117    cat<<EOF
118E: ${VERSION} is NOT supported
119EOF
120}
121
122Msg_NoSupportVERSION_ja(){
123    cat<<EOF
124E: バージョン ${VERSION} は非サポートです
125EOF
126}
127
128Msg_NoSupportDistUpgradeVERSION_C(){
129    cat<<EOF
130E: version ${VERSION} does not support --dist-upgrade option
131EOF
132}
133
134Msg_NoSupportDistUpgradeVERSION_ja(){
135    cat<<EOF
136E: バージョン ${VERSION} では --dist-upgrade オプションはサポートされていません
137EOF
138}
139
140Msg_NoSupportTARGET_C(){
141    cat<<EOF
142E: rpm build target ${TARGET} is NOT supported
143EOF
144}
145
146Msg_NoSupportTARGET_ja(){
147    cat<<EOF
148E: rpm ビルドターゲット ${TARGET} はサポートされていません
149EOF
150}
151
152Msg_NotPackageName_C(){
153    local RPM_PKG=$1
154    cat<<EOF
155E: $RPM_PKG is not a package name
156EOF
157}
158
159Msg_NotPackageName_ja(){
160    local RPM_PKG=$1
161    cat<<EOF
162E: $RPM_PKG はパッケージ名でありません
163EOF
164}
165
166Msg_NotSourceRPM_C(){
167    local RPM_PKG=$1
168    cat<<EOF
169E: $RPM_PKG is not a source RPM package
170EOF
171}
172
173Msg_NotSourceRPM_ja(){
174    local RPM_PKG=$1
175    cat<<EOF
176E: $RPM_PKG はソース RPM パッケージでありません
177EOF
178}
179
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
192##############################################################################
193
194check-parameter(){
195    [ -z "$*" ] && Usage_$LOCALE && return 1
196
197    while [ ! -z "$*" ]; do
198        case $1 in
199            --help|help)
200                Usage_$LOCALE
201                return 1
202                ;;
203            --version|--arch|--category|--target|--rpmbuild-with|--bootstrap-dir|--cache-dir|--built-rpms-dir)
204                [ $with_actions -eq 1 ] && \
205                    Msg_GiveNoMoreOptions_$LOCALE && return 1
206                shift
207                check-next-parameter $1 || return 1
208                ;;
209            --dist-upgrade|--unionfs|--with-compat32|--sign|--no-install)
210                [ $with_actions -eq 1 ] && \
211                    Msg_GiveNoMoreOptions_$LOCALE && return 1
212                ;;
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                ;;
221            *)
222                Msg_MissingParameter_$LOCALE $1
223                return 1
224                ;;
225        esac
226        shift
227    done
228
229    [ $with_actions -eq 0 ] && Msg_GiveAtLeastOneAction_$LOCALE && return 1
230
231    return 0
232}
233
234check-next-parameter(){
235    local arg=$1
236    [ -z "${arg}" ] && Msg_MissingParameter_$LOCALE ${arg} && return 1
237
238    [ $(echo ${arg} | grep '^-') ] && \
239        Msg_MissingParameter_$LOCALE ${arg} && return 1
240
241    return 0
242}
243
244setup-vbuilder(){
245    ## load default settings
246    VBUILDER_CONF=/etc/vbootstrap/vbuilder.conf
247    if [ -r $VBUILDER_CONF ]; then
248        . $VBUILDER_CONF
249        [ $? -eq 1 ] && return 1
250    fi
251    [ -z "${DEFAULT_VERSION}" ] && \
252        DEFAULT_VERSION=@@VBUILDER_DEFAULT_VERSION@@
253    [ -z "${CATEGORIES}" ] && \
254        CATEGORIES=@@VBUILDER_CATEGORIES@@
255    [ -z "${VBOOTSTRAP_DIR}" ] && \
256        VBOOTSTRAP_DIR=@@VBUILDER_VBOOTSTRAP_DIR@@
257    [ -z "${CACHE_DIR}" ] && \
258        CACHE_DIR=@@VBUILDER_CACHE_DIR@@
259    [ -z "${BUILT_RPMS_DIR}" ] && \
260        BUILT_RPMS_DIR=@@VBUILDER_BUILT_RPMS_DIR@@
261
262    ## set default version for vbootstrap
263    VERSION=$DEFAULT_VERSION
264
265    ## set current stable relase version
266    STABLE_VERSION=@@VBUILDER_STABLE_VERSION@@
267
268    ## set locale
269    case $LANG in
270        ja*)  LOCALE=ja ;;
271        *)    LOCALE=C ;;
272    esac
273
274    ## set boolian
275    with_setup_vbootstrap=0
276    with_dist_upgrade=0
277    with_unionfs=0
278    with_sign=0
279    with_no_install=0
280    with_actions=0
281    with_category_main=0
282    with_category_plus=0
283    with_category_nonfree=0
284    with_category_test=0
285    with_category_proposed_updates=0
286    with_category_security=0
287
288    return 0
289}
290
291setup-vbootstrap(){
292    if [ ${with_setup_vbootstrap} -eq 0 ]; then
293        with_setup_vbootstrap=1
294
295        ## check some directories
296        ## Note: create $BUILT_RPMS_DIR in RPM_Build()
297        [ -d $VBOOTSTRAP_DIR ] || mkdir -p $VBOOTSTRAP_DIR
298        [ -d $CACHE_DIR ] || mkdir -p $CACHE_DIR
299
300        ## check a chroot archtecture
301        if [ -z ${VARCH} ]; then
302            VARCH=$(uname -i)
303        else
304            case "${VARCH}" in
305                i386|i686|x86_64)
306                    [ "$(uname -i)" = "ppc" ] && \
307                        Msg_NoSupportVARCH_$LOCALE && return 1
308                    ;;
309                ppc)
310                    [ "$(uname -i)" = "i386" -o "$(uname -i)" = "i686" -o "$(uname -i)" = "x86_64" ] && \
311                        Msg_NoSupportVARCH_$LOCALE && return 1
312                    ;;
313            esac
314        fi
315
316        ##!! 4.2 is NO support on VARCH=x86_64
317        if [ "${VERSION}" = "4.2" -a "${VARCH}" = "x86_64" ]; then
318            Msg_NoSupportVERSION_${LOCALE} && return 1
319        fi
320
321        ## support i386 chroot on x86_64 below:
322        [ "${VARCH}" != "$(uname -i)" ] && VERSION=${VERSION}_${VARCH}
323
324        ## check support ${VERSION}
325        if [ -z "$(/usr/sbin/vbootstrap | sed -e s/^Usage:.*// -e s/^E:.*// | grep -m 1 ${VERSION})" ]; then
326            Msg_NoSupportVERSION_$LOCALE && return 1
327        fi
328
329        ## check ${VERSION} equals VineSeed*, when with_dist_upgrade=1
330        if [ $with_dist_upgrade -eq 1 ]; then
331            if [ "$(echo ${VERSION} | sed -e "s/\(VineSeed\).*/\1/")" != "VineSeed" ]; then
332                Msg_NoSupportDistUpgradeVERSION_$LOCALE && return 1
333            fi
334        fi
335
336        ## set ${MAJOR_VERSION}
337        MAJOR_VERSION=$(echo ${VERSION} | sed -e "s/_i[0-9]86//")
338
339        ## check apt categories
340        ## "main" category is unconditionally permited
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                    ;;
353                test)
354                    ## "test" category only exists in VineSeed
355                    [ "${MAJOR_VERSION}" = "VineSeed" ] || \
356                        Msg_NoSuchCategoryExists_$LOCALE ${cat} && return 1
357                    with_category_test=1
358                    ;;
359                proposed-updates)
360                    ##!! "proposed-updates" category does not exist in 4.2
361                    [ "${MAJOR_VERSION}" = "4.2" ] && \
362                        Msg_NoSuchCategoryExists_$LOCALE ${cat} && return 1
363
364                    with_category_proposed_updates=1
365                    ;;
366                security)
367                    ## "security" category does not exist in VineSeed
368                    [ "${MAJOR_VERSION}" = "VineSeed" ] && \
369                        Msg_NoSuchCategoryExists_$LOCALE ${cat} && return 1
370                    with_category_security=1
371                    ;;
372                *)
373                    Msg_NoSuchCategoryExists_$LOCALE ${cat} && return 1
374                    ;;
375            esac
376        done
377
378        ## check build target option ${TARGET}
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
382                Msg_NoSupportTARGET_$LOCALE && return 1
383            fi
384        fi
385
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
391    fi
392
393    ## set global variables
394    BUILD_ROOT=${VBOOTSTRAP_DIR}/${VERSION}
395    BUILD_USER=vbuilder
396    BUILD_DIR=/home/${BUILD_USER}/rpm
397    UNIONFS_DIR=${VBOOTSTRAP_DIR}/unionfs/${VERSION}
398    ARCHIVES_DIR=${BUILD_ROOT}/var/cache/apt/archives
399    EXTERNAL_ARCHIVES_DIR=${CACHE_DIR}/${VERSION}/apt/archives
400    VBUILDER_LOG=${BUILD_ROOT}/var/log/vbuilder.log
401
402    __chroot_sh="/usr/sbin/chroot ${BUILD_ROOT} /bin/sh -c"
403
404    mkdir -p $VBOOTSTRAP_DIR
405
406    return 0
407}
408
409setup-vbootstrap-rpm(){
410    setup-vbootstrap || return 1
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
423
424    return 0
425}
426
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 ... "
432            apt-get -qq update > /dev/null 2>&1
433            echo "done."
434            ;;
435        --chroot)
436            echo -n "apt-get update on chroot ... "
437            $__chroot_sh 'apt-get -qq update' > /dev/null 2>&1
438            echo "done."
439            ;;
440        *)
441            echo apt-get-update: unknown option $1
442            exit 1
443            ;;
444    esac
445}
446
447## mount-chroot {|--umount} [file system|name]
448## support file systems: /home /tmp /sys /proc /dev/shm /dev/pts /dev
449## support name: vfs archives_dir
450## NOTE: /tmp needs for applications which use X
451##       vfs is virtual file systems
452##       archives_dir uses to mount ${EXTERNAL_ARCHIVES_DIR} to ${ARCHIVES_DIR}
453##       unionfs_dir covers ${BUILD_ROOT} with unionfs
454mount-chroot(){
455    if [ "$1" = "--umount" ]; then
456        mount-chroot-umount $2 || return 1
457    else
458        mount-chroot-mount $1 || return 1
459    fi
460    return 0
461}
462
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            ;;
480        archives_dir)
481            [ -d ${ARCHIVES_DIR} ] || return 1
482            [ -z "$(mount | grep ${ARCHIVES_DIR})" ] || \
483                umount ${ARCHIVES_DIR}
484            ;;
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            ;;
495        *)
496            echo mount-chroot-umount: unknown file system $fs
497            exit 1
498            ;;
499    esac
500    return 0
501}
502
503## mount-chroot-mount [file system|name]
504mount-chroot-mount(){
505    local fs=$1
506    local mnt_opts=""
507
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            ;;
529        archives_dir)
530            [ -d ${EXTERNAL_ARCHIVES_DIR} ] || mkdir -p ${EXTERNAL_ARCHIVES_DIR}
531            [ -d ${ARCHIVES_DIR} ] || mkdir -p ${ARCHIVES_DIR}
532            [ -z "$(mount | grep ${ARCHIVES_DIR})" ] && \
533                mount ${mnt_opts} ${EXTERNAL_ARCHIVES_DIR} ${ARCHIVES_DIR}
534            [ -d ${ARCHIVES_DIR}/partial ] || mkdir -p ${ARCHIVES_DIR}/partial
535            ;;
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            ;;
544        *)
545            echo mount-chroot-mount: unknown file system $fs
546            exit 1
547            ;;
548    esac
549    return 0
550}
551
552write-vbuilder-log(){
553    HRULE="======================================================================"
554
555    [ -d ${BUILD_ROOT} ] || return 1
556
557    if [ ! -f $VBUILDER_LOG ]; then
558        cat<<EOF > $VBUILDER_LOG
559${HRULE}
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
566--version: ${VERSION}
567$(echo $([ -z "${VARCH}" ] || echo "--arch: ${VARCH}"))
568$(echo $([ -z "${CATEGORIES}" ] || echo "--category: ${CATEGORIES}"))
569$(echo $([ $with_dist_upgrade -eq 1 ] && echo "--dist-upgrade"))
570$(echo $([ $with_unionfs -eq 1 ] && echo "--unionfs"))
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}
576
577[$VBUILDER_CONF]
578$(cat $VBUILDER_CONF)
579
580[History]
581EOF
582    else
583        cat<<EOF >> $VBUILDER_LOG
584$*
585EOF
586    fi
587
588    return 0
589}
590
591##############################################################################
592
593Clean(){
594    setup-vbootstrap || return 1
595
596    # # output end-of-line in $VBUILDER_LOG
597    # [ -f $VBUILDER_LOG ] && write-vbuilder-log ${HRULE}
598    # Show-Info
599
600    # mount-chroot --umount /home
601    # mount-chroot --umount /tmp
602    mount-chroot --umount vfs
603    mount-chroot --umount archives_dir
604    mount-chroot --umount unionfs_dir
605    apt-get-update --host
606
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
619    fi
620
621    echo "Cleanup a build farm for ${VERSION} done."
622    return 0
623}
624
625Build(){
626    setup-vbootstrap || return 1
627
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}
633
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
641    mount-chroot archives_dir
642    mount-chroot vfs
643    # mount-chroot /tmp
644    # mount-chroot /home
645
646    $__chroot_sh 'apt-get -qq update && apt-get -qq -y dist-upgrade'
647
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"
652            # [ $with_category_security -eq 1 ] && \
653            #   echo
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'
662            # [ $with_category_security -eq 1 ] && \
663            #   echo
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'
670            [ $with_category_test -eq 1 ] && \
671                $__chroot_sh 'apt-get -qq update && apt-get -qq -y install apt-sourceslist-test'
672            ;;
673    esac
674
675    [ $with_dist_upgrade -eq 1 ] && \
676        $__chroot_sh 'apt-get -qq update && apt-get -qq -y dist-upgrade'
677
678    $__chroot_sh 'apt-get -qq -y install build-essential'
679
680    [ $with_category_nonfree -eq 1 ] && \
681        $__chroot_sh 'apt-get -qq -y install self-build-setup'
682
683    $__chroot_sh 'apt-get -qq -y install etcskel shadow-utils'
684
685    $__chroot_sh 'cd /dev && /sbin/MAKEDEV console'
686    $__chroot_sh 'cd /dev && /sbin/MAKEDEV null'
687    $__chroot_sh 'cd /dev && /sbin/MAKEDEV zero'
688    $__chroot_sh 'cd /dev && /sbin/MAKEDEV random'
689    $__chroot_sh 'cd /dev && /sbin/MAKEDEV urandom'
690
691    $__chroot_sh '/usr/sbin/pwconv'
692    $__chroot_sh "/usr/sbin/useradd ${BUILD_USER}"
693
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
697        $__chroot_sh "sed -i -e 's/^%_topdir/#%_topdir/' /home/${BUILD_USER}/.rpmmacros"
698    fi
699
700    ## output basic informations in chroot
701    write-vbuilder-log
702    write-vbuilder-log "build"
703
704    # mount-chroot --umount /home
705    # mount-chroot --umount /tmp
706    mount-chroot --umount vfs
707    mount-chroot --umount archives_dir
708    apt-get-update --host
709
710    echo "Making a build farm for ${VERSION} done."
711    return 0
712}
713
714Show-Info(){
715    setup-vbootstrap || return 1
716
717    [ -f $VBUILDER_LOG ] && cat $VBUILDER_LOG
718
719    return 0
720}
721
722RPM_Remove(){
723    setup-vbootstrap-rpm || return 1
724    mount-chroot unionfs_dir
725    mount-chroot archives_dir
726    mount-chroot vfs
727    apt-get-update --chroot
728
729    [ -f $RPM_PKG ] && Msg_NotPackageName_$LOCALE $RPM_PKG && return 1
730    $__chroot_sh "apt-get -y remove $BASE_RPM_PKG"
731
732    write-vbuilder-log "remove-rpm $RPM_PKG"
733
734    mount-chroot --umount vfs
735    mount-chroot --umount archives_dir
736    mount-chroot --umount unionfs_dir
737    apt-get-update --host
738
739    return 0
740}
741
742RPM_Install(){
743    setup-vbootstrap-rpm || return 1
744    mount-chroot unionfs_dir
745    mount-chroot archives_dir
746    mount-chroot vfs
747    apt-get-update --chroot
748
749    $__chroot_sh "cd ${BUILD_DIR} && apt-get -y install $BASE_RPM_PKG"
750
751    write-vbuilder-log "install-rpm $RPM_PKG"
752
753    mount-chroot --umount vfs
754    mount-chroot --umount archives_dir
755    mount-chroot --umount unionfs_dir
756    apt-get-update --host
757
758    return 0
759}
760
761RPM_Build(){
762    setup-vbootstrap-rpm || return 1
763    mount-chroot unionfs_dir
764    mount-chroot archives_dir
765    mount-chroot vfs
766    apt-get-update --chroot
767
768    [ ! -f $RPM_PKG ] && Msg_NotSourceRPM_$LOCALE $RPM_PKG && return 1
769   
770    RPM_PKG_USER=$(stat -c %U $RPM_PKG)
771    RPM_PKG_GROUP=$(stat -c %G $RPM_PKG)
772    [ ! -z "${SUDO_UID}" ] && RPM_PKG_USER=${SUDO_UID}
773    [ ! -z "${SUDO_GID}" ] && RPM_PKG_GROUP=${SUDO_GID}
774    local __install="install -p -v -o ${RPM_PKG_USER} -g ${RPM_PKG_GROUP}"
775
776    ## make src.rpm for $VERSION
777    $__chroot_sh "cd ${BUILD_DIR} && su ${BUILD_USER} -c 'rpm -ivh $BASE_RPM_PKG'"
778    $__chroot_sh "cd ${BUILD_DIR} && su ${BUILD_USER} -c 'rpmbuild -bs --nodeps --clean --rmsource --rmspec $RPM_OPTS ${BUILD_DIR}/SPECS/*.spec'"
779
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}
785    $__chroot_sh "cd ${BUILD_DIR}/SRPMS && apt-get -o APT::Install::Virtual=true -y build-dep $BASE_RPM_PKG"
786    $__chroot_sh "cd ${BUILD_DIR}/SRPMS && su ${BUILD_USER} -c 'rpmbuild --rebuild $RPM_OPTS $BASE_RPM_PKG'"
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')"
789
790    ## copy built rpms to ${HOME}/rpm/ for each archtectures
791    echo "Copying built rpms to ${BUILT_RPMS_DIR} for each archtectures ... "
792    for i in $RPM_PKG_ARCH_LIST; do \
793        if [ -d $BUILD_ROOT${BUILD_DIR}/${i} ]; then
794            if [ ! -d ${BUILT_RPMS_DIR}/${MAJOR_VERSION}/${i} ]; then
795                $__install -d ${BUILT_RPMS_DIR}/${MAJOR_VERSION}/${i}/
796                chown -R ${RPM_PKG_USER}:${RPM_PKG_GROUP} ${BUILT_RPMS_DIR}
797            fi
798            find $BUILD_ROOT${BUILD_DIR}/${i} -type f -regex '.*\.rpm' \
799                -exec $__install -m0644 {} ${BUILT_RPMS_DIR}/${MAJOR_VERSION}/${i}/ \;
800        fi
801    done
802
803    write-vbuilder-log "build-rpm $RPM_PKG"
804
805    mount-chroot --umount vfs
806    mount-chroot --umount archives_dir
807    mount-chroot --umount unionfs_dir
808    apt-get-update --host
809
810    echo "done."
811    return 0
812}
813
814RPM_Sign(){
815    [ $with_sign -eq 1 ] || return 1
816
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
821    return 0
822}
823
824
825##############################################################################
826
827setup-vbuilder || exit 1
828
829check-parameter $* || exit 1
830
831while [ $# -gt 0 ]; do
832    tmpARG=$1
833    case $tmpARG in
834        --version|--arch|--category|--target|--rpmbuild-with|--bootstrap-dir|--cache-dir|--built-rpms-dir)
835            shift
836            ;;
837        --dist-upgrade|--unionfs|--with-compat32|--sign|--no-install)
838            ;;
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            ;;
844        *)
845            echo unknown option $1
846            exit 1
847            ;;
848    esac
849
850    case $tmpARG in
851        --version)
852            VERSION=$1
853            ;;
854        --arch)
855            VARCH=$1
856            ;;
857        --category)
858            CATEGORIES=$1
859            ;;
860        --dist-upgrade)
861            with_dist_upgrade=1
862            ;;
863        --unionfs)
864            with_unionfs=1
865            ;;
866        --target)
867            TARGET=$1
868            RPM_OPTS="${RPM_OPTS} --target $TARGET"
869            ;;
870        --with-compat32)
871            RPM_OPTS="${RPM_OPTS} --with compat32"
872            ;;
873        --rpmbuild-with)
874            RPM_OPTS="${RPM_OPTS} --with $1"
875            ;;
876        --sign)
877            with_sign=1
878            ;;
879        --no-install)
880            with_no_install=1
881            ;;
882        --bootstrap-dir)
883            VBOOTSTRAP_DIR=$1
884            ;;
885        --cache-dir)
886            CACHE_DIR=$1
887            ;;
888        --built-rpms-dir)
889            BUILT_RPMS_DIR=$1
890            ;;
891        --build-rpm|build-rpm)
892            RPM_PKG=$1
893            RPM_Build || exit 1
894            ;;
895        --install-rpm|install-rpm)
896            RPM_PKG=$1
897            RPM_Install || exit 1
898            ;;
899        --remove-rpm|remove-rpm)
900            RPM_PKG=$1
901            RPM_Remove || exit 1
902            ;;
903        --show-info|show-info)
904            Show-Info || exit 1
905            ;;
906        --build|build)
907            Build || exit 1
908            ;;
909        --clean|clean)
910            Clean || exit 1
911            ;;
912    esac
913    shift
914done
915
916RPM_Sign
917
918exit
Note: See TracBrowser for help on using the repository browser.