source: projects/vbootstrap/tags/0.0.28/vbuilder.sh.in @ 1014

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

added to make /dev/urandom in Build()

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    $__chroot_sh 'cd /dev && /sbin/MAKEDEV urandom'
663
664    $__chroot_sh '/usr/sbin/pwconv'
665    $__chroot_sh "/usr/sbin/useradd ${BUILD_USER}"
666
667    ##!! for rpm-4.8.0 or higher
668    ##!! (See http://trac.vinelinux.org/wiki/Vine6/AboutUpdateToolchain)
669    if [ "$(echo ${VERSION} | sed -e "s/\(VineSeed\).*/\1/")" = "VineSeed" ]; then
670        $__chroot_sh "sed -i -e 's/^%_topdir/#%_topdir/' /home/${BUILD_USER}/.rpmmacros"
671    fi
672
673    ## output basic informations in chroot
674    write-vbuilder-log
675    write-vbuilder-log "build"
676
677    # mount-chroot --umount /home
678    # mount-chroot --umount /tmp
679    mount-chroot --umount vfs
680    mount-chroot --umount archives_dir
681    apt-get-update --host
682
683    echo "Making a build farm for ${VERSION} done."
684}
685
686Show-Info(){
687    setup-vbootstrap
688
689    [ -f $VBUILDER_LOG ] && cat $VBUILDER_LOG
690}
691
692RPM_Remove(){
693    setup-vbootstrap-rpm
694    mount-chroot unionfs_dir
695    mount-chroot archives_dir
696    mount-chroot vfs
697    apt-get-update --chroot
698
699    [ -f $RPM_PKG ] && Msg_NotPackageName_$LOCALE $RPM_PKG && exit 1
700    $__chroot_sh "apt-get -y remove $BASE_RPM_PKG"
701
702    write-vbuilder-log "remove-rpm $RPM_PKG"
703
704    mount-chroot --umount vfs
705    mount-chroot --umount archives_dir
706    mount-chroot --umount unionfs_dir
707    apt-get-update --host
708}
709
710RPM_Install(){
711    setup-vbootstrap-rpm
712    mount-chroot unionfs_dir
713    mount-chroot archives_dir
714    mount-chroot vfs
715    apt-get-update --chroot
716
717    $__chroot_sh "cd ${BUILD_DIR} && apt-get -y install $BASE_RPM_PKG"
718
719    write-vbuilder-log "install-rpm $RPM_PKG"
720
721    mount-chroot --umount vfs
722    mount-chroot --umount archives_dir
723    mount-chroot --umount unionfs_dir
724    apt-get-update --host
725}
726
727RPM_Build(){
728    setup-vbootstrap-rpm
729    mount-chroot unionfs_dir
730    mount-chroot archives_dir
731    mount-chroot vfs
732    apt-get-update --chroot
733
734    [ ! -f $RPM_PKG ] && Msg_NotSourceRPM_$LOCALE $RPM_PKG && exit 1
735   
736    RPM_PKG_USER=$(stat -c %U $RPM_PKG)
737    RPM_PKG_GROUP=$(stat -c %G $RPM_PKG)
738    [ ! -z "${SUDO_UID}" ] && RPM_PKG_USER=${SUDO_UID}
739    [ ! -z "${SUDO_GID}" ] && RPM_PKG_GROUP=${SUDO_GID}
740    local __install="install -p -v -o ${RPM_PKG_USER} -g ${RPM_PKG_GROUP}"
741    RPM_PKG_ARCH_LIST="RPMS/i386 RPMS/i686 RPMS/x86_64 RPMS/ppc RPMS/noarch SRPMS"
742    [ -z "${TARGET}" ] || \
743        RPM_PKG_ARCH_LIST="RPMS/${TARGET} ${RPM_PKG_ARCH_LIST}"
744
745    ## make src.rpm for $VERSION
746    $__chroot_sh "cd ${BUILD_DIR} && su ${BUILD_USER} -c 'rpm -ivh $BASE_RPM_PKG'"
747    $__chroot_sh "cd ${BUILD_DIR} && su ${BUILD_USER} -c 'rpmbuild -bs --nodeps --clean --rmsource --rmspec ${BUILD_DIR}/SPECS/*.spec'"
748
749
750    ## change ${DIST_RELEASE}
751    BASE_RPM_PKG=$(echo $BASE_RPM_PKG | sed -e "s/vl\([0-9]*\)\./vl${DIST_RELEASE}\./")
752
753    ## rebuild $BASE_RPM_PKG on ${DIST_RELEASE}
754    $__chroot_sh "cd ${BUILD_DIR}/SRPMS && apt-get -o APT::Install::Virtual=true -y build-dep $BASE_RPM_PKG"
755    $__chroot_sh "cd ${BUILD_DIR}/SRPMS && su ${BUILD_USER} -c 'rpmbuild --rebuild $RPM_OPTS $BASE_RPM_PKG'"
756    $__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')"
757
758    ## copy built rpms to ${HOME}/rpm/ for each archtectures
759    echo "Copying built rpms to ${BUILT_RPMS_DIR} for each archtectures ... "
760    for i in $RPM_PKG_ARCH_LIST; do \
761        if [ -d $BUILD_ROOT${BUILD_DIR}/${i} ]; then
762            if [ ! -d ${BUILT_RPMS_DIR}/${MAJOR_VERSION}/${i} ]; then
763                $__install -d ${BUILT_RPMS_DIR}/${MAJOR_VERSION}/${i}/
764                chown -R ${RPM_PKG_USER}:${RPM_PKG_GROUP} ${BUILT_RPMS_DIR}
765            fi
766            find $BUILD_ROOT${BUILD_DIR}/${i} -type f -regex '.*\.rpm' \
767                -exec $__install -m0644 {} ${BUILT_RPMS_DIR}/${MAJOR_VERSION}/${i}/ \;
768        fi
769    done
770
771    write-vbuilder-log "build-rpm $RPM_PKG"
772
773    mount-chroot --umount vfs
774    mount-chroot --umount archives_dir
775    mount-chroot --umount unionfs_dir
776    apt-get-update --host
777
778    echo "done."
779}
780
781
782##############################################################################
783
784setup-vbuilder
785
786check-parameter $* || exit 1
787
788while [ $# -gt 0 ]; do
789    tmpARG=$1
790    case $tmpARG in
791        --version|--arch|--category|--target|--bootstrap-dir|--cache-dir|--built-rpms-dir)
792            shift
793            ;;
794        --dist-upgrade|--unionfs|--with-compat32)
795            ;;
796        --build-rpm|build-rpm|--install-rpm|install-rpm|--remove-rpm|remove-rpm)
797            shift
798            ;;
799        --build|build|--clean|clean|--show-info|show-info)
800            ;;
801        *)
802            echo unknown option $1
803            exit 1
804            ;;
805    esac
806
807    case $tmpARG in
808        --version)
809            VERSION=$1
810            ;;
811        --arch)
812            VARCH=$1
813            ;;
814        --category)
815            CATEGORIES=$1
816            ;;
817        --dist-upgrade)
818            with_dist_upgrade=1
819            ;;
820        --unionfs)
821            with_unionfs=1
822            ;;
823        --target)
824            TARGET=$1
825            RPM_OPTS="${RPM_OPTS} --target $TARGET"
826            ;;
827        --with-compat32)
828            RPM_OPTS="${RPM_OPTS} --with compat32"
829            ;;
830        --bootstrap-dir)
831            VBOOTSTRAP_DIR=$1
832            ;;
833        --cache-dir)
834            CACHE_DIR=$1
835            ;;
836        --built-rpms-dir)
837            BUILT_RPMS_DIR=$1
838            ;;
839        --build-rpm|build-rpm)
840            RPM_PKG=$1
841            RPM_Build || exit 1
842            ;;
843        --install-rpm|install-rpm)
844            RPM_PKG=$1
845            RPM_Install || exit 1
846            ;;
847        --remove-rpm|remove-rpm)
848            RPM_PKG=$1
849            RPM_Remove || exit 1
850            ;;
851        --show-info|show-info)
852            Show-Info
853            ;;
854        --build|build)
855            Build
856            ;;
857        --clean|clean)
858            Clean
859            ;;
860    esac
861    shift
862done
863
864exit
Note: See TracBrowser for help on using the repository browser.