vchroot.sh.in 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. #!/bin/bash
  2. # -*- coding: utf-8-unix -*-
  3. TEXTDOMAIN=vbootstrap
  4. TEXTDOMAINDIR=/usr/share/locale
  5. trap clean-vchroot EXIT
  6. Usage(){
  7. cat<<EOF
  8. Usage: $(basename $0) [OPTION...] [COMMAND] - run command or shell in a chroot
  9. Options:
  10. --chroot: use specified chroot [version] (default: ${DEFAULT_VERSION})
  11. $(/usr/sbin/vbootstrap | sed -e s/^Usage:.*// -e s/^E:.*//)
  12. EOF
  13. }
  14. ##############################################################################
  15. . /usr/share/vbootstrap/libvbuilder.sh
  16. check-parameter(){
  17. [ -z "$*" ] && Usage && return 1
  18. while [ ! -z "$*" ]; do
  19. case $1 in
  20. --help|help)
  21. Usage
  22. return 1
  23. ;;
  24. --chroot)
  25. shift
  26. check-next-parameter $1 || return 1
  27. ;;
  28. esac
  29. shift
  30. done
  31. return 0
  32. }
  33. check-next-parameter(){
  34. [ -z "$1" ] && echo $"E: Missing some parameters after $1" && return 1
  35. [ $(echo $1 | grep '^-') ] && \
  36. echo $"E: Missing some parameters after $1" && return 1
  37. return 0
  38. }
  39. clean-vchroot(){
  40. # mount-chroot --umount /home
  41. mount-chroot --umount /tmp
  42. mount-chroot --umount vfs
  43. mount-chroot --umount archives_dir
  44. apt-get-update --host
  45. return 0
  46. }
  47. main(){
  48. setup-vbootstrap || return 1
  49. __chroot="/usr/sbin/chroot ${BUILD_ROOT}"
  50. ## setarch ix86 if ix86 chroot on x86_64 host
  51. [ $with_ix86_on_x86_64 -eq 1 ] && \
  52. __chroot="/usr/sbin/chroot ${BUILD_ROOT} setarch ${VARCH}"
  53. mount-chroot archives_dir
  54. mount-chroot vfs
  55. mount-chroot /tmp
  56. # mount-chroot /home
  57. apt-get-update --chroot
  58. ## copy host's configurations of /etc
  59. #passwd shadow group gshadow
  60. for i in resolv.conf hosts; do
  61. [ ! -f ${BUILD_ROOT}/etc/${i}.orig ] && \
  62. cp -pf ${BUILD_ROOT}/etc/${i} ${BUILD_ROOT}/etc/${i}.orig && \
  63. cp -pf /etc/${i} ${BUILD_ROOT}/etc
  64. done
  65. cp -Ppf /etc/localtime ${BUILD_ROOT}/etc
  66. $__chroot $* || return 1
  67. return 0
  68. }
  69. ##############################################################################
  70. # setup-vchroot || exit 1
  71. setup-vbuilder || exit 1
  72. check-parameter $* || exit 1
  73. while [ $# -gt 0 ]; do
  74. tmpARG=$1
  75. case $tmpARG in
  76. --chroot|-c)
  77. shift
  78. ;;
  79. *)
  80. break
  81. ;;
  82. esac
  83. case $tmpARG in
  84. --chroot|-c)
  85. VERSION=$1
  86. ;;
  87. esac
  88. shift
  89. done
  90. main $* || exit 1
  91. exit