summaryrefslogtreecommitdiff
path: root/localpbuilder-create
blob: 5287f524e2bd893998fd9daaec7522de28c95721 (plain)
  1. #!/bin/sh
  2. #
  3. # Copyright © 2005-2008 Jonas Smedegaard <dr@jones.dk>
  4. # Description: Create pbuilder 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: pbuilder, 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. opts="$opts $1"
  68. shift
  69. ;;
  70. --)
  71. shift
  72. break
  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. basetgz="/var/cache/pbuilder/base-$pool.tgz"
  90. buildplace="/var/cache/pbuilder/build-$pool/"
  91. aptcache="/var/cache/pbuilder/aptcache-$pool/"
  92. buildresult="$HOME/src/pbuild-$pool/"
  93. makepaths=''
  94. for path in "$aptcache" "$buildresult"; do
  95. if [ ! -d "$path" ]; then
  96. echo "W: Needed path \"$path\" does not exist"
  97. makepaths='yes'
  98. fi
  99. done
  100. if [ "$makepaths" = 'yes' ]; then
  101. [ "$force" = 'yes' ] \
  102. || ask 'Create the missing path(s)' \
  103. || exit1 "Cannot continue without those missing paths"
  104. mkdir -p "$buildresult"
  105. sudo mkdir -p "$aptcache"
  106. fi
  107. sudo pbuilder create \
  108. --buildresult "$buildresult" \
  109. --distribution "$distro" \
  110. --basetgz "$basetgz" \
  111. --buildplace "$buildplace" \
  112. --aptcache "$aptcache" \
  113. $othermirrors \
  114. $opts $@