summaryrefslogtreecommitdiff
path: root/localcowbuilder-fork
blob: b248925d4428ad0dadface6ba5f54c0958cf8e09 (plain)
  1. #!/bin/sh
  2. set -x
  3. #
  4. # Copyright © 2006-2008 Jonas Smedegaard <dr@jones.dk>
  5. # Description: Update Copy-On-Write environment
  6. #
  7. # This program is free software; you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation; either version 2, or (at your option)
  10. # any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful, but
  13. # WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. # General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with this program; if not, write to the Free Software
  19. # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  20. # 02111-1307 USA.
  21. #
  22. # Depends: cowdancer, sudo
  23. set -e
  24. PRG=$(basename "$0")
  25. LOCALMIRROR="deb http://proxy:9999/jones @@DIST@@ @@TOPIC@@"
  26. showhelp() {
  27. cat <<EOF
  28. Usage: $PRG OLDPOOL POOL DISTRIBUTION [ OTHERMIRROR | LOCALTOPIC ]
  29. Examples:
  30. $PRG sid sid-copy sid
  31. $PRG sid sid+mm sid 'deb http://debian-multimedia.org/ sid main'
  32. $PRG sid-ia32 sid-ia32+tweaks sid tweaks
  33. OTHERMIRROR is a full APT line, LOCALTOPIC is expanded using the
  34. following skeleton:
  35. $LOCALMIRROR
  36. All APT sources are replaced: all original sources must be redeclared.
  37. EOF
  38. }
  39. exit1() {
  40. echo "ERROR: $1"
  41. exit 1
  42. }
  43. ask() {
  44. echo -n "$1 (y/N)? "
  45. read response
  46. case "$response" in
  47. y|Y)
  48. :
  49. ;;
  50. *)
  51. return 1
  52. ;;
  53. esac
  54. return
  55. }
  56. if [ $# -lt 3 ]; then
  57. showhelp
  58. exit1 "not enough parameters"
  59. fi
  60. oldpool=
  61. pool=
  62. distro=
  63. while [ $# -gt 0 ]; do
  64. case $1 in
  65. -h|--help)
  66. showhelp
  67. exit 0
  68. ;;
  69. --)
  70. shift
  71. break
  72. ;;
  73. --*|-*)
  74. # opts="$opts $1"
  75. # shift
  76. exit1 "options are curently unsupported"
  77. ;;
  78. *)
  79. if [ -z "$oldpool" ]; then
  80. oldpool="$1"
  81. elif [ -z "$pool" ]; then
  82. pool="$1"
  83. elif [ -z "$distro" ]; then
  84. distro="$1"
  85. else
  86. if echo "$1" | egrep -vq '[^[:blank:]][[:blank:]]+[^[:blank:]]'; then
  87. mirror="$(echo "$LOCALMIRROR" | sed "s/@@DIST@@/$distro/g;s/@@TOPIC@@/$1/g")"
  88. else
  89. mirror="$1"
  90. fi
  91. othermirrors="${othermirrors:+$othermirrors|}""$mirror"
  92. fi
  93. shift
  94. ;;
  95. esac
  96. done
  97. if [ -z "$oldpool" ]; then
  98. exit1 "no oldpool provided"
  99. fi
  100. if [ -z "$pool" ]; then
  101. exit1 "no pool provided"
  102. fi
  103. if [ -z "$distro" ]; then
  104. exit1 "no distribution provided"
  105. fi
  106. oldbasepath="/var/cache/pbuilder/cow-$oldpool"
  107. basepath="/var/cache/pbuilder/cow-$pool"
  108. aptcache=""
  109. buildresult="$HOME/src/pbuild-$pool/"
  110. [ -d "$oldbasepath" ] || \
  111. exit1 "oldpool \"$oldbasepath\" does not exist"
  112. makepaths=''
  113. for path in "$buildresult"; do
  114. if [ ! -d "$path" ]; then
  115. echo "W: Needed path \"$path\" does not exist"
  116. makepaths='yes'
  117. fi
  118. done
  119. if [ "$makepaths" = 'yes' ]; then
  120. [ "$force" = 'yes' ] \
  121. || ask 'Create the missing path(s)' \
  122. || exit1 "Cannot continue without those missing paths"
  123. fi
  124. if [ -d "$basepath" ]; then
  125. echo "W: Needed path \"$path\" already exists"
  126. [ "$force" = 'yes' ] \
  127. || ask 'Remove the path' \
  128. || exit1 "Cannot continue with that path already there"
  129. fi
  130. mkdir -p "$buildresult"
  131. sudo rm -rf "$basepath"
  132. sudo cp -al "$oldbasepath" "$basepath"
  133. export DEBIAN_FRONTEND="noninteractive"
  134. export LANG=C
  135. echo "$othermirrors" | perl -e "while (<>) {chomp; /\w/ and unshift @m, '--othermirror', \$_};"\
  136. "exec 'sudo', 'cowbuilder', '--update', '--distribution', '$distro', '--basepath', '$basepath', '--aptcache', '$aptcache', '--override-config', @m"