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