source: projects/vbootstrap/tags/0.0.24/vbuilder.sh.in @ 791

Revision 791, 21.5 KB checked in by munepi, 14 years ago (diff)

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