Chroot-tools
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

140 lines
3.9KB

  1. #!/bin/bash
  2. set -e
  3. print_help(){
  4. echo '
  5. createchroot <folder>
  6. createchroot [TYPE] <folder>
  7. [TYPE]: host (root/non-root), wheezy (root/non-root), sid (root/non-root), precise (root/non-root), raring (root/non-root), arch (root)
  8. ~$: createchroot host ~/host-clone
  9. This creates instantly a chroot clone of the Host system using facadefs. 'superchroot ~/host-clone/root' have to be used.
  10. To umount, run 'fusermount -u ~/host-clone/root'.
  11. '
  12. }
  13. function make_debian(){
  14. fakeroot fakechroot debootstrap $linux $folder http://cdn.debian.net/debian/
  15. }
  16. function make_ubuntu(){
  17. fakeroot fakechroot debootstrap --variant=minbase $linux $folder http://archive.ubuntu.com/ubuntu
  18. }
  19. function sudo_make_debian(){
  20. debootstrap $linux $folder http://cdn.debian.net/debian/
  21. }
  22. function sudo_make_ubuntu(){
  23. debootstrap --variant=minbase $linux $folder http://archive.ubuntu.com/ubuntu
  24. }
  25. function sudo_make_arch(){
  26. pacstrap -dGM $folder
  27. }
  28. function make_hostclone(){
  29. mkdir -p $folder/{root,cache}
  30. if which facadefs >/dev/null; then
  31. facadefs / $folder/cache $folder/root/ -o allow_root
  32. printf "Host-Clone created, please run 'superchroot $folder/root/'\n"
  33. else
  34. printf "Error, can't find facadefs.\n"
  35. fi
  36. }
  37. if (("$#" == 1)); then
  38. if [ "$UID" -ne 0 ]; then
  39. # user + debian-based
  40. linux=$(lsb_release -c|awk {'print $2'})
  41. folder=$1
  42. case "$linux" in
  43. "wheezy") make_debian $linux $folder ;;
  44. "sid") make_debian $linux $folder ;;
  45. "precise") make_ubuntu $linux $folder ;;
  46. "raring") make_ubuntu $linux $folder ;;
  47. "--help") print_help ;;
  48. *) print_help ;;
  49. esac
  50. else
  51. folder=$1
  52. if which pacstrap >/dev/null; then
  53. sudo_make_arch $folder
  54. elif which debootstrap >/dev/null; then
  55. linux=$(lsb_release -c|awk {'print $2'})
  56. case "$linux" in
  57. "wheezy") sudo_make_debian $linux $folder ;;
  58. "sid") sudo_make_debian $linux $folder ;;
  59. "precise") sudo_make_ubuntu $linux $folder ;;
  60. "raring") sudo_make_ubuntu $linux $folder ;;
  61. "--help") print_help ;;
  62. *) print_help ;;
  63. esac
  64. elif which yum >/dev/null; then
  65. printf "currently commented out, because it need a / directory\n"
  66. # mkdir -p $1/devel/var/lib/rpm
  67. # rpm --root $1/devel --initdb
  68. # yumdownloader --destdir=/tmp fedora-release
  69. # rpm --root $1/devel -ivh /tmp/fedora-release*rpm
  70. # yum --installroot=$1/devel install bash yum
  71. # yum --installroot=$1/devel groupinstall "minimal install"
  72. else
  73. printf "Unexpected error!\n\n"
  74. print_help
  75. fi
  76. fi
  77. elif (("$#" == 2)); then
  78. linux=$1
  79. folder=$2
  80. if [ "$UID" -ne 0 ]; then
  81. case "$linux" in
  82. "wheezy") make_debian $linux $folder ;;
  83. "sid") make_debian $linux $folder ;;
  84. "precise") make_ubuntu $linux $folder ;;
  85. "raring") make_ubuntu $linux $folder ;;
  86. "host") make_hostclone $folder ;;
  87. *) print_help ;;
  88. esac
  89. else
  90. case "$linux" in
  91. "wheezy") sudo_make_debian $linux $folder ;;
  92. "sid") sudo_make_debian $linux $folder ;;
  93. "precise") sudo_make_ubuntu $linux $folder ;;
  94. "raring") sudo_make_ubuntu $linux $folder ;;
  95. "arch") sudo_make_arch $folder ;;
  96. "host") make_hostclone $folder ;;
  97. *) print_help ;;
  98. esac
  99. fi
  100. else
  101. print_help
  102. fi