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

Revision 3678, 25.1 KB checked in by munepi, 13 years ago (diff)

fixed Login_Chroot() in vbuilder.sh.in

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