123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187 |
- #!/bin/bash
- # -*- coding: utf-8-unix -*-
- ## default settings
- VBOOTSTRAP_DIR=/var/local/vbootstrap
- [ -d $VBOOTSTRAP_DIR ] || mkdir -p $VBOOTSTRAP_DIR
- DEFAULT_VERSION=@@DEFAULT_VERSION@@
- VERSION=$DEFAULT_VERSION
- Usage(){
- cat<<EOF
- Usage: $(basename $0) {--version [version]} {--arch [arch]} {--with-compat32} {--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))
- --with-compat32: build with compat32 on boostrap
- --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 plain build environment:
- $(basename $0) --clean --build
- * build source RPM:
- $(basename $0) --build-rpm [src.rpm]
- * make Vine Linux 4.2 environment:
- $(basename $0) --version 4.2 --clean --build
- * i386 chroot on x86_64:
- $(basename $0) --arch i386 --clean --build
- * build compat32:
- $(basename $0) --arch i386 --with-compat32 --build-rpm [src.rpm]
- EOF
- exit 1
- }
- FLAG_setup_vbootstrap=0
- setup-vbootstrap(){
- if [ ${FLAG_setup_vbootstrap} -eq 0 ]; then
- FLAG_setup_vbootstrap=1
- [ -z ${VARCH} ] && VARCH=$(uname -i)
- [ "${VARCH}" != "$(uname -i)" ] && VERSION=${VERSION}_${VARCH}
- 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
- umount ${BUILD_ROOT}/proc
- if [ -d ${BUILD_ROOT}/var/cache/apt/archives ]; then
- [ -d ${CACHE_DIR}/apt/archives ] || mkdir -p ${CACHE_DIR}/apt/archives
- mv -f ${BUILD_ROOT}/var/cache/apt/archives/*.rpm ${CACHE_DIR}/apt/archives/
- fi
- rm -rf $BUILD_ROOT/
- }
- 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
- [ -d ${CACHE_DIR} -a "${VARCH}" = "$(uname -i)" ] && \
- cp -f ${CACHE_DIR}/apt/archives/*.rpm ${BUILD_ROOT}/var/cache/apt/archives/
- /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}"
- }
- setup-vbootstrap-rpm(){
- setup-vbootstrap
- 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')"
- }
- [ $# -eq 0 ] && Usage
- while [ $# -gt 0 ]; do
- case "$1" in
- --version)
- shift;
- VERSION=$1
- ;;
- --arch)
- shift;
- VARCH=$1
- ;;
- --with-compat32)
- RPM_OPTS="--with compat32"
- ;;
- --build-rpm)
- shift;
- RPM_PKG=$1
- RPM_Build
- ;;
- --install-rpm)
- shift;
- RPM_PKG=$1
- RPM_Install
- ;;
- --remove-rpm)
- shift;
- RPM_PKG=$1
- RPM_Remove
- ;;
- --build)
- Build
- ;;
- --clean)
- Clean
- ;;
- *)
- Usage
- ;;
- esac
- shift
- done
- exit
|