summaryrefslogtreecommitdiff
path: root/localdebpool
blob: 25dfb3bf5d03dcfab59e33d1f76aac37fae0c1cf (plain)
  1. #!/bin/sh
  2. set -e
  3. ORIGIN="Jones"
  4. LABEL="Jones"
  5. DISTS="etch lenny sid"
  6. ARCHS="i386 powerpc amd64"
  7. PRVBASE=~/public_debian
  8. PUBBASE=~/public_websites/debian.jones.dk
  9. #PUBTOSRC=../../public_debian
  10. debugprint() {
  11. [ -n "$DEBUG" ] || return 0
  12. [ -z "$2" ] || [ "$DEBUG" -lt "$2" ] || return 0
  13. echo 1>&2 "$1"
  14. }
  15. compactlist() {
  16. ( for item in $@; do echo $item; done ) \
  17. | sort -u \
  18. | tr '\n' ' ' \
  19. | sed 's/[[:space:]]\+/ /g; s/^[[:space:]]//; s/[[:space:]]$//'
  20. }
  21. regexfromlist() {
  22. echo $@ | sed 's/[[:space:]]\+/\\|/g; s/^/\\(/; s/$/\\)/'
  23. }
  24. sectionsfromhintstream() {
  25. perl -ne 's/^Sections:\W*// && do { s/\W*,\W*/\n/g; s/\W*$/\n/; print; }'
  26. }
  27. pkginfofromprvpkgdir() {
  28. package="$(basename "$1")"
  29. pool="$(dirname "$1" | sed 's,.*/pool-\([^/]\+\)/\?.*,\1,; s,-all$,,')"
  30. dist="$(echo "$pool" | sed 's,[^a-z].*$,,')"
  31. buildhost="$(echo $(dirname "$@") | sed 's,^\([^/]\+\)/pool-.*,\1,')"
  32. echo "$package $pool $dist $buildhost"
  33. }
  34. archsfromdirs() {
  35. archs="$( \
  36. find "$@" -type l -exec find '{}'/ -type f -name '*.deb' ';' \
  37. | sed 's/^.*_\([a-z0-9-]\+\)\.deb$/\1/; s/\ball\b/'"$ARCHS"'/g' \
  38. )"
  39. archs="$(compactlist $archs)"
  40. debugprint "Archs found: \"$archs\"" "2"
  41. for arch in $archs; do
  42. valid=
  43. for arch_supported in $ARCHS; do
  44. case $arch in
  45. $arch_supported)
  46. debugprint "Arch ok: \"$arch\"" "2"
  47. echo "$arch"
  48. valid=1
  49. ;;
  50. esac
  51. done
  52. if [ -z "$valid" ]; then
  53. # TODO: Optionally just skip
  54. echo 1>&2 "ERROR: Unsupported architecture: \"$arch\"."
  55. exit 1
  56. fi
  57. done
  58. }
  59. distsfromprvgrpdirs() {
  60. dists="$( \
  61. find "$@" -type l -exec find '{}'/ -type f -name '*.deb' ';' \
  62. | sed 's,^.*/sections/[^/]*/\([^/]\+\)/.*$,\1,' \
  63. )"
  64. dists="$(compactlist $dists)"
  65. debugprint "Dists found: \"$dists\"" "2"
  66. for dist in $dists; do
  67. valid=
  68. for dist_supported in $DISTS; do
  69. case $dist in
  70. $dist_supported)
  71. debugprint "Dist ok: \"$dist\"" "2"
  72. echo "$dist"
  73. valid=1
  74. ;;
  75. esac
  76. done
  77. if [ -z "$valid" ]; then
  78. # TODO: Optionally just skip
  79. echo 1>&2 "ERROR: Unsupported distribution: \"$dist\"."
  80. exit 1
  81. fi
  82. done
  83. }
  84. genlist() {
  85. dist="$1"
  86. arch="$2"
  87. srcdir="$3"
  88. basedir="$4"
  89. case "$arch" in
  90. source)
  91. destdir="$basedir/source";
  92. cmd="dpkg-scansources";
  93. file="Sources";
  94. ;;
  95. *)
  96. destdir="$basedir/binary-$arch";
  97. cmd="dpkg-scanpackages -a$arch";
  98. file="Packages";
  99. ;;
  100. esac
  101. mkdir -p "$destdir"
  102. debugprint "genlist: \"$cmd . /dev/null pkg/\"" "2"
  103. ( cd "$srcdir" && $cmd . /dev/null pkg/ ) > "$destdir/$file"
  104. if [ -s "$destdir/$file" ]; then
  105. debugprint "Finalizing list at \"$destdir/\"" "2"
  106. gzip -c "$destdir/$file" > "$destdir/$file.gz"
  107. bzip2 -c "$destdir/$file" > "$destdir/$file.bz2"
  108. cat <<EOF > "$destdir/Release"
  109. Archive: $dist
  110. Component: $section
  111. Origin: $ORIGIN
  112. Label: $LABEL
  113. Architecture: $arch
  114. EOF
  115. else
  116. debugprint "purge empty list at \"$destdir/\"" "2"
  117. rm -f "$destdir/$file" "$destdir/$file.gz" "$destdir/$file.bz2" "$destdir/Release"
  118. rmdir -p --ignore-fail-on-non-empty "$destdir"
  119. fi
  120. }
  121. genrelease() {
  122. dist="$1"
  123. shift
  124. sections="$@"
  125. archs="$(archsfromdirs "$PRVBASE/sections"/*/"$dist")"
  126. archs="$(compactlist $archs)"
  127. case "$dist" in
  128. etch) suite="stable";;
  129. lenny) suite="testing";;
  130. sid) suite="unstable";;
  131. esac
  132. cat <<EOF > "$PUBBASE/dists/$dist/Release"
  133. Origin: $ORIGIN
  134. Label: $LABEL
  135. Suite: $suite
  136. Codename: $dist
  137. Architectures: $archs
  138. Components: $sections
  139. EOF
  140. }
  141. packages="$@"
  142. packages="$(compactlist $packages)"
  143. debugprint "Packages: \"$packages\""
  144. case "$packages" in
  145. -a|--all)
  146. pkg_re=".*"
  147. ;;
  148. "")
  149. echo 1>&2 "ERROR: No package(s) provided."
  150. exit 1
  151. ;;
  152. *)
  153. pkg_re="\b$(regexfromlist $packages)\b"
  154. ;;
  155. esac
  156. batchsections="$( \
  157. find "$PRVBASE" -type f -regex '.*/'"$pkg_re"'/HINTS' -exec cat '{}' ';' \
  158. | sectionsfromhintstream
  159. )"
  160. batchsections="$(compactlist $batchsections)"
  161. debugprint "Sections in batch: \"$batchsections\""
  162. batchsections_re=
  163. if [ -n "$batchsections" ]; then
  164. batchsections_re="\b$(regexfromlist $batchsections)\b"
  165. else
  166. echo 1>&2 "ERROR: Package(s) $@ was not found in any section."
  167. exit 1
  168. fi
  169. # Find packages in $prvpkgdir belonging to $sections, and
  170. # create/update symlink farms $prvgrpdir and $pubpkgdir.
  171. #
  172. # $PRVBASE/$buildhost/pool-$pool/$package/
  173. # $PRVBASE/sections/$section/$dist/$package/$pool/$buildhost
  174. # $PUBBASE/pkg/$package/$pool/$buildhost
  175. #
  176. cd "$PRVBASE" && find * -type f -name HINTS -exec grep -q "^Sections:.*$batchsections_re" '{}' ';' -printf '%h\n' \
  177. | while read prvpkgdir; do
  178. debugprint "prvpkgdir: \"$prvpkgdir\""
  179. set -- $(pkginfofromprvpkgdir "$prvpkgdir")
  180. package="$1" pool="$2" dist="$3" buildhost="$4"
  181. shift 4
  182. pkgsections="$(cat "$PRVBASE/$prvpkgdir/HINTS" | sectionsfromhintstream)"
  183. pkgsections="$(compactlist $pkgsections)"
  184. subdir="$package/$pool"
  185. mkdir -p "$PUBBASE/pkg/$subdir"
  186. ln -sf -T "$PRVBASE/$prvpkgdir" "$PUBBASE/pkg/$subdir/$buildhost"
  187. for section in $pkgsections; do
  188. mkdir -p "$PRVBASE/sections/$section/$dist/$subdir"
  189. ln -sf -T "../../../../../$prvpkgdir" "$PRVBASE/sections/$section/$dist/$subdir/$buildhost"
  190. done
  191. done
  192. # Create/update package lists
  193. #
  194. # $PUBBASE/dists/$dist/$section/{binary-$arch,source}
  195. #
  196. for section in $batchsections; do
  197. dists="$(distsfromprvgrpdirs "$PRVBASE/sections/$section")"
  198. for dist in $dists; do
  199. debugprint "genlists \"\$PRVBASE/sections/$section/$dist\" -> \"\$PUBBASE/dists/$dist/$section\""
  200. prvgrpdir="$PRVBASE/sections/$section/$dist"
  201. pubpkgdir="$PUBBASE/dists/$dist/$section"
  202. archs="$(archsfromdirs "$prvgrpdir")"
  203. for arch in $archs; do
  204. genlist "$dist" "$arch" "$prvgrpdir" "$pubpkgdir"
  205. done
  206. [ -z "$archs" ] || genlist "$dist" "source" "$prvgrpdir" "$pubpkgdir"
  207. done
  208. done
  209. # Create/update Release files
  210. #
  211. # $PUBBASE/dists/$dist/Release
  212. #
  213. allsections="$( \
  214. find "$PRVBASE" -type f -name HINTS -exec cat '{}' ';' \
  215. | sectionsfromhintstream
  216. )"
  217. allsections="$(compactlist $allsections)"
  218. debugprint "All sections: \"$allsections\""
  219. dists="$(distsfromprvgrpdirs "$PRVBASE/sections")"
  220. dists="$(compactlist $dists)"
  221. for dist in $dists; do
  222. genrelease "$dist" ${allsections}
  223. done
  224. exit 0