source: projects/vbootstrap/tags/0.0.26/vbuilder.sh.in @ 923

Revision 923, 22.3 KB checked in by munepi, 14 years ago (diff)

tagging 0.0.26

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