#!/bin/bash # -*- coding: utf-8-unix -*- Usage_C(){ cat< /dev/null 2>&1 echo "done." ;; --chroot) echo -n "apt-get update on chroot ... " /usr/sbin/chroot ${BUILD_ROOT} \ /bin/sh -c 'apt-get update' > /dev/null 2>&1 echo "done." ;; *) echo apt-get-update: unknown option $1 exit 1 ;; esac } ## mount /home mount_home(){ if [ "$1" = "--umount" ]; then [ -d ${BUILD_ROOT}/home ] || return 1 [ -z "$(mount | grep ${BUILD_ROOT}/home)" ] || \ umount ${BUILD_ROOT}/home else [ -d ${BUILD_ROOT}/home ] || mkdir -p ${BUILD_ROOT}/home [ -z "$(mount | grep ${BUILD_ROOT}/home)" ] && \ mount -o rbind /home ${BUILD_ROOT}/home fi } ## mount /tmp for applications which use X mount_tmp(){ if [ "$1" = "--umount" ]; then [ -d ${BUILD_ROOT}/tmp ] || return 1 [ -z "$(mount | grep ${BUILD_ROOT}/tmp)" ] || \ umount ${BUILD_ROOT}/tmp else [ -d ${BUILD_ROOT}/tmp ] || mkdir -p ${BUILD_ROOT}/tmp [ -z "$(mount | grep ${BUILD_ROOT}/tmp)" ] && \ mount --bind /tmp ${BUILD_ROOT}/tmp fi } ## mount virtual file systems mount_vfs(){ if [ "$1" = "--umount" ]; then # for dir in /sys /proc /dev/shm /dev/pts /dev; do # [ -z "$(mount | grep ${BUILD_ROOT}${dir})" ] || \ # umount ${BUILD_ROOT}${dir} # done [ -d ${BUILD_ROOT}/proc ] || return 1 [ -z "$(mount | grep ${BUILD_ROOT}/proc)" ] || \ umount ${BUILD_ROOT}/proc else # for dir in /dev /dev/pts /dev/shm /proc /sys; do # [ -d ${BUILD_ROOT}${dir} ] || mkdir -p ${BUILD_ROOT}${dir} # mount --bind ${dir} ${BUILD_ROOT}${dir} # done [ -d ${BUILD_ROOT}/proc ] || mkdir -p ${BUILD_ROOT}/proc [ -z "$(mount | grep ${BUILD_ROOT}/proc)" ] && \ mount --bind /proc ${BUILD_ROOT}/proc fi } ############################################################################## Clean(){ setup-vbootstrap # mount_home --umount # mount_tmp --umount mount_vfs --umount apt-get-update --host if [ -d ${BUILD_ROOT}/var/cache/apt/archives ]; then echo -n "Caching 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 echo "Cleanup a build farm for ${VERSION} done." } Build(){ setup-vbootstrap if [ $with_dist_upgrade -eq 1 ]; then ## make bootstrap of ${STABLE_VERSION} /usr/sbin/vbootstrap \ $(echo ${VERSION} | 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 ${VERSION} ${BUILD_ROOT} fi mount_vfs # mount_tmp # mount_home if [ -d ${CACHE_DIR} ]; then echo -n "Copying cached 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' if [ $with_dist_upgrade -eq 1 ]; then /usr/sbin/chroot ${BUILD_ROOT} \ /bin/sh -c 'apt-get update && apt-get -y dist-upgrade' fi /usr/sbin/chroot ${BUILD_ROOT} \ /bin/sh -c 'apt-get -y install build-essential' /usr/sbin/chroot ${BUILD_ROOT} \ /bin/sh -c 'apt-get -y install 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}" # mount_home --umount # mount_tmp --umount mount_vfs --umount apt-get-update --host echo "Making a build farm for ${VERSION} done." } RPM_Remove(){ setup-vbootstrap-rpm mount_vfs if [ -f $RPM_PKG ]; then Msg_NotPackageName_$LOCALE exit 1 fi /usr/sbin/chroot ${BUILD_ROOT} \ /bin/sh -c "apt-get -y remove $BASE_RPM_PKG" mount_vfs --umount apt-get-update --host } RPM_Install(){ setup-vbootstrap-rpm mount_vfs apt-get-update --chroot /usr/sbin/chroot ${BUILD_ROOT} \ /bin/sh -c "cd ${BUILD_DIR} && apt-get -y install $BASE_RPM_PKG" mount_vfs --umount apt-get-update --host } RPM_Build(){ setup-vbootstrap-rpm mount_vfs if [ ! -f $RPM_PKG ]; then Msg_NotSourceRPM_$LOCALE exit 1 fi RPM_PKG_USER=$(stat -c %U $RPM_PKG) RPM_PKG_GROUP=$(stat -c %G $RPM_PKG) local __install="install -p -v -o ${RPM_PKG_USER} -g ${RPM_PKG_GROUP}" RPM_PKG_ARCH_LIST="RPMS/i386 RPMS/x86_64 RPMS/ppc RPMS/noarch SRPMS" [ -z "${TARGET}" ] || \ RPM_PKG_ARCH_LIST="RPMS/${TARGET} ${RPM_PKG_ARCH_LIST}" ## make src.rpm for $VERSION /usr/sbin/chroot ${BUILD_ROOT} \ /bin/sh -c "cd ${BUILD_DIR} && su ${BUILD_USER} -c 'rpm -ivh $BASE_RPM_PKG'" /usr/sbin/chroot ${BUILD_ROOT} \ /bin/sh -c "cd ${BUILD_DIR} && su ${BUILD_USER} -c 'rpmbuild -bs --nodeps --clean --rmsource --rmspec ${BUILD_DIR}/SPECS/*.spec'" ## change ${DIST_RELEASE} BASE_RPM_PKG=$(echo $BASE_RPM_PKG | sed -e "s/vl\([0-9]*\)\./vl${DIST_RELEASE}\./") ## rebuild $BASE_RPM_PKG on ${DIST_RELEASE} /usr/sbin/chroot ${BUILD_ROOT} \ /bin/sh -c "cd ${BUILD_DIR}/SRPMS && apt-get -y build-dep $BASE_RPM_PKG" /usr/sbin/chroot ${BUILD_ROOT} \ /bin/sh -c "cd ${BUILD_DIR}/SRPMS && 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|.*\/.*\.src\.rpm||g' -e 's/$/ \\/g')" ## copy built rpms to ${HOME}/rpm/ for each archtectures echo "Copying built rpms to ${HOME}/rpm/ for each archtectures ... " for i in $RPM_PKG_ARCH_LIST; do \ if [ -d $BUILD_ROOT${BUILD_DIR}/${i} ]; then [ -d ${BUILT_RPMS_DIR}/${i} ] || \ $__install -d ${BUILT_RPMS_DIR}/${i}/ find $BUILD_ROOT${BUILD_DIR}/${i} -type f -regex '.*\.rpm' \ -exec $__install -m0644 {} ${BUILT_RPMS_DIR}/${i}/ \; fi done mount_vfs --umount apt-get-update --host echo "done." } ############################################################################## setup-vbuilder [ $# -eq 0 ] && Usage_$LOCALE while [ $# -gt 0 ]; do tmpARG=$1 case $tmpARG in --version|--arch|--target|--build-rpm|--install-rpm|--remove-rpm) shift check-next-parameter $1 || exit 1 ;; --dist-upgrade|--with-compat32|--build|--clean) ;; *) Usage_$LOCALE exit 1 ;; esac case $tmpARG in --version) VERSION=$1 ;; --arch) VARCH=$1 ;; --dist-upgrade) with_dist_upgrade=1 ;; --target) TARGET=$1 RPM_OPTS="${RPM_OPTS} --target $TARGET" ;; --with-compat32) RPM_OPTS="${RPM_OPTS} --with compat32" ;; --build-rpm) RPM_PKG=$1 RPM_Build || exit 1 ;; --install-rpm) RPM_PKG=$1 RPM_Install || exit 1 ;; --remove-rpm) RPM_PKG=$1 RPM_Remove || exit 1 ;; --build) Build ;; --clean) Clean ;; esac shift done exit