source: projects/vbootstrap/tags/0.0.29/vbuilder.sh.in @ 1376

Revision 1376, 23.4 KB checked in by munepi, 14 years ago (diff)

tagging 0.0.29

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