summaryrefslogtreecommitdiff
path: root/localcowbuilder-create
blob: 14495d390893a2fddaab6bac9751e06f7c8013e4 (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=$1
  34. distro=${2:-$pool}
  35. basepath="/var/cache/pbuilder/cow-$pool"
  36. aptcache="/var/cache/pbuilder/aptcache-$pool/"
  37. buildresult="$HOME/src/pbuild-$pool/"
  38. makepaths=''
  39. for path in "$aptcache" "$buildresult"; do
  40. if [ ! -d "$path" ]; then
  41. echo "W: Needed path \"$path\" does not exist"
  42. makepaths='yes'
  43. fi
  44. done
  45. if [ "$makepaths" = 'yes' ]; then
  46. [ "$force" = 'yes' ] \
  47. || ask 'Create the missing path(s)' \
  48. || exit1 "Cannot continue without those missing paths"
  49. mkdir -p "$buildresult"
  50. sudo mkdir -p "$aptcache"
  51. fi
  52. if [ -d "$basepath" ]; then
  53. echo "W: Needed path \"$path\" already exists"
  54. [ "$force" = 'yes' ] \
  55. || ask 'Remove the path' \
  56. || exit1 "Cannot continue with that path already there"
  57. sudo rm -rf "$basepath"
  58. fi
  59. sudo cowbuilder --create \
  60. --buildresult "$buildresult" \
  61. --distribution "$distro" \
  62. --basepath "$basepath" \
  63. --aptcache "$aptcache" \
  64. ${3:+--othermirror "$3"}