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

Revision 2514, 24.0 KB checked in by munepi, 13 years ago (diff)

updated vbuilder.sh.in: defined require-root() (Thanks to tomo-p-san)

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
597require-root(){
598  if [ $USER != "root" ]; then
599    echo "The root privilege is required."
600    sudo $0 $*
601    return $?
602  fi
603}
604
605##############################################################################
606
607Clean(){
608    setup-vbootstrap || return 1
609
610    # # output end-of-line in $VBUILDER_LOG
611    # [ -f $VBUILDER_LOG ] && write-vbuilder-log ${HRULE}
612    # Show-Info
613
614    # mount-chroot --umount /home
615    # mount-chroot --umount /tmp
616    mount-chroot --umount vfs
617    mount-chroot --umount archives_dir
618    mount-chroot --umount unionfs_dir
619    apt-get-update --host
620
621    if [ $with_unionfs -eq 1 ]; then
622        if [ -d ${UNIONFS_DIR} ]; then
623            echo -n "Cleaning build root \"${UNIONFS_DIR}\" via unionfs ... "
624            rm -rf ${UNIONFS_DIR}
625            echo "done."
626        fi
627    else
628        if [ -d ${BUILD_ROOT} ]; then
629            echo -n "Cleaning build root \"${BUILD_ROOT}\" ... "
630            rm -rf ${BUILD_ROOT}
631            echo "done."
632        fi
633    fi
634
635    echo "Cleanup a build farm for ${VERSION} done."
636    return 0
637}
638
639Build(){
640    setup-vbootstrap || return 1
641
642    if [ $with_dist_upgrade -eq 1 ]; then
643        ## make bootstrap of ${STABLE_VERSION}
644        /usr/sbin/vbootstrap \
645            $(echo ${VERSION} | sed -e "s/VineSeed/${STABLE_VERSION}/") \
646            ${BUILD_ROOT}
647
648        ## aim apt-line to VineSeed
649        sed -i "s/apt ${STABLE_VERSION}/apt VineSeed/g" \
650            ${BUILD_ROOT}/etc/apt/sources.list.d/main.list
651    else
652        /usr/sbin/vbootstrap ${VERSION} ${BUILD_ROOT}
653    fi
654
655    mount-chroot archives_dir
656    mount-chroot vfs
657    # mount-chroot /tmp
658    # mount-chroot /home
659
660    $__chroot_sh 'apt-get -qq update && apt-get -qq -y dist-upgrade'
661
662    ##!! 4.2 has no apt-sourceslist-{plus,nonfree,proposed-updates} packages
663    case ${MAJOR_VERSION} in
664        4.2)
665            $__chroot_sh "sed -i -e 's/main plus updates nonfree *$/$(echo ${CATEGORIES} | sed -e "s/,/ /"g) updates/g' /etc/apt/sources.list"
666            # [ $with_category_security -eq 1 ] && \
667            #   echo
668            ;;
669        @@VBUILDER_STABLE_VERSION@@)
670            [ $with_category_plus -eq 1 ] && \
671                $__chroot_sh 'apt-get -qq update && apt-get -qq -y install apt-sourceslist-plus'
672            [ $with_category_nonfree -eq 1 ] && \
673                $__chroot_sh 'apt-get -qq update && apt-get -qq -y install apt-sourceslist-nonfree'
674            [ $with_category_proposed_updates -eq 1 ] && \
675                $__chroot_sh 'apt-get -qq update && apt-get -qq -y install apt-sourceslist-proposed-updates'
676            # [ $with_category_security -eq 1 ] && \
677            #   echo
678            ;;
679        VineSeed)
680            [ $with_category_plus -eq 1 ] && \
681                $__chroot_sh 'apt-get -qq update && apt-get -qq -y install apt-sourceslist-plus'
682            [ $with_category_nonfree -eq 1 ] && \
683                $__chroot_sh 'apt-get -qq update && apt-get -qq -y install apt-sourceslist-nonfree'
684            [ $with_category_test -eq 1 ] && \
685                $__chroot_sh 'apt-get -qq update && apt-get -qq -y install apt-sourceslist-test'
686            ;;
687    esac
688
689    [ $with_dist_upgrade -eq 1 ] && \
690        $__chroot_sh 'apt-get -qq update && apt-get -qq -y dist-upgrade'
691
692    $__chroot_sh 'apt-get -qq -y install build-essential'
693
694    [ $with_category_nonfree -eq 1 ] && \
695        $__chroot_sh 'apt-get -qq -y install self-build-setup'
696
697    $__chroot_sh 'apt-get -qq -y install etcskel shadow-utils'
698
699    $__chroot_sh 'cd /dev && /sbin/MAKEDEV console'
700    $__chroot_sh 'cd /dev && /sbin/MAKEDEV null'
701    $__chroot_sh 'cd /dev && /sbin/MAKEDEV zero'
702    $__chroot_sh 'cd /dev && /sbin/MAKEDEV random'
703    $__chroot_sh 'cd /dev && /sbin/MAKEDEV urandom'
704
705    $__chroot_sh '/usr/sbin/pwconv'
706    $__chroot_sh "/usr/sbin/useradd ${BUILD_USER}"
707
708    ##!! for rpm-4.8.0 or higher
709    ##!! (See http://trac.vinelinux.org/wiki/Vine6/AboutUpdateToolchain)
710    if [ "$(echo ${VERSION} | sed -e "s/\(VineSeed\).*/\1/")" = "VineSeed" ]; then
711        $__chroot_sh "sed -i -e 's/^%_topdir/#%_topdir/' /home/${BUILD_USER}/.rpmmacros"
712    fi
713
714    ## output basic informations in chroot
715    write-vbuilder-log
716    write-vbuilder-log "build"
717
718    # mount-chroot --umount /home
719    # mount-chroot --umount /tmp
720    mount-chroot --umount vfs
721    mount-chroot --umount archives_dir
722    apt-get-update --host
723
724    echo "Making a build farm for ${VERSION} done."
725    return 0
726}
727
728Show-Info(){
729    setup-vbootstrap || return 1
730
731    [ -f $VBUILDER_LOG ] && cat $VBUILDER_LOG
732
733    return 0
734}
735
736RPM_Remove(){
737    setup-vbootstrap-rpm || return 1
738    mount-chroot unionfs_dir
739    mount-chroot archives_dir
740    mount-chroot vfs
741    apt-get-update --chroot
742
743    [ -f $RPM_PKG ] && Msg_NotPackageName_$LOCALE $RPM_PKG && return 1
744    $__chroot_sh "apt-get -y remove $BASE_RPM_PKG"
745
746    write-vbuilder-log "remove-rpm $RPM_PKG"
747
748    mount-chroot --umount vfs
749    mount-chroot --umount archives_dir
750    mount-chroot --umount unionfs_dir
751    apt-get-update --host
752
753    return 0
754}
755
756RPM_Install(){
757    setup-vbootstrap-rpm || return 1
758    mount-chroot unionfs_dir
759    mount-chroot archives_dir
760    mount-chroot vfs
761    apt-get-update --chroot
762
763    $__chroot_sh "cd ${BUILD_DIR} && apt-get -y install $BASE_RPM_PKG"
764
765    write-vbuilder-log "install-rpm $RPM_PKG"
766
767    mount-chroot --umount vfs
768    mount-chroot --umount archives_dir
769    mount-chroot --umount unionfs_dir
770    apt-get-update --host
771
772    return 0
773}
774
775RPM_Build(){
776    setup-vbootstrap-rpm || return 1
777    mount-chroot unionfs_dir
778    mount-chroot archives_dir
779    mount-chroot vfs
780    apt-get-update --chroot
781
782    [ ! -f $RPM_PKG ] && Msg_NotSourceRPM_$LOCALE $RPM_PKG && return 1
783   
784    RPM_PKG_USER=$(stat -c %U $RPM_PKG)
785    RPM_PKG_GROUP=$(stat -c %G $RPM_PKG)
786    [ ! -z "${SUDO_UID}" ] && RPM_PKG_USER=${SUDO_UID}
787    [ ! -z "${SUDO_GID}" ] && RPM_PKG_GROUP=${SUDO_GID}
788    local __install="install -p -v -o ${RPM_PKG_USER} -g ${RPM_PKG_GROUP}"
789
790    ## make src.rpm for $VERSION
791    $__chroot_sh "cd ${BUILD_DIR} && su ${BUILD_USER} -c 'rpm -ivh $BASE_RPM_PKG'"
792    $__chroot_sh "cd ${BUILD_DIR} && su ${BUILD_USER} -c 'rpmbuild -bs --nodeps --clean --rmsource --rmspec $RPM_OPTS ${BUILD_DIR}/SPECS/*.spec'"
793
794
795    ## change ${DIST_RELEASE}
796    BASE_RPM_PKG=$(echo $BASE_RPM_PKG | sed -e "s/vl\([0-9]*\)\./vl${DIST_RELEASE}\./")
797
798    ## rebuild $BASE_RPM_PKG on ${DIST_RELEASE}
799    $__chroot_sh "cd ${BUILD_DIR}/SRPMS && apt-get -o APT::Install::Virtual=true -y build-dep $BASE_RPM_PKG"
800    $__chroot_sh "cd ${BUILD_DIR}/SRPMS && su ${BUILD_USER} -c 'rpmbuild --rebuild $RPM_OPTS $BASE_RPM_PKG'"
801    [ $with_no_install -eq 0 ] && \
802        $__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')"
803
804    ## copy built rpms to ${HOME}/rpm/ for each archtectures
805    echo "Copying built rpms to ${BUILT_RPMS_DIR} for each archtectures ... "
806    for i in $RPM_PKG_ARCH_LIST; do \
807        if [ -d $BUILD_ROOT${BUILD_DIR}/${i} ]; then
808            if [ ! -d ${BUILT_RPMS_DIR}/${MAJOR_VERSION}/${i} ]; then
809                $__install -d ${BUILT_RPMS_DIR}/${MAJOR_VERSION}/${i}/
810                chown -R ${RPM_PKG_USER}:${RPM_PKG_GROUP} ${BUILT_RPMS_DIR}
811            fi
812            find $BUILD_ROOT${BUILD_DIR}/${i} -type f -regex '.*\.rpm' \
813                -exec $__install -m0644 {} ${BUILT_RPMS_DIR}/${MAJOR_VERSION}/${i}/ \;
814        fi
815    done
816
817    write-vbuilder-log "build-rpm $RPM_PKG"
818
819    mount-chroot --umount vfs
820    mount-chroot --umount archives_dir
821    mount-chroot --umount unionfs_dir
822    apt-get-update --host
823
824    echo "done."
825    return 0
826}
827
828RPM_Sign(){
829    [ $with_sign -eq 1 ] || return 1
830
831    [ -z "${SUDO_USER}" ] && Msg_SUDO_USERisEmpty_$LOCALE && return 1
832
833    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')"
834
835    return 0
836}
837
838
839##############################################################################
840
841require-root $* || exit 1
842
843setup-vbuilder || exit 1
844
845check-parameter $* || exit 1
846
847while [ $# -gt 0 ]; do
848    tmpARG=$1
849    case $tmpARG in
850        --version|--arch|--category|--target|--rpmbuild-with|--bootstrap-dir|--cache-dir|--built-rpms-dir)
851            shift
852            ;;
853        --dist-upgrade|--unionfs|--with-compat32|--sign|--no-install)
854            ;;
855        --build-rpm|build-rpm|--install-rpm|install-rpm|--remove-rpm|remove-rpm)
856            shift
857            ;;
858        --build|build|--clean|clean|--show-info|show-info)
859            ;;
860        *)
861            echo unknown option $1
862            exit 1
863            ;;
864    esac
865
866    case $tmpARG in
867        --version)
868            VERSION=$1
869            ;;
870        --arch)
871            VARCH=$1
872            ;;
873        --category)
874            CATEGORIES=$1
875            ;;
876        --dist-upgrade)
877            with_dist_upgrade=1
878            ;;
879        --unionfs)
880            with_unionfs=1
881            ;;
882        --target)
883            TARGET=$1
884            RPM_OPTS="${RPM_OPTS} --target $TARGET"
885            ;;
886        --with-compat32)
887            RPM_OPTS="${RPM_OPTS} --with compat32"
888            ;;
889        --rpmbuild-with)
890            RPM_OPTS="${RPM_OPTS} --with $1"
891            ;;
892        --sign)
893            with_sign=1
894            ;;
895        --no-install)
896            with_no_install=1
897            ;;
898        --bootstrap-dir)
899            VBOOTSTRAP_DIR=$1
900            ;;
901        --cache-dir)
902            CACHE_DIR=$1
903            ;;
904        --built-rpms-dir)
905            BUILT_RPMS_DIR=$1
906            ;;
907        --build-rpm|build-rpm)
908            RPM_PKG=$1
909            RPM_Build || exit 1
910            ;;
911        --install-rpm|install-rpm)
912            RPM_PKG=$1
913            RPM_Install || exit 1
914            ;;
915        --remove-rpm|remove-rpm)
916            RPM_PKG=$1
917            RPM_Remove || exit 1
918            ;;
919        --show-info|show-info)
920            Show-Info || exit 1
921            ;;
922        --build|build)
923            Build || exit 1
924            ;;
925        --clean|clean)
926            Clean || exit 1
927            ;;
928    esac
929    shift
930done
931
932RPM_Sign
933
934exit
Note: See TracBrowser for help on using the repository browser.