123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312 |
- #!/bin/bash
- # -*- coding: utf-8-unix -*-
- Usage_C(){
- cat<<EOF
- Usage: $(basename $0) {--version [version]} {--arch [arch]} {--build-rpm [src.rpm]|--install-rpm [arch.rpm]|--remove-rpm [package]|--build|--clean}
- --version: set [version] (default: ${DEFAULT_VERSION})
- --arch: set [arch] (default: $(uname -i))
- --build-rpm: build [src.rpm] on boostrap
- --install-rpm: install [arch.rpm] on boostrap
- --remove-rpm: remove [package] on boostrap
- --build: build boostrap of [version]
- --clean: clean boostrap of [version]
- For example,
- * make a clean/plain build environment on the current archtecture:
- $(basename $0) --clean --build
- * build source RPM:
- $(basename $0) --build-rpm [src.rpm]
- * make a plain build environment for Vine Linux 4.2:
- $(basename $0) --version 4.2 --clean --build
- * make a i386 chroot on x86_64:
- $(basename $0) --arch i386 --clean --build
- $(/usr/sbin/vbootstrap | sed -e s/^Usage:.*// -e s/^E:.*//)
- EOF
- }
- Usage_ja(){
- Usage_C
- }
- Msg_MissingParameter_C(){
- while read para; do
- cat<<EOF
- E: Missing some parameter before ${para}
- EOF
- done
- }
- Msg_MissingParameter_ja(){
- Msg_MissingParameter_C
- }
- Msg_NoSupportVARCH_C(){
- cat<<EOF
- E: arch ${VARCH} is NO support on $(uname -i)
- EOF
- }
- Msg_NoSupportVARCH_ja(){
- Msg_NoSupportVARCH_C
- }
- Msg_NoSupportVERSION_C(){
- cat<<EOF
- E: version ${VERSION} is NO support
- EOF
- }
- Msg_NoSupportVERSION_ja(){
- Msg_NoSupportVERSION_C
- }
- ##############################################################################
- setup-vbuilder(){
- ## load default settings
- if [ -d /etc/vbootstrap/vbuilder.conf ]; then
- . /etc/vbootstrap/vbuilder.conf
- else
- [ -z "${VBOOTSTRAP_DIR}" ] && \
- VBOOTSTRAP_DIR=@@VBUILDER_VBOOTSTRAP_DIR@@
- [ -z "${DEFAULT_VERSION}" ] && \
- DEFAULT_VERSION=@@VBUILDER_DEFAULT_VERSION@@
- fi
- [ -d $VBOOTSTRAP_DIR ] || mkdir -p $VBOOTSTRAP_DIR
- VERSION=$DEFAULT_VERSION
- ## set locale
- case $LANG in
- ja*) LOCALE=ja ;;
- *) LOCALE=C ;;
- esac
- }
- check-next-parameter(){
- while read arg; do
- if [ $(echo ${arg} | grep '^-') ]; then
- echo ${arg} | Msg_MissingParameter_$LOCALE
- return 1
- fi
- done
- }
- FLAG_setup_vbootstrap=0
- setup-vbootstrap(){
- if [ ${FLAG_setup_vbootstrap} -eq 0 ]; then
- FLAG_setup_vbootstrap=1
- ## check a chroot archtecture
- if [ ! -z ${VARCH} ]; then
- case "${VARCH}" in
- i386)
- [ "$(uname -i)" = "ppc" ] && \
- Msg_NoSupportVARCH_$LOCALE
- [ $? -eq 0 ] && exit 1
- ;;
- x86_64)
- [ "$(uname -i)" = "ppc" ] && \
- Msg_NoSupportVARCH_$LOCALE
- [ $? -eq 0 ] && exit 1
- ;;
- ppc)
- [ "$(uname -i)" = "i386" -o "$(uname -i)" = "x86_64" ] && \
- Msg_NoSupportVARCH_$LOCALE
- [ $? -eq 0 ] && exit 1
- ;;
- esac
- fi
- [ -z ${VARCH} ] && VARCH=$(uname -i)
- ##!! IRREGULAR: 4.2 is NO support on x86_64
- if [ "${VERSION}" = "4.2" -a "$(uname -i)" = "x86_64" ]; then
- Msg_NoSupportVERSION_${LOCALE}
- exit 1
- fi
- ## support for i386 chroot on x86_64 below:
- [ "${VARCH}" != "$(uname -i)" ] && VERSION=${VERSION}_${VARCH}
- ## check support ${VERSION}
- if [ -z "$(/usr/sbin/vbootstrap | sed -e s/^Usage:.*// -e s/^E:.*// | grep -m 1 ${VERSION})" ]; then
- Msg_NoSupportVERSION_$LOCALE
- exit 1
- fi
- fi
- BUILD_ROOT=${VBOOTSTRAP_DIR}/${VERSION}
- BUILD_USER=vbuilder
- CACHE_DIR=${VBOOTSTRAP_DIR}/cache/${VERSION}
- BUILD_DIR=/home/${BUILD_USER}/rpm
- mkdir -p $VBOOTSTRAP_DIR
- }
- ##############################################################################
- Clean(){
- setup-vbootstrap
- [ -d ${BUILD_ROOT}/proc ] && \
- umount ${BUILD_ROOT}/proc
- if [ -d ${BUILD_ROOT}/var/cache/apt/archives ]; then
- echo -n "Chaching RPMs in ${CACHE_DIR}/apt/archives ... "
- [ -d ${CACHE_DIR}/apt/archives ] || mkdir -p ${CACHE_DIR}/apt/archives
- mv -f ${BUILD_ROOT}/var/cache/apt/archives/*.rpm ${CACHE_DIR}/apt/archives/
- echo "done."
- fi
- if [ -d ${BUILD_ROOT} ]; then
- echo -n "Cleaning build root \"${BUILD_ROOT}\" ... "
- rm -rf ${BUILD_ROOT}
- echo "done."
- fi
- }
- Build(){
- setup-vbootstrap
- /usr/sbin/vbootstrap ${VERSION} ${BUILD_ROOT}
- [ -d ${BUILD_ROOT}/proc ] || mkdir -p ${BUILD_ROOT}/proc
- mount -t proc proc ${BUILD_ROOT}/proc
- if [ -d ${CACHE_DIR} ]; then
- echo -n "Copying chached RPMs to ${BUILD_ROOT}/var/cache/apt/archives ... "
- cp -f ${CACHE_DIR}/apt/archives/*.rpm ${BUILD_ROOT}/var/cache/apt/archives/
- echo "done."
- fi
- /usr/sbin/chroot ${BUILD_ROOT} \
- /bin/sh -c 'apt-get update && apt-get -y dist-upgrade'
- /usr/sbin/chroot ${BUILD_ROOT} \
- /bin/sh -c 'apt-get -y install apt-sourceslist-plus && apt-get update'
- /usr/sbin/chroot ${BUILD_ROOT} \
- /bin/sh -c 'apt-get -y install apt-sourceslist-nonfree && apt-get update'
- /usr/sbin/chroot ${BUILD_ROOT} \
- /bin/sh -c 'apt-get -y install build-essential self-build-setup'
- /usr/sbin/chroot ${BUILD_ROOT} \
- /bin/sh -c 'apt-get -y install etcskel shadow-utils'
- /usr/sbin/chroot ${BUILD_ROOT} /bin/sh -c 'cd /dev && /sbin/MAKEDEV console'
- /usr/sbin/chroot ${BUILD_ROOT} /bin/sh -c 'cd /dev && /sbin/MAKEDEV null'
- /usr/sbin/chroot ${BUILD_ROOT} /bin/sh -c 'cd /dev && /sbin/MAKEDEV zero'
-
- /usr/sbin/chroot ${BUILD_ROOT} /bin/sh -c '/usr/sbin/pwconv'
- /usr/sbin/chroot ${BUILD_ROOT} /bin/sh -c "/usr/sbin/useradd ${BUILD_USER}"
- echo "Making a build farm for ${VERSION} done."
- }
- setup-vbootstrap-rpm(){
- setup-vbootstrap
- ## check ${BUILD_ROOT}
- [ -d ${BUILD_ROOT} ] || Build
- 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
- }
- RPM_Remove(){
- setup-vbootstrap-rpm
- if [ -f $RPM_PKG ]; then
- echo "$RPM_PKG: not package name."
- exit 1
- fi
- /usr/sbin/chroot ${BUILD_ROOT} \
- /bin/sh -c "apt-get -y remove $BASE_RPM_PKG"
- }
- RPM_Install(){
- setup-vbootstrap-rpm
- /usr/sbin/chroot ${BUILD_ROOT} \
- /bin/sh -c "cd ${BUILD_DIR} && apt-get -y install $BASE_RPM_PKG"
- }
- RPM_Build(){
- setup-vbootstrap-rpm
- if [ ! -f $RPM_PKG ]; then
- echo "$RPM_PKG: not source RPM package."
- exit 1
- fi
- /usr/sbin/chroot ${BUILD_ROOT} \
- /bin/sh -c "cd ${BUILD_DIR} && apt-get -y build-dep $BASE_RPM_PKG"
- /usr/sbin/chroot ${BUILD_ROOT} \
- /bin/sh -c "cd ${BUILD_DIR} && su ${BUILD_USER} -c 'rpmbuild --rebuild $RPM_OPTS $BASE_RPM_PKG'"
- /usr/sbin/chroot ${BUILD_ROOT} \
- /bin/sh -c "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/$/ \\/g')"
- }
- ##############################################################################
- setup-vbuilder
- [ $# -eq 0 ] && Usage_$LOCALE
- while [ $# -gt 0 ]; do
- case "$1" in
- --version)
- shift;
- echo $1 | check-next-parameter
- [ $? -eq 1 ] && exit 1
- VERSION=$1
- ;;
- --arch)
- shift;
- echo $1 | check-next-parameter
- [ $? -eq 1 ] && exit 1
- VARCH=$1
- ;;
- ##!! This option is obsolete for 5.0 or above higher version on i386.
- --with-compat32)
- RPM_OPTS="--with compat32"
- ;;
- --build-rpm)
- shift;
- echo $1 | check-next-parameter
- [ $? -eq 1 ] && exit 1
- RPM_PKG=$1
- RPM_Build
- ;;
- --install-rpm)
- shift;
- echo $1 | check-next-parameter
- [ $? -eq 1 ] && exit 1
- RPM_PKG=$1
- RPM_Install
- ;;
- --remove-rpm)
- shift;
- echo $1 | check-next-parameter
- [ $? -eq 1 ] && exit 1
- RPM_PKG=$1
- RPM_Remove
- ;;
- --build)
- Build
- ;;
- --clean)
- Clean
- ;;
- *)
- Usage_$LOCALE
- exit 1
- ;;
- esac
- shift
- done
- exit
|