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

Revision 4530, 25.2 KB checked in by munepi, 13 years ago (diff)

set STABLE_VERSION to 6.0

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