summaryrefslogtreecommitdiff
path: root/localpbuilder-create
blob: cde3a926533e287ea1374c44d37d97d66aebf557 (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. basetgz="/var/cache/pbuilder/base-$pool.tgz"
  70. buildplace="/var/cache/pbuilder/build-$pool/"
  71. aptcache="/var/cache/pbuilder/aptcache-$pool/"
  72. buildresult="$HOME/src/pbuild-$pool/"
  73. makepaths=''
  74. for path in "$aptcache" "$buildresult"; do
  75. if [ ! -d "$path" ]; then
  76. echo "W: Needed path \"$path\" does not exist"
  77. makepaths='yes'
  78. fi
  79. done
  80. if [ "$makepaths" = 'yes' ]; then
  81. [ "$force" = 'yes' ] \
  82. || ask 'Create the missing path(s)' \
  83. || exit1 "Cannot continue without those missing paths"
  84. mkdir -p "$buildresult"
  85. sudo mkdir -p "$aptcache"
  86. fi
  87. sudo pbuilder create \
  88. --buildresult "$buildresult" \
  89. --distribution "$distro" \
  90. --basetgz "$basetgz" \
  91. --buildplace "$buildplace" \
  92. --aptcache "$aptcache" \
  93. $othermirrors \
  94. $opts $@