summaryrefslogtreecommitdiff
path: root/localcowbuilder-create
blob: f64e0950ec317703b5de13b37024382f622359e6 (plain)
  1. #!/bin/sh
  2. #
  3. # Copyright © 2006-2011 Jonas Smedegaard <dr@jones.dk>
  4. # Description: Create Copy-On-Write environment
  5. #
  6. # This program is free software; you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation; either version 2, or (at your option)
  9. # any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful, but
  12. # WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. # General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program; if not, write to the Free Software
  18. # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  19. # 02111-1307 USA.
  20. #
  21. # Depends: cowdancer, sudo
  22. set -e
  23. PRG=$(basename "$0")
  24. showhelp() {
  25. cat <<EOF
  26. Usage: $PRG POOL [ DISTRIBUTION [ OTHERMIRROR ... ] ]
  27. Examples:
  28. $PRG sid
  29. $PRG sid+mm sid 'deb http://debian-multimedia.org/ sid main'
  30. $PRG sid-ia32 sid --arch i386
  31. EOF
  32. }
  33. exit1() {
  34. echo "ERROR: $1"
  35. exit 1
  36. }
  37. ask() {
  38. echo -n "$1 (y/N)? "
  39. read response
  40. case "$response" in
  41. y|Y)
  42. :
  43. ;;
  44. *)
  45. return 1
  46. ;;
  47. esac
  48. return
  49. }
  50. if [ $# -eq 0 ]; then
  51. showhelp
  52. exit1 "not enough parameters"
  53. fi
  54. pool=
  55. distro=
  56. arch=
  57. newline='
  58. '
  59. while [ $# -gt 0 ]; do
  60. case $1 in
  61. -h|--help)
  62. showhelp
  63. exit 0
  64. ;;
  65. --arch|-a)
  66. arch="$2"
  67. shift 2 || exit1 "option \"--arg\" requires an argument"
  68. ;;
  69. --)
  70. shift
  71. break
  72. ;;
  73. --*|-*)
  74. exit1 "options (apart from --arch) are curently unsupported"
  75. ;;
  76. *)
  77. if [ -z "$pool" ]; then
  78. pool="$1"
  79. elif [ -z "$distro" ]; then
  80. distro="$1"
  81. else
  82. othermirrors="${othermirrors:+$othermirrors$newline}$1"
  83. fi
  84. shift
  85. ;;
  86. esac
  87. done
  88. if [ -z "$pool" ]; then
  89. exit1 "no pool provided"
  90. fi
  91. if [ -z "$distro" ]; then
  92. distro="$pool"
  93. fi
  94. basepath="/var/cache/pbuilder/cow-$pool"
  95. aptcache=""
  96. buildresult="$HOME/src/pbuild-$pool/"
  97. makepaths=''
  98. for path in "$buildresult"; do
  99. if [ ! -d "$path" ]; then
  100. echo "W: Needed path \"$path\" does not exist"
  101. makepaths='yes'
  102. fi
  103. done
  104. if [ "$makepaths" = 'yes' ]; then
  105. [ "$force" = 'yes' ] \
  106. || ask 'Create the missing path(s)' \
  107. || exit1 "Cannot continue without those missing paths"
  108. mkdir -p "$buildresult"
  109. fi
  110. if [ -d "$basepath" ]; then
  111. echo "W: Needed path \"$basepath\" already exists"
  112. [ "$force" = 'yes' ] \
  113. || ask 'Remove the path' \
  114. || exit1 "Cannot continue with that path already there"
  115. sudo rm -rf "$basepath"
  116. fi
  117. if [ -n "$arch" ]; then
  118. echo "$othermirrors" | perl -e "while (<>) {/\w/ and unshift @m, '--othermirror', \$_};"\
  119. "exec 'sudo', 'cowbuilder', '--create', '--buildresult', '$buildresult', '--distribution', '$distro', '--basepath', '$basepath', '--aptcache', '$aptcache', '--debootstrapopts', '--arch', '--debootstrapopts', '$arch', @m"
  120. else
  121. echo "$othermirrors" | perl -e "while (<>) {/\w/ and unshift @m, '--othermirror', \$_};"\
  122. "exec 'sudo', 'cowbuilder', '--create', '--buildresult', '$buildresult', '--distribution', '$distro', '--basepath', '$basepath', '--aptcache', '$aptcache', @m"
  123. fi