summaryrefslogtreecommitdiff
path: root/localdebpool
blob: 45ddcfcc5b188ffae843883d199c81d6ca8a6471 (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. # Find packages in $prvpkgdir belonging to $sections
  157. #
  158. # $PRVBASE/$buildhost/pool-$pool/$package/
  159. #
  160. batchsections="$( \
  161. find "$PRVBASE" -type f -regex '.*/'"$pkg_re"'/HINTS' -exec cat '{}' ';' \
  162. | sectionsfromhintstream
  163. )"
  164. batchsections="$(compactlist $batchsections)"
  165. debugprint "Sections in batch: \"$batchsections\""
  166. batchsections_re=
  167. if [ -n "$batchsections" ]; then
  168. batchsections_re="\b$(regexfromlist $batchsections)\b"
  169. else
  170. echo 1>&2 "ERROR: Package(s) $@ was not found in any section."
  171. exit 1
  172. fi
  173. # Create/update symlink farms $prvgrpdir and $pubpkgdir
  174. #
  175. # $PRVBASE/sections/$section/$dist/$package/$pool/$buildhost
  176. # $PUBBASE/pkg/$package/$pool/$buildhost
  177. #
  178. cd "$PRVBASE" && find * -type f -name HINTS -exec grep -q "^Sections:.*$batchsections_re" '{}' ';' -printf '%h\n' \
  179. | while read prvpkgdir; do
  180. debugprint "prvpkgdir: \"$prvpkgdir\""
  181. set -- $(pkginfofromprvpkgdir "$prvpkgdir")
  182. package="$1" pool="$2" dist="$3" buildhost="$4"
  183. shift 4
  184. pkgsections="$(cat "$PRVBASE/$prvpkgdir/HINTS" | sectionsfromhintstream)"
  185. pkgsections="$(compactlist $pkgsections)"
  186. subdir="$package/$pool"
  187. mkdir -p "$PUBBASE/pkg/$subdir"
  188. ln -sf -T "$PRVBASE/$prvpkgdir" "$PUBBASE/pkg/$subdir/$buildhost"
  189. for section in $pkgsections; do
  190. mkdir -p "$PRVBASE/sections/$section/$dist/$subdir"
  191. ln -sf -T "../../../../../$prvpkgdir" "$PRVBASE/sections/$section/$dist/$subdir/$buildhost"
  192. done
  193. done
  194. # Create/update package lists
  195. #
  196. # $PUBBASE/dists/$dist/$section/{binary-$arch,source}
  197. #
  198. for section in $batchsections; do
  199. dists="$(distsfromprvgrpdirs "$PRVBASE/sections/$section")"
  200. for dist in $dists; do
  201. debugprint "genlists \"\$PRVBASE/sections/$section/$dist\" -> \"\$PUBBASE/dists/$dist/$section\""
  202. prvgrpdir="$PRVBASE/sections/$section/$dist"
  203. pubpkgdir="$PUBBASE/dists/$dist/$section"
  204. archs="$(archsfromdirs "$prvgrpdir")"
  205. for arch in $archs; do
  206. genlist "$dist" "$arch" "$prvgrpdir" "$pubpkgdir"
  207. done
  208. [ -z "$archs" ] || genlist "$dist" "source" "$prvgrpdir" "$pubpkgdir"
  209. done
  210. done
  211. # Create/update Release files
  212. #
  213. # $PUBBASE/dists/$dist/Release
  214. #
  215. allsections="$( \
  216. find "$PRVBASE" -type f -name HINTS -exec cat '{}' ';' \
  217. | sectionsfromhintstream
  218. )"
  219. allsections="$(compactlist $allsections)"
  220. debugprint "All sections: \"$allsections\""
  221. dists="$(distsfromprvgrpdirs "$PRVBASE/sections")"
  222. dists="$(compactlist $dists)"
  223. for dist in $dists; do
  224. genrelease "$dist" ${allsections}
  225. done
  226. exit 0