123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- #!/bin/bash
- # -*- coding: utf-8-unix -*-
- TEXTDOMAIN=vbootstrap
- TEXTDOMAINDIR=/usr/share/locale
- trap clean-vchroot EXIT
- Usage(){
- cat<<EOF
- Usage: $(basename $0) [OPTION...] [COMMAND] - run command or shell in a chroot
- Options:
- --chroot: use specified chroot [version] (default: ${DEFAULT_VERSION})
- $(/usr/sbin/vbootstrap | sed -e s/^Usage:.*// -e s/^E:.*//)
- EOF
- }
- ##############################################################################
- . /usr/share/vbootstrap/libvbuilder.sh
- check-parameter(){
- [ -z "$*" ] && Usage && return 1
- while [ ! -z "$*" ]; do
- case $1 in
- --help|help)
- Usage
- return 1
- ;;
- --chroot)
- shift
- check-next-parameter $1 || return 1
- ;;
- esac
- shift
- done
- 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
- }
- clean-vchroot(){
- # mount-chroot --umount /home
- mount-chroot --umount /tmp
- mount-chroot --umount vfs
- mount-chroot --umount archives_dir
- apt-get-update --host
- return 0
- }
- main(){
- 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 archives_dir
- mount-chroot vfs
- 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
- [ ! -f ${BUILD_ROOT}/etc/${i}.orig ] && \
- cp -pf ${BUILD_ROOT}/etc/${i} ${BUILD_ROOT}/etc/${i}.orig && \
- cp -pf /etc/${i} ${BUILD_ROOT}/etc
- done
- cp -Ppf /etc/localtime ${BUILD_ROOT}/etc
- $__chroot $* || return 1
-
- return 0
- }
- ##############################################################################
- # setup-vchroot || exit 1
- setup-vbuilder || exit 1
- check-parameter $* || exit 1
- while [ $# -gt 0 ]; do
- tmpARG=$1
- case $tmpARG in
- --chroot|-c)
- shift
- ;;
- *)
- break
- ;;
- esac
- case $tmpARG in
- --chroot|-c)
- VERSION=$1
- ;;
- esac
- shift
- done
- main $* || exit 1
- exit
|