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