|
@@ -0,0 +1,179 @@
|
|
|
+#!/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}
|
|
|
+
|
|
|
+ BUILD_ROOT=${VBOOTSTRAP_DIR}/${VERSION}
|
|
|
+ CACHE_DIR=${VBOOTSTRAP_DIR}/cache/${VERSION}
|
|
|
+ BUILD_DIR=/usr/src/vine
|
|
|
+ fi
|
|
|
+}
|
|
|
+
|
|
|
+##############################################################################
|
|
|
+
|
|
|
+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 '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'
|
|
|
+}
|
|
|
+
|
|
|
+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} && 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/$/ \\/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
|
|
|
+
|