source: projects/vbootstrap/tags/0.0.48/vbuilder.sh.in @ 5368

Revision 5368, 29.7 KB checked in by munepi, 12 years ago (diff)

DEFAULT_VERSION を廃止

Line 
1#!/bin/bash
2# -*- coding: utf-8-unix -*-
3
4TEXTDOMAIN=vbootstrap
5TEXTDOMAINDIR=/usr/share/locale
6
7Usage(){
8    cat<<EOF
9$(basename $0) @@VBUILDER_VERSION@@ $(echo $([ -z "@@VBUILDER_REVISION@@" ] || echo "(r@@VBUILDER_REVISION@@)"))
10Usage:  $(basename $0) {--profile [profile]} {--version [version]} {--arch [arch]} {--category [categories]} {--fetch-url [fetch_url]} {--dist-upgrade} {--target [target]} {--with-compat32} {--rpmbuild-define [macro_expr]} {--rpmbuild-with [bcond_with]} {--rpmbuild-without [bcond_with]} {--sign} {--no-install} {--debug} {--help} {--bootstrap-dir [directory]} {--unionfs-dir [directory]} {--cache-dir [directory]} {--built-rpms-dir [directory]} {clean|build|build-rpm [src.rpm]|install-rpm [arch.rpm|package]|remove-rpm [package]}
11EOF
12
13    echo $"
14Options:
15        --profile:              set a profile
16        --version:              set [version] (default: ${DEFAULT_VERSION})
17        --arch:                 set [arch] (default: ${UARCH})
18        --category:             set [categories] (default: ${CATEGORIES})
19        --fetch-url:            set [fetch_url] to fetch packages (default: ${VBOOTSTRAP_FETCH_URL})
20        --dist-upgrade:         make VineSeed bootstrap via ${STABLE_VERSION}
21        --unionfs:              cover a bootstrap with unionfs
22        --target:               build rpms with [target]
23        --with-compat32:        build rpms with compat32 on bootstrap
24        --rpmbuild-define:      give a option --define [macro_expr] to rpmbuild
25        --rpmbuild-with:        give a option --with [bcond_with] to rpmbuild
26        --rpmbuild-without:     give a option --without [bcond_with] to rpmbuild
27        --sign:                 sign built rpms
28        --no-install:           build only a source rpm - do NOT install a built rpm
29        --login:                login in chroot as root user
30        --bootstrap-dir:        set a bootstrap directory (default: ${VBOOTSTRAP_DIR})
31        --unionfs-dir:          set a directory to store unionfs images of vbootstrap (default: ${UNIONFS_DIR})
32        --cache-dir:            set a directory to cache rpms (default: ${CACHE_DIR})
33        --built-rpms-dir:       set a directory to store built rpms in chroot (default: ${BUILT_RPMS_DIR})
34        --debug:                enable debug mode
35        --help:                 show this help
36"
37
38    echo $"
39Actions:
40        clean:                  clean the bootstrap of [version]
41        build:                  build a bootstrap of [version]
42        build-rpm:              build [src.rpm] on a bootstrap
43        install-rpm:            install [arch.rpm|package] on a bootstrap
44        remove-rpm:             remove [package] on a bootstrap
45"
46
47    echo $"
48Examples:
49* make a clean/plain build environment on the current archtecture:
50$(basename $0) clean build
51* build rpms from the specified source rpm:
52$(basename $0) build-rpm [src.rpm]
53* make a plain build environment for Vine Linux 5.2:
54$(basename $0) --version 5.2 clean build
55* make a i386 chroot on x86_64:
56$(basename $0) --arch i386 clean build
57* build a kernel package with target i686:
58$(basename $0) --target i686 build-rpm [kernel src.rpm]
59* build a compat32 package:
60$(basename $0) --arch i386 --with-compat32 build-rpm [src.rpm]
61"
62    /usr/sbin/vbootstrap | sed -e s/^Usage:.*// -e s/^E:.*//
63## TODO: output supported profiles and their names/comments
64}
65
66##############################################################################
67
68initialize-variables(){
69    ## set boolian variables
70    with_profile=0
71    with_setup_vbootstrap=0
72    with_dist_upgrade=0
73    with_unionfs=0
74    with_sign=0
75    with_no_install=0
76    with_login=0
77    with_debug=0
78    with_actions=0
79    with_ix86_on_x86_64=0
80    with_category_main=0
81    with_category_plus=0
82    with_category_nonfree=0
83    with_category_test=0
84    with_category_proposed_updates=0
85    with_category_security=0
86
87    return 0
88}
89
90check-parameter(){
91    [ -z "$*" ] && Usage && return 1
92
93    while [ ! -z "$*" ]; do
94        case $1 in
95            --help|help)
96                setup-vbuilder ||:
97                Usage
98                return 1
99                ;;
100            --profile)
101                shift
102                with_profile=1
103                PROFILE=$1
104                check-next-parameter $1 || return 1
105                ;;
106            --version|--arch|--category|--fetch-url|--target|--rpmbuild-define|--rpmbuild-with|--rpmbuild-without|--bootstrap-dir|--unionfs-dir|--cache-dir|--built-rpms-dir)
107                [ $with_actions -eq 1 ] && \
108                    echo $"E: You can give no more options after actions" && \
109                    return 1
110                shift
111                check-next-parameter $1 || return 1
112                ;;
113            --dist-upgrade|--unionfs|--with-compat32|--sign|--no-install|--login|--debug)
114                [ $with_actions -eq 1 ] && \
115                    echo $"E: You can give no more options after actions" && \
116                    return 1
117                ;;
118            --build-rpm|build-rpm|--install-rpm|install-rpm|--remove-rpm|remove-rpm)
119                with_actions=1
120                shift
121                check-next-parameter $1 || return 1
122                ;;
123            --build|build|--clean|clean)
124                with_actions=1
125                ;;
126            *)
127                echo $"E: Missing some parameters after $1"
128                return 1
129                ;;
130        esac
131        shift
132    done
133
134    [ $with_actions -eq 0 ] && \
135        echo $"E: You must give at least one action" && return 1
136
137    return 0
138}
139
140check-next-parameter(){
141    [ -z "$1" ] && echo $"E: Missing some parameters after $1" && return 1
142
143    [ $(echo $1 | grep '^-') ] && \
144        echo $"E: Missing some parameters after $1" && return 1
145
146    return 0
147}
148
149## NOTE: setup-vbuilder() loads
150##  - system wide configurations (from /etc/vbootstrap/vbuilder.conf)
151##  - given profile (from /etc/vbootstrap/profile.d/*.conf)
152##  - given command-line parameters
153## where given command-line parameters override the settings given profile,
154## and the settings given profile override system wide settings.
155## If you use a profile of vbuilder, you may not override the settings
156## given profile.
157setup-vbuilder(){
158    ## check $SUDO_USER and $USERHELPER_UID
159    RPM_SIGN_USER=$SUDO_USER
160    if [ -z "${RPM_SIGN_USER}" ]; then
161        [ -z "${USERHELPER_UID}" ] && \
162            echo $"W: \$SUDO_USER and \$USERHELPER_UID are empty" && \
163            return 1
164           
165        RPM_SIGN_USER=$(getent passwd $USERHELPER_UID | cut -d":" -f1)
166    fi
167    ## get $RPM_SIGN_USER's home directory
168    HOME=$(getent passwd $RPM_SIGN_USER |  cut -d":" -f6)
169
170    ## load default settings
171    VBUILDER_CONF=/etc/vbootstrap/vbuilder.conf
172    if [ -r $VBUILDER_CONF ]; then
173        . $VBUILDER_CONF
174        [ $? -eq 1 ] && return 1
175    fi
176    [ -z "${CATEGORIES}" ] && \
177        CATEGORIES=@@VBUILDER_CATEGORIES@@
178    [ -z "${VBOOTSTRAP_FETCH_URL}" ] && \
179        VBOOTSTRAP_FETCH_URL=@@VBUILDER_VBOOTSTRAP_FETCH_URL@@
180    [ -z "${VBOOTSTRAP_DIR}" ] && \
181        VBOOTSTRAP_DIR=@@VBUILDER_VBOOTSTRAP_DIR@@
182    [ -z "${UNIONFS_DIR}" ] && \
183        UNIONFS_DIR=@@VBUILDER_UNIONFS_DIR@@
184    [ -z "${CACHE_DIR}" ] && \
185        CACHE_DIR=@@VBUILDER_CACHE_DIR@@
186    [ -z "${BUILT_RPMS_DIR}" ] && \
187        BUILT_RPMS_DIR=@@VBUILDER_BUILT_RPMS_DIR@@
188
189    ## set default version for vbootstrap
190    VERSION=@@VBUILDER_DEFAULT_VERSION@@
191
192    ## load profile
193    if [ ${with_profile} -eq 1 ]; then
194        [ ! -r /etc/vbootstrap/profile.d/${PROFILE}.conf ] && \
195            echo $"E: No such profile found: ${PROFILE}" && return 1
196
197        . /etc/vbootstrap/profile.d/${PROFILE}.conf
198        [ $? -eq 1 ] && return 1
199    fi
200
201    ## set current stable relase version
202    STABLE_VERSION=@@VBUILDER_STABLE_VERSION@@
203
204    ## set default chroot archtecture
205    UARCH=$(uname -i)
206    case "${UARCH}" in
207        arm*)
208            UARCH="arm"
209            ;;
210    esac
211
212    return 0
213}
214
215setup-vbootstrap(){
216    if [ ${with_setup_vbootstrap} -eq 0 ]; then
217        with_setup_vbootstrap=1
218
219        ## check debug mode
220        [ ${with_debug} -eq 1 ] && \
221            cat $VBUILDER_CONF && \
222            set && set -x
223
224        ## check some directories
225        ## Note: create $BUILT_RPMS_DIR in RPM_Build()
226        [ -d $VBOOTSTRAP_DIR ] || mkdir -p $VBOOTSTRAP_DIR
227        [ -d $CACHE_DIR ] || mkdir -p $CACHE_DIR
228
229        ## check chroot version
230        case ${VERSION} in
231            4.2|5.2|6.0|VineSeed)
232                ;;
233            *)
234                echo $"E: ${VERSION} is NOT supported"
235                return 1
236                ;;
237        esac
238
239        case "${VARCH}" in
240            arm*)
241                VARCH="arm"
242                ;;
243        esac
244
245        ## check a chroot archtecture
246        if [ -z ${VARCH} ]; then
247            VARCH=${UARCH}
248        else
249            case "${VARCH}" in
250                i386|x86_64)
251                    [ "${UARCH}" = "ppc" -o "${UARCH}" = "arm" ] && \
252                        echo $"E: arch ${VARCH} is NOT supported on ${UARCH}" && return 1
253                    ;;
254                ppc)
255                    [ "${UARCH}" = "i386" -o "${UARCH}" = "x86_64" -o "${UARCH}" = "arm" ] && \
256                        echo $"E: arch ${VARCH} is NOT supported on ${UARCH}" && return 1
257                    ;;
258                arm)
259                    [ "${UARCH}" = "i386" -o "${UARCH}" = "x86_64" -o "${UARCH}" = "ppc" ] && \
260                        echo $"E: arch ${VARCH} is NOT supported on ${UARCH}" && return 1
261                    ;;
262            esac
263        fi
264
265        ##!! 4.2 is NO support on VARCH=x86_64 or VARCH=arch
266        if [ "${VERSION}" = "4.2" ]; then
267            if [ "${VARCH}" = "x86_64" -o "${VARCH}" = "arm" ]; then
268                echo $"E: ${VERSION}_${VARCH} is NOT supported"
269                return 1
270            fi
271        fi
272
273        ## set base profile <version>_<arch>
274        BASE_PROFILE=${VERSION}_${VARCH}
275
276        ## check support ${BASE_PROFILE}
277        if [ -z "$(/usr/sbin/vbootstrap | sed -e s/^Usage:.*// -e s/^E:.*// | grep -m 1 ${BASE_PROFILE})" ]; then
278            echo $"E: ${BASE_PROFILE} is NOT supported"
279            return 1
280        fi
281
282        ## check ${VERSION} equals VineSeed*, when with_dist_upgrade=1
283        if [ $with_dist_upgrade -eq 1 ]; then
284            if [ "${VERSION}" != "VineSeed" ]; then
285                echo $"E: version ${VERSION} does not support --dist-upgrade option"
286                return 1
287            fi
288        fi
289
290        ## support i386 chroot on x86_64 below:
291        [ "${UARCH}" = "x86_64" -a "${VARCH}" = "i386" ] && \
292            with_ix86_on_x86_64=1
293
294        ## check apt categories
295        ## "main" category is unconditionally permited
296        with_category_main=1
297        for cat in $(echo ${CATEGORIES} | sed -e "s/,/ /"g); do
298            case $cat in
299                main)
300                    with_category_main=1
301                    ;;
302                plus)
303                    with_category_plus=1
304                    ;;
305                nonfree)
306                    with_category_nonfree=1
307                    ;;
308                test)
309                    ## "test" category only exists in VineSeed
310                    [ "${VERSION}" = "VineSeed" ] || \
311                        echo $"E: No such category exists: $cat" && return 1
312                    with_category_test=1
313                    ;;
314                proposed-updates)
315                    ##!! "proposed-updates" category does not exist in 4.2
316                    [ "${VERSION}" = "4.2" ] && \
317                        echo $"E: No such category exists: $cat" && return 1
318
319                    with_category_proposed_updates=1
320                    ;;
321                security)
322                    ## "security" category does not exist in VineSeed
323                    [ "${VERSION}" = "VineSeed" ] && \
324                        echo $"E: No such category exists: $cat" && return 1
325                    with_category_security=1
326                    ;;
327                *)
328                    echo $"E: No such category exists: $cat" && return 1
329                    ;;
330            esac
331        done
332
333        ## check build target option ${TARGET}
334        if [ ! -z "${TARGET}" ]; then
335            RPM_TARGET_LIST="$(cat /usr/lib/rpm/rpmrc | grep arch_canon: | sed -e "s/arch_canon:[[:blank:]]*\(.*\):.*/\1/")"
336            RPM_TARGET_LIST="${RPM_TARGET_LIST} noarch"
337            if [ -z "$(echo ${RPM_TARGET_LIST} | grep ${TARGET})" ]; then
338                echo $"E: rpm build target ${TARGET} is NOT supported"
339                return 1
340            fi
341        fi
342
343        ## set ${RPM_PKG_ARCH_LIST}
344        RPM_PKG_ARCH_LIST=" \
345            RPMS/i386 RPMS/i486 RPMS/i586 RPMS/i686 RPMS/x86_64 RPMS/ppc \
346            RPMS/noarch \
347            RPMS/armv3l RPMS/armv4l RPMS/armv4tl \
348            RPMS/armv5tejl RPMS/armv5tel RPMS/armv6l RPMS/armv7l \
349            SRPMS"
350        [ -z "${TARGET}" ] || \
351            RPM_PKG_ARCH_LIST="RPMS/${TARGET} ${RPM_PKG_ARCH_LIST}"
352
353    fi
354
355    ## set global variables
356    BUILD_USER=vbuilder
357    BUILD_DIR=/home/${BUILD_USER}/rpm
358    if [ ${with_profile} -eq 1 ]; then
359        BUILD_ROOT=${VBOOTSTRAP_DIR}/${PROFILE}
360        UNIONFS_ROOT=${UNIONFS_DIR}/${PROFILE}
361    else
362        BUILD_ROOT=${VBOOTSTRAP_DIR}/${BASE_PROFILE}
363        UNIONFS_ROOT=${UNIONFS_DIR}/${BASE_PROFILE}
364    fi
365    ARCHIVES_DIR=${BUILD_ROOT}/var/cache/apt/archives
366    EXTERNAL_ARCHIVES_DIR=${CACHE_DIR}/${BASE_PROFILE}/apt/archives
367
368    __chroot_sh="/usr/sbin/chroot ${BUILD_ROOT} /bin/sh -c -l"
369
370    mkdir -p $VBOOTSTRAP_DIR
371
372    return 0
373}
374
375setup-vbootstrap-rpm(){
376    setup-vbootstrap || return 1
377
378    ## check ${BUILD_ROOT}
379    [ -d ${BUILD_ROOT} ] || Build
380    ## setarch ix86 if ix86 chroot on x86_64 host
381    [ $with_ix86_on_x86_64 -eq 1 ] && \
382        __chroot_sh="/usr/sbin/chroot ${BUILD_ROOT} setarch ${VARCH} /bin/sh -c -l"
383
384    DIST_RELEASE=$(cat ${BUILD_ROOT}/etc/vine-release | cut -f3 -d" " | cut -f1 -d.)
385
386    if [ -f $RPM_PKG ]; then
387        BASE_RPM_PKG=$(basename $RPM_PKG)
388        cp -f $RPM_PKG $BUILD_ROOT${BUILD_DIR}
389    else
390        BASE_RPM_PKG=$RPM_PKG   
391    fi
392
393    return 0
394}
395
396## recover apt-get data on host/chroot
397apt-get-update(){
398    case $1 in
399        --host)
400            echo -n $"apt-get update on host ... "
401            apt-get -qq update > /dev/null 2>&1
402            echo $"done."
403            ;;
404        --chroot)
405            echo -n $"apt-get update on chroot ... "
406            $__chroot_sh 'apt-get -qq update' > /dev/null 2>&1
407            echo $"done."
408            ;;
409        *)
410            echo apt-get-update: unknown option $1
411            exit 1
412            ;;
413    esac
414}
415
416## mount-chroot {|--umount} [file system|name]
417## support file systems: /home /tmp /sys /proc /dev/shm /dev/pts /dev
418## support names: vfs archives_dir
419## NOTE: /tmp needs for applications which use X
420##       vfs is virtual file systems
421##       archives_dir uses to mount ${EXTERNAL_ARCHIVES_DIR} to ${ARCHIVES_DIR}
422##       unionfs_dir covers ${BUILD_ROOT} with unionfs
423mount-chroot(){
424    if [ "$1" = "--umount" ]; then
425        mount-chroot-umount $2 || return 1
426    else
427        mount-chroot-mount $1 || return 1
428    fi
429    return 0
430}
431
432## mount-chroot-umount [file system|name]
433mount-chroot-umount(){
434    local fs=$1
435    case $fs in
436        /home|/tmp|/sys|/proc|/dev/shm|/dev/pts|/dev)
437            [ -d ${BUILD_ROOT}${fs} ] || return 1
438            [ -z "$(mount | grep ${BUILD_ROOT}${fs})" ] || \
439                umount ${BUILD_ROOT}${fs}
440            if [ ! -z "$(mount | grep ${BUILD_ROOT}${fs})" ]; then
441                echo $"Retry lazy unmount ${BUILD_ROOT}${fs} ... "
442                umount -l ${BUILD_ROOT}${fs}
443                echo $"done."
444            fi
445            ;;
446        vfs)
447            for dir in /sys /proc /dev/shm /dev/pts /dev; do
448                mount-chroot-umount ${dir} || return 1
449            done
450            ;;
451        archives_dir)
452            [ -d ${ARCHIVES_DIR} ] || return 1
453            [ -z "$(mount | grep ${ARCHIVES_DIR})" ] || \
454                umount ${ARCHIVES_DIR}
455            ;;
456        unionfs_dir)
457            [ -d ${BUILD_ROOT} ] || return 1
458            [ -z "$(mount | grep ${BUILD_ROOT} | grep unionfs)" ] || \
459                umount ${BUILD_ROOT}
460            if [ ! -z "$(mount | grep ${BUILD_ROOT} | grep unionfs)" ]; then
461                echo $"Retry lazy unmount ${BUILD_ROOT} ... "
462                umount -l ${BUILD_ROOT}
463                echo $"done."
464            fi
465            ;;
466        *)
467            echo mount-chroot-umount: unknown file system $fs
468            exit 1
469            ;;
470    esac
471    return 0
472}
473
474## mount-chroot-mount [file system|name]
475mount-chroot-mount(){
476    local fs=$1
477
478    case $fs in
479        /home)
480            [ -d ${BUILD_ROOT}${fs} ] || mkdir -p ${BUILD_ROOT}${fs}
481            [ -z "$(mount | grep ${BUILD_ROOT}${fs})" ] && \
482                mount -o _netdev,rbind ${fs} ${BUILD_ROOT}${fs}
483            ;;
484        /tmp|/dev)
485            [ -d ${BUILD_ROOT}${fs} ] || mkdir -p ${BUILD_ROOT}${fs}
486            [ -z "$(mount | grep ${BUILD_ROOT}${fs})" ] && \
487                mount --bind -o _netdev ${fs} ${BUILD_ROOT}${fs}
488            ;;
489        /sys)
490            [ -d ${BUILD_ROOT}${fs} ] || mkdir -p ${BUILD_ROOT}${fs}
491            [ -z "$(mount | grep ${BUILD_ROOT}${fs})" ] && \
492                mount -o _netdev -t sysfs vbuildersysfs ${BUILD_ROOT}${fs}
493            ;;
494        /proc)
495            [ -d ${BUILD_ROOT}${fs} ] || mkdir -p ${BUILD_ROOT}${fs}
496            [ -z "$(mount | grep ${BUILD_ROOT}${fs})" ] && \
497                mount -o _netdev -t proc vbuilderproc ${BUILD_ROOT}${fs}
498            ;;
499        /dev/shm)
500            [ -d ${BUILD_ROOT}${fs} ] || mkdir -p ${BUILD_ROOT}${fs}
501            [ -z "$(mount | grep ${BUILD_ROOT}${fs})" ] && \
502                mount -o _netdev -t tmpfs vbuildertmpfs ${BUILD_ROOT}${fs}
503            ;;
504        /dev/pts)
505            [ -d ${BUILD_ROOT}${fs} ] || mkdir -p ${BUILD_ROOT}${fs}
506            [ -z "$(mount | grep ${BUILD_ROOT}${fs})" ] && \
507                mount -o gid=5,mode=620,_netdev -t devpts vbuilderdevpts ${BUILD_ROOT}${fs}
508            ;;
509        vfs)
510            for dir in /dev /dev/pts /dev/shm /proc /sys; do
511                mount-chroot-mount ${dir} || return 1
512            done
513            ;;
514        archives_dir)
515            [ -d ${EXTERNAL_ARCHIVES_DIR} ] || mkdir -p ${EXTERNAL_ARCHIVES_DIR}
516            [ -d ${ARCHIVES_DIR} ] || mkdir -p ${ARCHIVES_DIR}
517            [ -z "$(mount | grep ${ARCHIVES_DIR})" ] && \
518                mount --bind -o _netdev ${EXTERNAL_ARCHIVES_DIR} ${ARCHIVES_DIR}
519            [ -d ${ARCHIVES_DIR}/partial ] || mkdir -p ${ARCHIVES_DIR}/partial
520            ;;
521        unionfs_dir)
522            if [ $with_unionfs -eq 1 ]; then
523                [ -d ${UNIONFS_ROOT} ] || mkdir -p ${UNIONFS_ROOT}
524                [ -z "$(mount | grep ${UNIONFS_ROOT})" ] && \
525                    mount -t unionfs -o dirs=${UNIONFS_ROOT}=rw:${BUILD_ROOT}=ro unionfs ${BUILD_ROOT}
526                unionctl ${BUILD_ROOT} --list
527            fi
528            ;;
529        *)
530            echo mount-chroot-mount: unknown file system $fs
531            exit 1
532            ;;
533    esac
534    return 0
535}
536
537## TODO: support spec-validator
538## spec-validator [spec file]
539spec-validator(){
540    echo
541    return 0
542}
543
544
545##############################################################################
546
547Clean(){
548    setup-vbootstrap || return 1
549
550    # mount-chroot --umount /home
551    mount-chroot --umount /tmp
552    mount-chroot --umount /dev/shm
553    mount-chroot --umount /dev/pts
554    mount-chroot --umount /proc
555    mount-chroot --umount archives_dir
556    mount-chroot --umount unionfs_dir
557    apt-get-update --host
558
559    ## We remark that we first remove /, and secondly remove /.
560    ## If we directly remove /, we obtained some non-empty directories:
561    ##   /dev/.udev/rules.d.
562    if [ $with_unionfs -eq 1 ]; then
563        if [ -d ${UNIONFS_ROOT} ]; then
564            echo -n $"Cleaning build root ${UNIONFS_ROOT} via unionfs ... "
565            rm -rf ${UNIONFS_ROOT} 2>/dev/null
566            rm -rf ${UNIONFS_ROOT}
567            echo $"done."
568        fi
569    else
570        if [ -d ${BUILD_ROOT} ]; then
571            echo -n $"Cleaning build root ${BUILD_ROOT} ... "
572            rm -rf ${BUILD_ROOT} 2>/dev/null
573            rm -rf ${BUILD_ROOT}
574            echo $"done."
575        fi
576    fi
577
578    echo $"Cleanup a build farm for ${BUILD_ROOT} done."
579    return 0
580}
581
582Build(){
583    setup-vbootstrap || return 1
584
585    if [ $with_dist_upgrade -eq 1 ]; then
586        ## make bootstrap of ${STABLE_VERSION}
587        /usr/sbin/vbootstrap \
588            $(echo ${BASE_PROFILE} | sed -e "s/VineSeed/${STABLE_VERSION}/") \
589            ${VBOOTSTRAP_FETCH_URL} ${BUILD_ROOT}
590
591        ## aim apt-line to VineSeed
592        sed -i "s/apt ${STABLE_VERSION}/apt VineSeed/g" \
593            ${BUILD_ROOT}/etc/apt/sources.list.d/main.list
594    else
595        /usr/sbin/vbootstrap ${BASE_PROFILE} ${VBOOTSTRAP_FETCH_URL} ${BUILD_ROOT}
596    fi
597
598    mount-chroot /proc
599    mount-chroot archives_dir
600    mount-chroot /dev/pts
601    mount-chroot /dev/shm
602    # mount-chroot /tmp
603    # mount-chroot /home
604
605    ##!! 4.2 has no apt-sourceslist-{plus,nonfree,proposed-updates} packages
606    case ${VERSION} in
607        4.2)
608            sed -i -e "s|@@VBUILDER_VBOOTSTRAP_FETCH_URL@@|${VBOOTSTRAP_FETCH_URL}|g" ${BUILD_ROOT}/etc/apt/sources.list
609            sed -i -e 's/main plus updates nonfree *$/$(echo ${CATEGORIES} | sed -e "s/,/ /"g) updates/g' ${BUILD_ROOT}/etc/apt/sources.list
610            $__chroot_sh 'apt-get -qq update && apt-get -qq -y dist-upgrade'
611            # [ $with_category_security -eq 1 ] && \
612            #   echo
613            ;;
614        5.2|@@VBUILDER_STABLE_VERSION@@)
615            sed -i -e "s|@@VBUILDER_VBOOTSTRAP_FETCH_URL@@|${VBOOTSTRAP_FETCH_URL}|g" ${BUILD_ROOT}/etc/apt/sources.list.d/main.list
616            $__chroot_sh 'apt-get -qq update && apt-get -qq -y dist-upgrade'
617            [ $with_category_plus -eq 1 ] && \
618                $__chroot_sh 'apt-get -qq update && apt-get -qq -y install apt-sourceslist-plus' && \
619                sed -i -e "s|@@VBUILDER_VBOOTSTRAP_FETCH_URL@@|${VBOOTSTRAP_FETCH_URL}|g" ${BUILD_ROOT}/etc/apt/sources.list.d/plus.list
620            [ $with_category_nonfree -eq 1 ] && \
621                $__chroot_sh 'apt-get -qq update && apt-get -qq -y install apt-sourceslist-nonfree' && \
622                sed -i -e "s|@@VBUILDER_VBOOTSTRAP_FETCH_URL@@|${VBOOTSTRAP_FETCH_URL}|g" ${BUILD_ROOT}/etc/apt/sources.list.d/nonfree.list
623            [ $with_category_proposed_updates -eq 1 ] && \
624                $__chroot_sh 'apt-get -qq update && apt-get -qq -y install apt-sourceslist-proposed-updates' && \
625                sed -i -e "s|@@VBUILDER_VBOOTSTRAP_FETCH_URL@@|${VBOOTSTRAP_FETCH_URL}|g" ${BUILD_ROOT}/etc/apt/sources.list.d/proposed-updates.list
626            # [ $with_category_security -eq 1 ] && \
627            #   echo
628            ;;
629        VineSeed)
630            sed -i -e "s|@@VBUILDER_VBOOTSTRAP_FETCH_URL@@|${VBOOTSTRAP_FETCH_URL}|g" ${BUILD_ROOT}/etc/apt/sources.list.d/main.list
631            $__chroot_sh 'apt-get -qq update && apt-get -qq -y dist-upgrade'
632            [ $with_category_plus -eq 1 ] && \
633                $__chroot_sh 'apt-get -qq update && apt-get -qq -y install apt-sourceslist-plus' && \
634                sed -i -e "s|@@VBUILDER_VBOOTSTRAP_FETCH_URL@@|${VBOOTSTRAP_FETCH_URL}|g" ${BUILD_ROOT}/etc/apt/sources.list.d/plus.list
635            [ $with_category_nonfree -eq 1 ] && \
636                $__chroot_sh 'apt-get -qq update && apt-get -qq -y install apt-sourceslist-nonfree' && \
637                sed -i -e "s|@@VBUILDER_VBOOTSTRAP_FETCH_URL@@|${VBOOTSTRAP_FETCH_URL}|g" ${BUILD_ROOT}/etc/apt/sources.list.d/nonfree.list
638            [ $with_category_test -eq 1 ] && \
639                $__chroot_sh 'apt-get -qq update && apt-get -qq -y install apt-sourceslist-test' && \
640                sed -i -e "s|@@VBUILDER_VBOOTSTRAP_FETCH_URL@@|${VBOOTSTRAP_FETCH_URL}|g" ${BUILD_ROOT}/etc/apt/sources.list.d/test.list
641            ;;
642    esac
643
644    [ $with_dist_upgrade -eq 1 ] && \
645        $__chroot_sh 'apt-get -qq update && apt-get -qq -y dist-upgrade'
646
647    $__chroot_sh 'apt-get -qq -y install build-essential'
648    $__chroot_sh 'apt-get -qq -y install etcskel shadow-utils'
649
650    $__chroot_sh 'cd /dev && /sbin/MAKEDEV console'
651    $__chroot_sh 'cd /dev && /sbin/MAKEDEV ptmx'
652    $__chroot_sh 'cd /dev && /sbin/MAKEDEV null'
653    $__chroot_sh 'cd /dev && /sbin/MAKEDEV zero'
654    $__chroot_sh 'cd /dev && /sbin/MAKEDEV random'
655    $__chroot_sh 'cd /dev && /sbin/MAKEDEV urandom'
656    $__chroot_sh 'cd /dev && mkdir -p shm && chmod 777 shm'
657    $__chroot_sh 'cd /dev && mkdir -p pts && chmod 755 pts'
658
659    $__chroot_sh '/usr/sbin/pwconv'
660    $__chroot_sh "/usr/sbin/useradd ${BUILD_USER}"
661
662    ##!! for rpm-4.8.0 or higher
663    ##!! (See http://trac.vinelinux.org/wiki/Vine6/AboutUpdateToolchain)
664    if [ "${VERSION}" = "VineSeed" ]; then
665        $__chroot_sh "sed -i -e 's/^%_topdir/#%_topdir/' /home/${BUILD_USER}/.rpmmacros"
666    fi
667
668    ## set local repositories (profile only)
669    if [ ${with_profile} -eq 1 ]; then
670        if [ ! -z "${LOCAL_REPOS}" ]; then
671            cat >${BUILD_ROOT}/etc/apt/sources.list.d/local.list<<EOF
672${LOCAL_REPOS}
673EOF
674        fi
675
676        $__chroot_sh "apt-get update"
677
678        ## additional base packages
679        [ ! -z "${ADD_BASE_PKGS}" ] && \
680            $__chroot_sh "apt-get -y install ${ADD_BASE_PKGS}" 
681    fi
682
683    # mount-chroot --umount /home
684    # mount-chroot --umount /tmp
685    mount-chroot --umount /dev/shm
686    mount-chroot --umount /dev/pts
687    mount-chroot --umount archives_dir
688    mount-chroot --umount /proc
689    apt-get-update --host
690
691    echo $"Making a build farm for ${BUILD_ROOT} done."
692    return 0
693}
694
695RPM_Remove(){
696    setup-vbootstrap-rpm || return 1
697    mount-chroot unionfs_dir
698    mount-chroot archives_dir
699    mount-chroot /proc
700    mount-chroot /dev/pts
701    mount-chroot /dev/shm
702    apt-get-update --chroot
703
704    [ -f $RPM_PKG ] && \
705        echo $"E: $RPM_PKG is not a package name" && return 1
706    $__chroot_sh "apt-get -y remove $BASE_RPM_PKG"
707
708    mount-chroot --umount /dev/shm
709    mount-chroot --umount /dev/pts
710    mount-chroot --umount /proc
711    mount-chroot --umount archives_dir
712    mount-chroot --umount unionfs_dir
713    apt-get-update --host
714
715    return 0
716}
717
718RPM_Install(){
719    setup-vbootstrap-rpm || return 1
720    mount-chroot unionfs_dir
721    mount-chroot archives_dir
722    mount-chroot /proc
723    mount-chroot /dev/pts
724    mount-chroot /dev/shm
725
726    apt-get-update --chroot
727
728    [ $with_category_nonfree -eq 1 ] && \
729        [ ! -z "$(echo $BASE_RPM_PKG | grep -e 'self-build-' -e 'install-assist-')" ] && \
730        $__chroot_sh 'rpm -q --quiet self-build-setup || apt-get -qq -y install self-build-setup'
731
732    $__chroot_sh "cd ${BUILD_DIR} && apt-get -y install $BASE_RPM_PKG"
733
734    mount-chroot --umount /dev/shm
735    mount-chroot --umount /dev/pts
736    mount-chroot --umount /proc
737    mount-chroot --umount archives_dir
738    mount-chroot --umount unionfs_dir
739    apt-get-update --host
740
741    return 0
742}
743
744RPM_Build(){
745    [ ! -f ${RPM_PKG} ] && \
746        echo $"E: No such file found: ${RPM_PKG}" && return 1
747
748    ## check the extension of given $RPM_PKG
749    local RPM_PKG_EXT=${RPM_PKG##*.}
750    case ${RPM_PKG_EXT} in
751        spec)
752            ## In this case,
753            ## the file ${RPM_PKG} is a spec file!
754            # spec-validator ${RPM_PKG} || return 1
755            # return 1
756
757            ## We assign the variable ${RPM_PKG}
758            ## the src.rpm generated by the spec file ${RPM_PKG}.
759            RPM_PKG=$(rpm -E "%{_srcrpmdir}")/$(rpm -q --qf "%{name}-%{version}-%{release}\n" --specfile ${RPM_PKG} | head -n 1).src.rpm
760            ;;
761        rpm)
762            RPM_PKG_EXT=$(echo ${RPM_PKG} | sed -e "s|.*\.\(src\.rpm\)$|\1|")
763            [ "${RPM_PKG_EXT}" != "src.rpm" ] && \
764                echo $"E: $RPM_PKG is NOT a source RPM package" && return 1
765            ;;
766        *)
767            echo $"The action build-rpm cannot work such extension: ${RPM_PKG_EXT}"
768            return 1
769            ;;
770    esac
771
772    setup-vbootstrap-rpm || return 1
773    mount-chroot unionfs_dir
774    mount-chroot archives_dir
775    mount-chroot /proc
776    mount-chroot /dev/pts
777    mount-chroot /dev/shm
778    apt-get-update --chroot
779   
780    [ ! -f ${RPM_PKG} ] && \
781        echo $"E: No such file found: ${RPM_PKG}" && return 1
782
783    RPM_PKG_USER=$(stat -c %U $RPM_PKG)
784    RPM_PKG_GROUP=$(stat -c %G $RPM_PKG)
785    [ ! -z "${SUDO_UID}" ] && RPM_PKG_USER=${SUDO_UID}
786    [ ! -z "${SUDO_GID}" ] && RPM_PKG_GROUP=${SUDO_GID}
787    local __install="install -p -v -o ${RPM_PKG_USER} -g ${RPM_PKG_GROUP}"
788
789    ## make src.rpm for $VERSION
790    $__chroot_sh "cd ${BUILD_DIR} && su ${BUILD_USER} -c 'rpm -ivh $BASE_RPM_PKG'"
791    $__chroot_sh "cd ${BUILD_DIR} && su ${BUILD_USER} -c 'rpmbuild -bs --nodeps --clean --rmsource --rmspec $RPM_OPTS ${BUILD_DIR}/SPECS/*.spec'"
792
793
794    ## change ${DIST_RELEASE}
795    BASE_RPM_PKG=$(echo $BASE_RPM_PKG | sed -e "s/vl[0-9]*\([A-Za-z]*[0-9A-Za-z]*\)\./vl${DIST_RELEASE}\1\./")
796
797    ## rebuild $BASE_RPM_PKG on ${DIST_RELEASE}
798    $__chroot_sh "cd ${BUILD_DIR}/SRPMS && apt-get -o APT::Install::Virtual=true -y build-dep $BASE_RPM_PKG"
799    $__chroot_sh "cd ${BUILD_DIR}/SRPMS && su ${BUILD_USER} -c 'rpmbuild --rebuild $RPM_OPTS $BASE_RPM_PKG'"
800
801    BUILT_RPMS_LIST=$(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')
802
803    [ $with_category_nonfree -eq 1 ] && \
804        [ ! -z "$(echo $BUILT_RPMS_LIST | grep -e 'self-build-' -e 'install-assist-')" ] && \
805        $__chroot_sh 'rpm -q --quiet self-build-setup || apt-get -qq -y install self-build-setup'
806
807    [ $with_no_install -eq 0 ] && \
808        $__chroot_sh "cd ${BUILD_DIR} && apt-get -y install $BUILT_RPMS_LIST"
809
810    ## copy built rpms to ${HOME}/rpm/ for each archtectures
811    echo $"Copying built rpms to ${BUILT_RPMS_DIR} for each archtectures ... "
812    for i in $RPM_PKG_ARCH_LIST; do
813        [ -d $BUILD_ROOT${BUILD_DIR}/${i} ] || continue
814        if [ ! -d ${BUILT_RPMS_DIR}/${VERSION}/${i} ]; then
815            $__install -d ${BUILT_RPMS_DIR}/${VERSION}/${i}/
816            chown -R ${RPM_PKG_USER}:${RPM_PKG_GROUP} ${BUILT_RPMS_DIR}
817        fi
818        find $BUILD_ROOT${BUILD_DIR}/${i} -type f -regex '.*\.rpm' \
819            -exec $__install -m0644 {} ${BUILT_RPMS_DIR}/${VERSION}/${i}/ \;
820    done
821
822    mount-chroot --umount /dev/shm
823    mount-chroot --umount /dev/pts
824    mount-chroot --umount /proc
825    mount-chroot --umount archives_dir
826    mount-chroot --umount unionfs_dir
827    apt-get-update --host
828
829    echo $"done."
830    return 0
831}
832
833RPM_Sign(){
834    [ $with_sign -eq 1 ] || return 1
835
836    setup-vbootstrap || return 1
837
838    [ -d ${BUILD_ROOT} ] || Build
839
840    mount-chroot unionfs_dir
841
842    echo $"Signing built rpms using ${RPM_SIGN_USER}'s key: "
843    su $RPM_SIGN_USER -c "rpmsign --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}/${VERSION},g -e 's/$/ \\/g')"
844
845    mount-chroot --umount unionfs_dir
846
847    return 0
848}
849
850Login_Chroot(){
851    [ $with_login -eq 1 ] || return 1
852
853    setup-vbootstrap || return 1
854
855    __chroot="/usr/sbin/chroot ${BUILD_ROOT}"
856    ## setarch ix86 if ix86 chroot on x86_64 host
857    [ $with_ix86_on_x86_64 -eq 1 ] && \
858        __chroot="/usr/sbin/chroot ${BUILD_ROOT} setarch ${VARCH}"
859
860
861    mount-chroot unionfs_dir
862    mount-chroot archives_dir
863    mount-chroot /proc
864    mount-chroot /dev/pts
865    mount-chroot /dev/shm
866    mount-chroot /tmp
867    # mount-chroot /home
868    apt-get-update --chroot
869
870    ## copy host's configurations of /etc
871    #passwd shadow group gshadow
872    for i in resolv.conf hosts; do
873        cp -pf /etc/${i} ${BUILD_ROOT}/etc
874    done
875    cp -Ppf /etc/localtime ${BUILD_ROOT}/etc
876
877    $__chroot /bin/bash
878
879    # mount-chroot  --umount /home
880    mount-chroot  --umount /tmp
881    mount-chroot --umount /dev/shm
882    mount-chroot --umount /dev/pts
883    mount-chroot --umount /proc
884    mount-chroot --umount archives_dir
885    mount-chroot --umount unionfs_dir
886    apt-get-update --host
887
888    return 0
889}
890
891
892##############################################################################
893
894initialize-variables || exit 1
895
896check-parameter $* || exit 1
897
898setup-vbuilder || exit 1
899
900while [ $# -gt 0 ]; do
901    tmpARG=$1
902    case $tmpARG in
903        --profile)
904            shift
905            ;;
906        --version|--arch|--category|--fetch-url|--target|--rpmbuild-define|--rpmbuild-with|--rpmbuild-without|--bootstrap-dir|--unionfs-dir|--cache-dir|--built-rpms-dir)
907            shift
908            ;;
909        --dist-upgrade|--unionfs|--with-compat32|--sign|--no-install|--login|--debug)
910            ;;
911        --build-rpm|build-rpm|--install-rpm|install-rpm|--remove-rpm|remove-rpm)
912            shift
913            ;;
914        --build|build|--clean|clean)
915            ;;
916        *)
917            echo unknown option $1
918            exit 1
919            ;;
920    esac
921
922    case $tmpARG in
923        --profile)
924            ;;
925        --version)
926            VERSION=$1
927            ;;
928        --arch)
929            VARCH=$1
930            ;;
931        --category)
932            CATEGORIES=$1
933            ;;
934        --fetch-url)
935            VBOOTSTRAP_FETCH_URL=$1
936            ;;
937        --dist-upgrade)
938            with_dist_upgrade=1
939            ;;
940        --unionfs)
941            with_unionfs=1
942            ;;
943        --target)
944            TARGET=$1
945            RPM_OPTS="${RPM_OPTS} --target $TARGET"
946            ;;
947        --with-compat32)
948            RPM_OPTS="${RPM_OPTS} --with compat32"
949            ;;
950        --rpmbuild-define)
951            RPM_OPTS="${RPM_OPTS} --define $1"
952            ;;
953        --rpmbuild-with)
954            RPM_OPTS="${RPM_OPTS} --with $1"
955            ;;
956        --rpmbuild-without)
957            RPM_OPTS="${RPM_OPTS} --without $1"
958            ;;
959        --sign)
960            with_sign=1
961            ;;
962        --no-install)
963            with_no_install=1
964            ;;
965        --login)
966            with_login=1
967            ;;
968        --bootstrap-dir)
969            VBOOTSTRAP_DIR=$1
970            ;;
971        --unionfs-dir)
972            UNIONFS_DIR=$1
973            ;;
974        --cache-dir)
975            CACHE_DIR=$1
976            ;;
977        --built-rpms-dir)
978            BUILT_RPMS_DIR=$1
979            ;;
980        --debug)
981            with_debug=1
982            ;;
983        --build-rpm|build-rpm)
984            RPM_PKG=$1
985            RPM_Build || exit 1
986            ;;
987        --install-rpm|install-rpm)
988            RPM_PKG=$1
989            RPM_Install || exit 1
990            ;;
991        --remove-rpm|remove-rpm)
992            RPM_PKG=$1
993            RPM_Remove || exit 1
994            ;;
995        --build|build)
996            Build || exit 1
997            ;;
998        --clean|clean)
999            Clean || exit 1
1000            ;;
1001    esac
1002    shift
1003done
1004
1005RPM_Sign ||:
1006
1007Login_Chroot ||:
1008
1009exit
Note: See TracBrowser for help on using the repository browser.