source: projects/vbootstrap/tags/0.0.26/vbuilder.sh.in @ 923

Revision 923, 22.3 KB checked in by munepi, 14 years ago (diff)

tagging 0.0.26

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