123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898 |
- #!/bin/bash
- # -*- coding: utf-8-unix -*-
- TEXTDOMAIN=vbootstrap
- TEXTDOMAINDIR=/usr/share/locale
- Usage(){
- cat<<EOF
- $(basename $0) @@VBUILDER_VERSION@@ $(echo $([ -z "@@VBUILDER_REVISION@@" ] || echo "(r@@VBUILDER_REVISION@@)"))
- Usage: $(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]}
- EOF
- echo $"
- Options:
- --version: set [version] (default: ${DEFAULT_VERSION})
- --arch: set [arch] (default: ${UARCH})
- --category: set [categories] (default: ${CATEGORIES})
- --dist-upgrade: make VineSeed bootstrap via ${STABLE_VERSION}
- --unionfs: cover a bootstrap with unionfs
- --target: build rpms with [target]
- --with-compat32: build rpms with compat32 on bootstrap
- --rpmbuild-define: give a option --define [macro_expr] to rpmbuild
- --rpmbuild-with: give a option --with [bcond_with] to rpmbuild
- --rpmbuild-without: give a option --without [bcond_with] to rpmbuild
- --sign: sign built rpms
- --no-install: build only a source rpm - do NOT install a built rpm
- --login: login in chroot as root user
- --bootstrap-dir: set a bootstrap directory (default: ${VBOOTSTRAP_DIR})
- --unionfs-dir: set a directory to store unionfs images of vbootstrap (default: ${UNIONFS_DIR})
- --cache-dir: set a directory to cache rpms (default: ${CACHE_DIR})
- --built-rpms-dir: set a directory to store built rpms in chroot (default: ${BUILT_RPMS_DIR})
- --debug: enable debug mode
- --help: show this help
- "
- echo $"
- Actions:
- clean: clean the bootstrap of [version]
- build: build a bootstrap of [version]
- build-rpm: build [src.rpm] on a bootstrap
- install-rpm: install [arch.rpm|package] on a bootstrap
- remove-rpm: remove [package] on a bootstrap
- "
- echo $"
- Examples:
- * make a clean/plain build environment on the current archtecture:
- $(basename $0) clean build
- * build rpms from the specified source rpm:
- $(basename $0) build-rpm [src.rpm]
- * make a plain build environment for Vine Linux 5.2:
- $(basename $0) --version 5.2 clean build
- * make a i386 chroot on x86_64:
- $(basename $0) --arch i386 clean build
- * build a kernel package with target i686:
- $(basename $0) --target i686 build-rpm [kernel src.rpm]
- * build a compat32 package:
- $(basename $0) --arch i386 --with-compat32 build-rpm [src.rpm]
- "
- /usr/sbin/vbootstrap | sed -e s/^Usage:.*// -e s/^E:.*//
- }
- ##############################################################################
- check-parameter(){
- [ -z "$*" ] && Usage && return 1
- while [ ! -z "$*" ]; do
- case $1 in
- --help|help)
- Usage
- return 1
- ;;
- --version|--arch|--category|--target|--rpmbuild-define|--rpmbuild-with|--rpmbuild-without|--bootstrap-dir|--unionfs-dir|--cache-dir|--built-rpms-dir)
- [ $with_actions -eq 1 ] && \
- echo $"E: You can give no more options after actions" && \
- return 1
- shift
- check-next-parameter $1 || return 1
- ;;
- --dist-upgrade|--unionfs|--with-compat32|--sign|--no-install|--login|--debug)
- [ $with_actions -eq 1 ] && \
- echo $"E: You can give no more options after actions" && \
- return 1
- ;;
- --build-rpm|build-rpm|--install-rpm|install-rpm|--remove-rpm|remove-rpm)
- with_actions=1
- shift
- check-next-parameter $1 || return 1
- ;;
- --build|build|--clean|clean)
- with_actions=1
- ;;
- *)
- echo $"E: Missing some parameters after $1"
- return 1
- ;;
- esac
- shift
- done
- [ $with_actions -eq 0 ] && \
- echo $"E: You must give at least one action" && return 1
- return 0
- }
- check-next-parameter(){
- [ -z "$1" ] && echo $"E: Missing some parameters after $1" && return 1
- [ $(echo $1 | grep '^-') ] && \
- echo $"E: Missing some parameters after $1" && return 1
- return 0
- }
- setup-vbuilder(){
- ## check $SUDO_USER and $USERHELPER_UID
- RPM_SIGN_USER=$SUDO_USER
- if [ -z "${RPM_SIGN_USER}" ]; then
- [ -z "${USERHELPER_UID}" ] && \
- echo $"W: \$SUDO_USER and \$USERHELPER_UID are empty" && \
- return 1
-
- RPM_SIGN_USER=$(getent passwd $USERHELPER_UID | cut -d":" -f1)
- fi
- ## get $RPM_SIGN_USER's home directory
- HOME=$(getent passwd $RPM_SIGN_USER | cut -d":" -f6)
- ## load default settings
- VBUILDER_CONF=/etc/vbootstrap/vbuilder.conf
- if [ -r $VBUILDER_CONF ]; then
- . $VBUILDER_CONF
- [ $? -eq 1 ] && return 1
- fi
- [ -z "${DEFAULT_VERSION}" ] && \
- DEFAULT_VERSION=@@VBUILDER_DEFAULT_VERSION@@
- [ -z "${CATEGORIES}" ] && \
- CATEGORIES=@@VBUILDER_CATEGORIES@@
- [ -z "${VBOOTSTRAP_DIR}" ] && \
- VBOOTSTRAP_DIR=@@VBUILDER_VBOOTSTRAP_DIR@@
- [ -z "${UNIONFS_DIR}" ] && \
- UNIONFS_DIR=@@VBUILDER_UNIONFS_DIR@@
- [ -z "${CACHE_DIR}" ] && \
- CACHE_DIR=@@VBUILDER_CACHE_DIR@@
- [ -z "${BUILT_RPMS_DIR}" ] && \
- BUILT_RPMS_DIR=@@VBUILDER_BUILT_RPMS_DIR@@
- ## set default version for vbootstrap
- VERSION=$DEFAULT_VERSION
- ## set current stable relase version
- STABLE_VERSION=@@VBUILDER_STABLE_VERSION@@
- ## set default chroot archtecture
- UARCH=$(uname -i)
- case "${UARCH}" in
- arm*)
- UARCH="arm"
- ;;
- esac
- ## set boolian variables
- with_setup_vbootstrap=0
- with_dist_upgrade=0
- with_unionfs=0
- with_sign=0
- with_no_install=0
- with_login=0
- with_debug=0
- with_actions=0
- with_ix86_on_x86_64=0
- with_category_main=0
- with_category_plus=0
- with_category_nonfree=0
- with_category_test=0
- with_category_proposed_updates=0
- with_category_security=0
- return 0
- }
- setup-vbootstrap(){
- if [ ${with_setup_vbootstrap} -eq 0 ]; then
- with_setup_vbootstrap=1
- ## check debug mode
- [ ${with_debug} -eq 1 ] && \
- cat $VBUILDER_CONF && \
- set && set -x
- ## check some directories
- ## Note: create $BUILT_RPMS_DIR in RPM_Build()
- [ -d $VBOOTSTRAP_DIR ] || mkdir -p $VBOOTSTRAP_DIR
- [ -d $CACHE_DIR ] || mkdir -p $CACHE_DIR
- ## check chroot version
- case ${VERSION} in
- 4.2|5.2|6.0|VineSeed)
- ;;
- *)
- echo $"E: ${VERSION} is NOT supported"
- return 1
- ;;
- esac
- case "${VARCH}" in
- arm*)
- VARCH="arm"
- ;;
- esac
- ## check a chroot archtecture
- if [ -z ${VARCH} ]; then
- VARCH=${UARCH}
- else
- case "${VARCH}" in
- i386|x86_64)
- [ "${UARCH}" = "ppc" -o "${UARCH}" = "arm" ] && \
- echo $"E: arch ${VARCH} is NOT supported on ${UARCH}" && return 1
- ;;
- ppc)
- [ "${UARCH}" = "i386" -o "${UARCH}" = "x86_64" -o "${UARCH}" = "arm" ] && \
- echo $"E: arch ${VARCH} is NOT supported on ${UARCH}" && return 1
- ;;
- arm)
- [ "${UARCH}" = "i386" -o "${UARCH}" = "x86_64" -o "${UARCH}" = "ppc" ] && \
- echo $"E: arch ${VARCH} is NOT supported on ${UARCH}" && return 1
- ;;
- esac
- fi
- ##!! 4.2 is NO support on VARCH=x86_64 or VARCH=arch
- if [ "${VERSION}" = "4.2" ]; then
- if [ "${VARCH}" = "x86_64" -o "${VARCH}" = "arm" ]; then
- echo $"E: ${VERSION}_${VARCH} is NOT supported"
- return 1
- fi
- fi
- ## set the profile <version>_<arch>
- PROFILE=${VERSION}_${VARCH}
- ## check support ${PROFILE}
- if [ -z "$(/usr/sbin/vbootstrap | sed -e s/^Usage:.*// -e s/^E:.*// | grep -m 1 ${PROFILE})" ]; then
- echo $"E: ${PROFILE} is NOT supported"
- return 1
- fi
- ## check ${VERSION} equals VineSeed*, when with_dist_upgrade=1
- if [ $with_dist_upgrade -eq 1 ]; then
- if [ "${VERSION}" != "VineSeed" ]; then
- echo $"E: version ${VERSION} does not support --dist-upgrade option"
- return 1
- fi
- fi
- ## support i386 chroot on x86_64 below:
- [ "${UARCH}" = "x86_64" -a "${VARCH}" = "i386" ] && \
- with_ix86_on_x86_64=1
- ## check apt categories
- ## "main" category is unconditionally permited
- with_category_main=1
- for cat in $(echo ${CATEGORIES} | sed -e "s/,/ /"g); do
- case $cat in
- main)
- with_category_main=1
- ;;
- plus)
- with_category_plus=1
- ;;
- nonfree)
- with_category_nonfree=1
- ;;
- test)
- ## "test" category only exists in VineSeed
- [ "${VERSION}" = "VineSeed" ] || \
- echo $"E: No such category exists: $cat" && return 1
- with_category_test=1
- ;;
- proposed-updates)
- ##!! "proposed-updates" category does not exist in 4.2
- [ "${VERSION}" = "4.2" ] && \
- echo $"E: No such category exists: $cat" && return 1
- with_category_proposed_updates=1
- ;;
- security)
- ## "security" category does not exist in VineSeed
- [ "${VERSION}" = "VineSeed" ] && \
- echo $"E: No such category exists: $cat" && return 1
- with_category_security=1
- ;;
- *)
- echo $"E: No such category exists: $cat" && return 1
- ;;
- esac
- done
- ## check build target option ${TARGET}
- if [ ! -z "${TARGET}" ]; then
- RPM_TARGET_LIST="$(cat /usr/lib/rpm/rpmrc | grep arch_canon: | sed -e "s/arch_canon:[[:blank:]]*\(.*\):.*/\1/")"
- RPM_TARGET_LIST="${RPM_TARGET_LIST} noarch"
- if [ -z "$(echo ${RPM_TARGET_LIST} | grep ${TARGET})" ]; then
- echo $"E: rpm build target ${TARGET} is NOT supported"
- return 1
- fi
- fi
- ## set ${RPM_PKG_ARCH_LIST}
- 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"
- [ -z "${TARGET}" ] || \
- RPM_PKG_ARCH_LIST="RPMS/${TARGET} ${RPM_PKG_ARCH_LIST}"
- fi
- ## set global variables
- BUILD_ROOT=${VBOOTSTRAP_DIR}/${PROFILE}
- BUILD_USER=vbuilder
- BUILD_DIR=/home/${BUILD_USER}/rpm
- UNIONFS_ROOT=${UNIONFS_DIR}/${PROFILE}
- ARCHIVES_DIR=${BUILD_ROOT}/var/cache/apt/archives
- EXTERNAL_ARCHIVES_DIR=${CACHE_DIR}/${PROFILE}/apt/archives
- __chroot_sh="/usr/sbin/chroot ${BUILD_ROOT} /bin/sh -c -l"
- mkdir -p $VBOOTSTRAP_DIR
- return 0
- }
- setup-vbootstrap-rpm(){
- setup-vbootstrap || return 1
- ## check ${BUILD_ROOT}
- [ -d ${BUILD_ROOT} ] || Build
- ## setarch ix86 if ix86 chroot on x86_64 host
- [ $with_ix86_on_x86_64 -eq 1 ] && \
- __chroot_sh="/usr/sbin/chroot ${BUILD_ROOT} setarch ${VARCH} /bin/sh -c -l"
- DIST_RELEASE=$(cat ${BUILD_ROOT}/etc/vine-release | cut -f3 -d" " | cut -f1 -d.)
- if [ -f $RPM_PKG ]; then
- BASE_RPM_PKG=$(basename $RPM_PKG)
- cp -f $RPM_PKG $BUILD_ROOT${BUILD_DIR}
- else
- BASE_RPM_PKG=$RPM_PKG
- fi
- return 0
- }
- ## recover apt-get data on host/chroot
- apt-get-update(){
- case $1 in
- --host)
- echo -n $"apt-get update on host ... "
- apt-get -qq update > /dev/null 2>&1
- echo $"done."
- ;;
- --chroot)
- echo -n $"apt-get update on chroot ... "
- $__chroot_sh 'apt-get -qq update' > /dev/null 2>&1
- echo $"done."
- ;;
- *)
- echo apt-get-update: unknown option $1
- exit 1
- ;;
- esac
- }
- ## mount-chroot {|--umount} [file system|name]
- ## support file systems: /home /tmp /sys /proc /dev/shm /dev/pts /dev
- ## support names: vfs archives_dir
- ## NOTE: /tmp needs for applications which use X
- ## vfs is virtual file systems
- ## archives_dir uses to mount ${EXTERNAL_ARCHIVES_DIR} to ${ARCHIVES_DIR}
- ## unionfs_dir covers ${BUILD_ROOT} with unionfs
- mount-chroot(){
- if [ "$1" = "--umount" ]; then
- mount-chroot-umount $2 || return 1
- else
- mount-chroot-mount $1 || return 1
- fi
- return 0
- }
- ## mount-chroot-umount [file system|name]
- mount-chroot-umount(){
- local fs=$1
- case $fs in
- /home|/tmp|/sys|/proc|/dev/shm|/dev/pts|/dev)
- [ -d ${BUILD_ROOT}${fs} ] || return 1
- [ -z "$(mount | grep ${BUILD_ROOT}${fs})" ] || \
- umount ${BUILD_ROOT}${fs}
- if [ ! -z "$(mount | grep ${BUILD_ROOT}${fs})" ]; then
- echo $"Retry lazy unmount ${BUILD_ROOT}${fs} ... "
- umount -l ${BUILD_ROOT}${fs}
- echo $"done."
- fi
- ;;
- vfs)
- for dir in /sys /proc /dev/shm /dev/pts /dev; do
- mount-chroot-umount ${dir} || return 1
- done
- ;;
- archives_dir)
- [ -d ${ARCHIVES_DIR} ] || return 1
- [ -z "$(mount | grep ${ARCHIVES_DIR})" ] || \
- umount ${ARCHIVES_DIR}
- ;;
- unionfs_dir)
- [ -d ${BUILD_ROOT} ] || return 1
- [ -z "$(mount | grep ${BUILD_ROOT} | grep unionfs)" ] || \
- umount ${BUILD_ROOT}
- if [ ! -z "$(mount | grep ${BUILD_ROOT} | grep unionfs)" ]; then
- echo $"Retry lazy unmount ${BUILD_ROOT} ... "
- umount -l ${BUILD_ROOT}
- echo $"done."
- fi
- ;;
- *)
- echo mount-chroot-umount: unknown file system $fs
- exit 1
- ;;
- esac
- return 0
- }
- ## mount-chroot-mount [file system|name]
- mount-chroot-mount(){
- local fs=$1
- case $fs in
- /home)
- [ -d ${BUILD_ROOT}${fs} ] || mkdir -p ${BUILD_ROOT}${fs}
- [ -z "$(mount | grep ${BUILD_ROOT}${fs})" ] && \
- mount -o _netdev,rbind ${fs} ${BUILD_ROOT}${fs}
- ;;
- /tmp|/dev)
- [ -d ${BUILD_ROOT}${fs} ] || mkdir -p ${BUILD_ROOT}${fs}
- [ -z "$(mount | grep ${BUILD_ROOT}${fs})" ] && \
- mount --bind -o _netdev ${fs} ${BUILD_ROOT}${fs}
- ;;
- /sys)
- [ -d ${BUILD_ROOT}${fs} ] || mkdir -p ${BUILD_ROOT}${fs}
- [ -z "$(mount | grep ${BUILD_ROOT}${fs})" ] && \
- mount -o _netdev -t sysfs vbuildersysfs ${BUILD_ROOT}${fs}
- ;;
- /proc)
- [ -d ${BUILD_ROOT}${fs} ] || mkdir -p ${BUILD_ROOT}${fs}
- [ -z "$(mount | grep ${BUILD_ROOT}${fs})" ] && \
- mount -o _netdev -t proc vbuilderproc ${BUILD_ROOT}${fs}
- ;;
- /dev/shm)
- [ -d ${BUILD_ROOT}${fs} ] || mkdir -p ${BUILD_ROOT}${fs}
- [ -z "$(mount | grep ${BUILD_ROOT}${fs})" ] && \
- mount -o _netdev -t tmpfs vbuildertmpfs ${BUILD_ROOT}${fs}
- ;;
- /dev/pts)
- [ -d ${BUILD_ROOT}${fs} ] || mkdir -p ${BUILD_ROOT}${fs}
- [ -z "$(mount | grep ${BUILD_ROOT}${fs})" ] && \
- mount -o gid=5,mode=620,_netdev -t devpts vbuilderdevpts ${BUILD_ROOT}${fs}
- ;;
- vfs)
- for dir in /dev /dev/pts /dev/shm /proc /sys; do
- mount-chroot-mount ${dir} || return 1
- done
- ;;
- archives_dir)
- [ -d ${EXTERNAL_ARCHIVES_DIR} ] || mkdir -p ${EXTERNAL_ARCHIVES_DIR}
- [ -d ${ARCHIVES_DIR} ] || mkdir -p ${ARCHIVES_DIR}
- [ -z "$(mount | grep ${ARCHIVES_DIR})" ] && \
- mount --bind -o _netdev ${EXTERNAL_ARCHIVES_DIR} ${ARCHIVES_DIR}
- [ -d ${ARCHIVES_DIR}/partial ] || mkdir -p ${ARCHIVES_DIR}/partial
- ;;
- unionfs_dir)
- if [ $with_unionfs -eq 1 ]; then
- [ -d ${UNIONFS_ROOT} ] || mkdir -p ${UNIONFS_ROOT}
- [ -z "$(mount | grep ${UNIONFS_ROOT})" ] && \
- mount -t unionfs -o dirs=${UNIONFS_ROOT}=rw:${BUILD_ROOT}=ro unionfs ${BUILD_ROOT}
- unionctl ${BUILD_ROOT} --list
- fi
- ;;
- *)
- echo mount-chroot-mount: unknown file system $fs
- exit 1
- ;;
- esac
- return 0
- }
- ##############################################################################
- Clean(){
- setup-vbootstrap || return 1
- # mount-chroot --umount /home
- mount-chroot --umount /tmp
- mount-chroot --umount /dev/shm
- mount-chroot --umount /dev/pts
- mount-chroot --umount /proc
- mount-chroot --umount archives_dir
- mount-chroot --umount unionfs_dir
- apt-get-update --host
- ## We remark that we first remove /, and secondly remove /.
- ## If we directly remove /, we obtained some non-empty directories:
- ## /dev/.udev/rules.d.
- if [ $with_unionfs -eq 1 ]; then
- if [ -d ${UNIONFS_ROOT} ]; then
- echo -n $"Cleaning build root ${UNIONFS_ROOT} via unionfs ... "
- rm -rf ${UNIONFS_ROOT} 2>/dev/null
- rm -rf ${UNIONFS_ROOT}
- echo $"done."
- fi
- else
- if [ -d ${BUILD_ROOT} ]; then
- echo -n $"Cleaning build root ${BUILD_ROOT} ... "
- rm -rf ${BUILD_ROOT} 2>/dev/null
- rm -rf ${BUILD_ROOT}
- echo $"done."
- fi
- fi
- echo $"Cleanup a build farm for ${PROFILE} done."
- return 0
- }
- Build(){
- setup-vbootstrap || return 1
- if [ $with_dist_upgrade -eq 1 ]; then
- ## make bootstrap of ${STABLE_VERSION}
- /usr/sbin/vbootstrap \
- $(echo ${PROFILE} | sed -e "s/VineSeed/${STABLE_VERSION}/") \
- ${BUILD_ROOT}
- ## aim apt-line to VineSeed
- sed -i "s/apt ${STABLE_VERSION}/apt VineSeed/g" \
- ${BUILD_ROOT}/etc/apt/sources.list.d/main.list
- else
- /usr/sbin/vbootstrap ${PROFILE} ${BUILD_ROOT}
- fi
- mount-chroot /proc
- mount-chroot archives_dir
- mount-chroot /dev/pts
- mount-chroot /dev/shm
- # mount-chroot /tmp
- # mount-chroot /home
- $__chroot_sh 'apt-get -qq update && apt-get -qq -y dist-upgrade'
- ##!! 4.2 has no apt-sourceslist-{plus,nonfree,proposed-updates} packages
- case ${VERSION} in
- 4.2)
- $__chroot_sh "sed -i -e 's/main plus updates nonfree *$/$(echo ${CATEGORIES} | sed -e "s/,/ /"g) updates/g' /etc/apt/sources.list"
- # [ $with_category_security -eq 1 ] && \
- # echo
- ;;
- 5.2|@@VBUILDER_STABLE_VERSION@@)
- [ $with_category_plus -eq 1 ] && \
- $__chroot_sh 'apt-get -qq update && apt-get -qq -y install apt-sourceslist-plus'
- [ $with_category_nonfree -eq 1 ] && \
- $__chroot_sh 'apt-get -qq update && apt-get -qq -y install apt-sourceslist-nonfree'
- [ $with_category_proposed_updates -eq 1 ] && \
- $__chroot_sh 'apt-get -qq update && apt-get -qq -y install apt-sourceslist-proposed-updates'
- # [ $with_category_security -eq 1 ] && \
- # echo
- ;;
- VineSeed)
- [ $with_category_plus -eq 1 ] && \
- $__chroot_sh 'apt-get -qq update && apt-get -qq -y install apt-sourceslist-plus'
- [ $with_category_nonfree -eq 1 ] && \
- $__chroot_sh 'apt-get -qq update && apt-get -qq -y install apt-sourceslist-nonfree'
- [ $with_category_test -eq 1 ] && \
- $__chroot_sh 'apt-get -qq update && apt-get -qq -y install apt-sourceslist-test'
- ;;
- esac
- [ $with_dist_upgrade -eq 1 ] && \
- $__chroot_sh 'apt-get -qq update && apt-get -qq -y dist-upgrade'
- $__chroot_sh 'apt-get -qq -y install build-essential'
- $__chroot_sh 'apt-get -qq -y install etcskel shadow-utils'
- $__chroot_sh 'cd /dev && /sbin/MAKEDEV console'
- $__chroot_sh 'cd /dev && /sbin/MAKEDEV ptmx'
- $__chroot_sh 'cd /dev && /sbin/MAKEDEV null'
- $__chroot_sh 'cd /dev && /sbin/MAKEDEV zero'
- $__chroot_sh 'cd /dev && /sbin/MAKEDEV random'
- $__chroot_sh 'cd /dev && /sbin/MAKEDEV urandom'
- $__chroot_sh 'cd /dev && mkdir -p shm && chmod 777 shm'
- $__chroot_sh 'cd /dev && mkdir -p pts && chmod 755 pts'
- $__chroot_sh '/usr/sbin/pwconv'
- $__chroot_sh "/usr/sbin/useradd ${BUILD_USER}"
- ##!! for rpm-4.8.0 or higher
- ##!! (See http://trac.vinelinux.org/wiki/Vine6/AboutUpdateToolchain)
- if [ "${VERSION}" = "VineSeed" ]; then
- $__chroot_sh "sed -i -e 's/^%_topdir/#%_topdir/' /home/${BUILD_USER}/.rpmmacros"
- fi
- # mount-chroot --umount /home
- # mount-chroot --umount /tmp
- mount-chroot --umount /dev/shm
- mount-chroot --umount /dev/pts
- mount-chroot --umount archives_dir
- mount-chroot --umount /proc
- apt-get-update --host
- echo $"Making a build farm for ${PROFILE} done."
- return 0
- }
- RPM_Remove(){
- setup-vbootstrap-rpm || return 1
- mount-chroot unionfs_dir
- mount-chroot archives_dir
- mount-chroot /proc
- mount-chroot /dev/pts
- mount-chroot /dev/shm
- apt-get-update --chroot
- [ -f $RPM_PKG ] && \
- echo $"E: $RPM_PKG is not a package name" && return 1
- $__chroot_sh "apt-get -y remove $BASE_RPM_PKG"
- mount-chroot --umount /dev/shm
- mount-chroot --umount /dev/pts
- mount-chroot --umount /proc
- mount-chroot --umount archives_dir
- mount-chroot --umount unionfs_dir
- apt-get-update --host
- return 0
- }
- RPM_Install(){
- setup-vbootstrap-rpm || return 1
- mount-chroot unionfs_dir
- mount-chroot archives_dir
- mount-chroot /proc
- mount-chroot /dev/pts
- mount-chroot /dev/shm
- apt-get-update --chroot
- [ $with_category_nonfree -eq 1 ] && \
- [ ! -z "$(echo $BASE_RPM_PKG | grep -e 'self-build-' -e 'install-assist-')" ] && \
- $__chroot_sh 'rpm -q --quiet self-build-setup || apt-get -qq -y install self-build-setup'
- $__chroot_sh "cd ${BUILD_DIR} && apt-get -y install $BASE_RPM_PKG"
- mount-chroot --umount /dev/shm
- mount-chroot --umount /dev/pts
- mount-chroot --umount /proc
- mount-chroot --umount archives_dir
- mount-chroot --umount unionfs_dir
- apt-get-update --host
- return 0
- }
- RPM_Build(){
- setup-vbootstrap-rpm || return 1
- mount-chroot unionfs_dir
- mount-chroot archives_dir
- mount-chroot /proc
- mount-chroot /dev/pts
- mount-chroot /dev/shm
- apt-get-update --chroot
- [ ! -f $RPM_PKG ] && \
- echo $"E: $RPM_PKG is not a source RPM package" && return 1
-
- RPM_PKG_USER=$(stat -c %U $RPM_PKG)
- RPM_PKG_GROUP=$(stat -c %G $RPM_PKG)
- [ ! -z "${SUDO_UID}" ] && RPM_PKG_USER=${SUDO_UID}
- [ ! -z "${SUDO_GID}" ] && RPM_PKG_GROUP=${SUDO_GID}
- local __install="install -p -v -o ${RPM_PKG_USER} -g ${RPM_PKG_GROUP}"
- ## make src.rpm for $VERSION
- $__chroot_sh "cd ${BUILD_DIR} && su ${BUILD_USER} -c 'rpm -ivh $BASE_RPM_PKG'"
- $__chroot_sh "cd ${BUILD_DIR} && su ${BUILD_USER} -c 'rpmbuild -bs --nodeps --clean --rmsource --rmspec $RPM_OPTS ${BUILD_DIR}/SPECS/*.spec'"
- ## change ${DIST_RELEASE}
- BASE_RPM_PKG=$(echo $BASE_RPM_PKG | sed -e "s/vl[0-9]*\([A-Za-z]*[0-9A-Za-z]*\)\./vl${DIST_RELEASE}\1\./")
- ## rebuild $BASE_RPM_PKG on ${DIST_RELEASE}
- $__chroot_sh "cd ${BUILD_DIR}/SRPMS && apt-get -o APT::Install::Virtual=true -y build-dep $BASE_RPM_PKG"
- $__chroot_sh "cd ${BUILD_DIR}/SRPMS && su ${BUILD_USER} -c 'rpmbuild --rebuild $RPM_OPTS $BASE_RPM_PKG'"
- BUILT_RPMS_LIST=$(find $BUILD_ROOT${BUILD_DIR}/RPMS -type f -regex '.*\.rpm' | sed -e s@${BUILD_ROOT}@@g -e 's|.*\/compat32-.*||g' -e 's|.*\/.*\.src\.rpm||g' -e 's/$/ \\/g')
- [ $with_category_nonfree -eq 1 ] && \
- [ ! -z "$(echo $BUILT_RPMS_LIST | grep -e 'self-build-' -e 'install-assist-')" ] && \
- $__chroot_sh 'rpm -q --quiet self-build-setup || apt-get -qq -y install self-build-setup'
- [ $with_no_install -eq 0 ] && \
- $__chroot_sh "cd ${BUILD_DIR} && apt-get -y install $BUILT_RPMS_LIST"
- ## copy built rpms to ${HOME}/rpm/ for each archtectures
- echo $"Copying built rpms to ${BUILT_RPMS_DIR} for each archtectures ... "
- for i in $RPM_PKG_ARCH_LIST; do
- [ -d $BUILD_ROOT${BUILD_DIR}/${i} ] || continue
- if [ ! -d ${BUILT_RPMS_DIR}/${VERSION}/${i} ]; then
- $__install -d ${BUILT_RPMS_DIR}/${VERSION}/${i}/
- chown -R ${RPM_PKG_USER}:${RPM_PKG_GROUP} ${BUILT_RPMS_DIR}
- fi
- find $BUILD_ROOT${BUILD_DIR}/${i} -type f -regex '.*\.rpm' \
- -exec $__install -m0644 {} ${BUILT_RPMS_DIR}/${VERSION}/${i}/ \;
- done
- mount-chroot --umount /dev/shm
- mount-chroot --umount /dev/pts
- mount-chroot --umount /proc
- mount-chroot --umount archives_dir
- mount-chroot --umount unionfs_dir
- apt-get-update --host
- echo $"done."
- return 0
- }
- RPM_Sign(){
- [ $with_sign -eq 1 ] || return 1
- setup-vbootstrap || return 1
- [ -d ${BUILD_ROOT} ] || Build
- mount-chroot unionfs_dir
- echo $"Signing built rpms using ${RPM_SIGN_USER}'s key: "
- 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')"
- mount-chroot --umount unionfs_dir
- return 0
- }
- Login_Chroot(){
- [ $with_login -eq 1 ] || return 1
- setup-vbootstrap || return 1
- __chroot="/usr/sbin/chroot ${BUILD_ROOT}"
- ## setarch ix86 if ix86 chroot on x86_64 host
- [ $with_ix86_on_x86_64 -eq 1 ] && \
- __chroot="/usr/sbin/chroot ${BUILD_ROOT} setarch ${VARCH}"
- mount-chroot unionfs_dir
- mount-chroot archives_dir
- mount-chroot /proc
- mount-chroot /dev/pts
- mount-chroot /dev/shm
- mount-chroot /tmp
- # mount-chroot /home
- apt-get-update --chroot
- ## copy host's configurations of /etc
- #passwd shadow group gshadow
- for i in resolv.conf hosts; do
- cp -pf /etc/${i} ${BUILD_ROOT}/etc
- done
- cp -Ppf /etc/localtime ${BUILD_ROOT}/etc
- $__chroot /bin/bash
- # mount-chroot --umount /home
- mount-chroot --umount /tmp
- mount-chroot --umount /dev/shm
- mount-chroot --umount /dev/pts
- mount-chroot --umount /proc
- mount-chroot --umount archives_dir
- mount-chroot --umount unionfs_dir
- apt-get-update --host
- return 0
- }
- ##############################################################################
- setup-vbuilder || exit 1
- check-parameter $* || exit 1
- while [ $# -gt 0 ]; do
- tmpARG=$1
- case $tmpARG in
- --version|--arch|--category|--target|--rpmbuild-define|--rpmbuild-with|--rpmbuild-without|--bootstrap-dir|--unionfs-dir|--cache-dir|--built-rpms-dir)
- shift
- ;;
- --dist-upgrade|--unionfs|--with-compat32|--sign|--no-install|--login|--debug)
- ;;
- --build-rpm|build-rpm|--install-rpm|install-rpm|--remove-rpm|remove-rpm)
- shift
- ;;
- --build|build|--clean|clean)
- ;;
- *)
- echo unknown option $1
- exit 1
- ;;
- esac
- case $tmpARG in
- --version)
- VERSION=$1
- ;;
- --arch)
- VARCH=$1
- ;;
- --category)
- CATEGORIES=$1
- ;;
- --dist-upgrade)
- with_dist_upgrade=1
- ;;
- --unionfs)
- with_unionfs=1
- ;;
- --target)
- TARGET=$1
- RPM_OPTS="${RPM_OPTS} --target $TARGET"
- ;;
- --with-compat32)
- RPM_OPTS="${RPM_OPTS} --with compat32"
- ;;
- --rpmbuild-define)
- RPM_OPTS="${RPM_OPTS} --define $1"
- ;;
- --rpmbuild-with)
- RPM_OPTS="${RPM_OPTS} --with $1"
- ;;
- --rpmbuild-without)
- RPM_OPTS="${RPM_OPTS} --without $1"
- ;;
- --sign)
- with_sign=1
- ;;
- --no-install)
- with_no_install=1
- ;;
- --login)
- with_login=1
- ;;
- --bootstrap-dir)
- VBOOTSTRAP_DIR=$1
- ;;
- --unionfs-dir)
- UNIONFS_DIR=$1
- ;;
- --cache-dir)
- CACHE_DIR=$1
- ;;
- --built-rpms-dir)
- BUILT_RPMS_DIR=$1
- ;;
- --debug)
- with_debug=1
- ;;
- --build-rpm|build-rpm)
- RPM_PKG=$1
- RPM_Build || exit 1
- ;;
- --install-rpm|install-rpm)
- RPM_PKG=$1
- RPM_Install || exit 1
- ;;
- --remove-rpm|remove-rpm)
- RPM_PKG=$1
- RPM_Remove || exit 1
- ;;
- --build|build)
- Build || exit 1
- ;;
- --clean|clean)
- Clean || exit 1
- ;;
- esac
- shift
- done
- RPM_Sign ||:
- Login_Chroot ||:
- exit
|