summaryrefslogtreecommitdiff
path: root/localcowbuilder-create
blob: e6eb030c4d3e2bdbff0a19c5302b44e78111e289 (plain)
  1. #!/bin/sh
  2. set -e
  3. PRG=$(basename "$0")
  4. showhelp() {
  5. cat <<EOF
  6. Usage: $PRG POOL [ DISTRIBUTION [ OTHERMIRROR] ]
  7. Examples:
  8. $PRG sid
  9. $PRG sid+mm sid 'deb http://debian-multimedia.org/ sid main'
  10. $PRG sid-ia32 sid --arch i386
  11. EOF
  12. }
  13. exit1() {
  14. echo "ERROR: $1"
  15. exit 1
  16. }
  17. ask() {
  18. echo -n "$1 (y/N)? "
  19. read response
  20. case "$response" in
  21. y|Y)
  22. :
  23. ;;
  24. *)
  25. return 1
  26. ;;
  27. esac
  28. return
  29. }
  30. if [ $# -eq 0 ]; then
  31. showhelp
  32. exit1 "not enough parameters"
  33. fi
  34. pool=
  35. distro=
  36. while [ $# -gt 0 ]; do
  37. case $1 in
  38. -h|--help)
  39. showhelp
  40. exit 0
  41. ;;
  42. --arch|-a)
  43. opts="$opts --debootstrapopts --arch --debootstrapopts $2"
  44. shift 2
  45. ;;
  46. --*|-*)
  47. opts="$opts $1"
  48. shift
  49. ;;
  50. --)
  51. shift
  52. break
  53. ;;
  54. *)
  55. if [ -z "$pool" ]; then
  56. pool="$1"
  57. elif [ -z "$distro" ]; then
  58. distro="$1"
  59. else
  60. othermirrors="$othermirrors --othermirror \"$1\""
  61. fi
  62. shift
  63. ;;
  64. esac
  65. done
  66. if [ -z "$distro" ]; then
  67. distro="$pool"
  68. fi
  69. basepath="/var/cache/pbuilder/cow-$pool"
  70. aptcache="/var/cache/pbuilder/aptcache-$pool/"
  71. buildresult="$HOME/src/pbuild-$pool/"
  72. makepaths=''
  73. for path in "$aptcache" "$buildresult"; do
  74. if [ ! -d "$path" ]; then
  75. echo "W: Needed path \"$path\" does not exist"
  76. makepaths='yes'
  77. fi
  78. done
  79. if [ "$makepaths" = 'yes' ]; then
  80. [ "$force" = 'yes' ] \
  81. || ask 'Create the missing path(s)' \
  82. || exit1 "Cannot continue without those missing paths"
  83. mkdir -p "$buildresult"
  84. sudo mkdir -p "$aptcache"
  85. fi
  86. if [ -d "$basepath" ]; then
  87. echo "W: Needed path \"$path\" already exists"
  88. [ "$force" = 'yes' ] \
  89. || ask 'Remove the path' \
  90. || exit1 "Cannot continue with that path already there"
  91. sudo rm -rf "$basepath"
  92. fi
  93. sudo cowbuilder --create \
  94. --buildresult "$buildresult" \
  95. --distribution "$distro" \
  96. --basepath "$basepath" \
  97. --aptcache "$aptcache" \
  98. $othermirrors \
  99. $opts $@