source: projects/vbootstrap/tags/0.0.33/vbuilder.sh.in @ 2468

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

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

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