summaryrefslogtreecommitdiff
path: root/localcowbuilder-create
blob: 8edf579f7ad4e00858fd87abf3e44464d8373b1b (plain)
  1. #!/bin/sh
  2. #
  3. # Copyright © 2006-2008 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. while [ $# -gt 0 ]; do
  57. case $1 in
  58. -h|--help)
  59. showhelp
  60. exit 0
  61. ;;
  62. --arch|-a)
  63. opts="$opts --debootstrapopts --arch --debootstrapopts $2"
  64. shift 2
  65. ;;
  66. --)
  67. shift
  68. break
  69. ;;
  70. --*|-*)
  71. opts="$opts $1"
  72. shift
  73. ;;
  74. *)
  75. if [ -z "$pool" ]; then
  76. pool="$1"
  77. elif [ -z "$distro" ]; then
  78. distro="$1"
  79. else
  80. othermirrors="$othermirrors --othermirror \"$1\""
  81. fi
  82. shift
  83. ;;
  84. esac
  85. done
  86. if [ -z "$distro" ]; then
  87. distro="$pool"
  88. fi
  89. basepath="/var/cache/pbuilder/cow-$pool"
  90. aptcache=""
  91. buildresult="$HOME/src/pbuild-$pool/"
  92. makepaths=''
  93. for path in "$buildresult"; do
  94. if [ ! -d "$path" ]; then
  95. echo "W: Needed path \"$path\" does not exist"
  96. makepaths='yes'
  97. fi
  98. done
  99. if [ "$makepaths" = 'yes' ]; then
  100. [ "$force" = 'yes' ] \
  101. || ask 'Create the missing path(s)' \
  102. || exit1 "Cannot continue without those missing paths"
  103. mkdir -p "$buildresult"
  104. fi
  105. if [ -d "$basepath" ]; then
  106. echo "W: Needed path \"$path\" already exists"
  107. [ "$force" = 'yes' ] \
  108. || ask 'Remove the path' \
  109. || exit1 "Cannot continue with that path already there"
  110. sudo rm -rf "$basepath"
  111. fi
  112. sudo cowbuilder --create \
  113. --buildresult "$buildresult" \
  114. --distribution "$distro" \
  115. --basepath "$basepath" \
  116. --aptcache "$aptcache" \
  117. $othermirrors \
  118. $opts $@