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

Revision 3352, 26.7 KB checked in by munepi, 13 years ago (diff)

updated vbuilder.sh.in

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