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.

105 lines
2.9KB

  1. #!/bin/bash
  2. set -e
  3. GET_URL=http://getchroot.osuv.de
  4. _CHROOT=~/.getchroot
  5. function build_chroot {
  6. mkdir -p $_CHROOT/
  7. # /run is needed because it's missed in the squeeze image.
  8. mkdir -p $2/run
  9. if [ -f $_CHROOT/$1.tar.xz ]; then
  10. tar -C $2 -xf $_CHROOT/$1.tar.xz 2> /dev/null
  11. else
  12. wget -P $_CHROOT/ $GET_URL/$1.tar.xz
  13. tar -C $2 -xf $_CHROOT/$1.tar.xz 2> /dev/null
  14. fi
  15. # copy resolv.conf from host into chroot
  16. cp /etc/resolv.conf $2/etc/resolv.conf
  17. }
  18. function update_chroot {
  19. current=$(cat <(curl -s $GET_URL/$1.md5sum))
  20. exist=$(md5sum $_CHROOT/$1.tar.xz|awk '{print$1}')
  21. if [[ "$current" = "$exist" ]]; then
  22. printf "No update for %s available\n" "$1"
  23. else
  24. rm $_CHROOT/$1.tar.xz
  25. wget -P $_CHROOT/ $GET_URL/$1.tar.xz
  26. fi
  27. }
  28. function print_help {
  29. echo "
  30. ./getchroot [option] <folder>
  31. [option]:
  32. arch:...............Arch Linux
  33. *squeeze:............Debian 6 Squeeze
  34. *wheezy:.............Debian 7 Wheezy
  35. sid:................Debian Unstable
  36. precise:............Ubuntu LTS 12.04, Precise Pangolin
  37. trusty:.............Ubuntu LTS 14.04, Trusty Tahr
  38. xenial:.............Ubuntu LTS 16.04, Xenial Xerus
  39. *fedora19:...........Fedora 19, Schrödinger's cat
  40. *fedora20:...........Fedora 20, Heisenbug
  41. *archbsd:............ArchBSD
  42. centos5:............CentOS 5.10
  43. centos6:............CentOS 6.7
  44. centos7:............CentOS 7.2
  45. * currently not available
  46. This will download a prepared tar.xz file to $_CHROOT and extract to your given folder
  47. ./getchroot update [option]
  48. This will compare and download a prepared tar.xz file to $_CHROOT for later usage
  49. EXAMPLES
  50. :~$ ./getchroot arch mychrootarch/
  51. This will download arch.tar.xz to $_CHROOT if not available and extract it to mychrootarch/
  52. :~$ ./getchroot update arch
  53. This will compare your local arch.tar.xz container file with the online version. If they are different, it will be downloaded again.
  54. Then do
  55. :~$ ./getchroot arch mychrootarch/
  56. to update to the latest container.
  57. "
  58. }
  59. if (("$#" == 2)); then
  60. case "$1" in
  61. "arch") build_chroot $1 $2 ;;
  62. "wheezy") build_chroot $1 $2 ;;
  63. "sid") build_chroot $1 $2 ;;
  64. "precise") build_chroot $1 $2 ;;
  65. "trusty") build_chroot $1 $2 ;;
  66. "xenial") build_chroot $1 $2 ;;
  67. "fedora19") build_chroot $1 $2 ;;
  68. "fedora20") build_chroot $1 $2 ;;
  69. "squeeze") build_chroot $1 $2 ;;
  70. "archbsd") build_chroot $1 $2 ;;
  71. "centos5") build_chroot $1 $2 ;;
  72. "centos6") build_chroot $1 $2 ;;
  73. "centos7") build_chroot $1 $2 ;;
  74. "update") update_chroot $2 ;;
  75. *) echo -e "unknown option\n" ;;
  76. esac
  77. else
  78. printf "Wrong usage!\n\n"
  79. print_help
  80. exit
  81. fi