source: projects/vbootstrap/trunk/vbuilder.sh.in @ 1240

Revision 1240, 23.2 KB checked in by munepi, 14 years ago (diff)

update vbuilder.sh.in: added --sign option

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