summaryrefslogtreecommitdiff
path: root/localdebpool
blob: a01abbe07ab056e1063a646884a137b9bfedcbb4 (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. section="$1"
  86. dist="$2"
  87. arch="$3"
  88. srcdir="$4"
  89. basedir="$5"
  90. case "$arch" in
  91. source)
  92. destdir="$basedir/source";
  93. cmd="dpkg-scansources";
  94. file="Sources";
  95. ;;
  96. *)
  97. destdir="$basedir/binary-$arch";
  98. cmd="dpkg-scanpackages -a$arch";
  99. file="Packages";
  100. ;;
  101. esac
  102. mkdir -p "$destdir"
  103. debugprint "genlist: \"$cmd . /dev/null pkg/$section/\"" "2"
  104. ( cd "$srcdir" && $cmd . /dev/null pkg/$section/ ) > "$destdir/$file"
  105. if [ -s "$destdir/$file" ]; then
  106. debugprint "Finalizing list at \"$destdir/\"" "2"
  107. gzip -c "$destdir/$file" > "$destdir/$file.gz"
  108. bzip2 -c "$destdir/$file" > "$destdir/$file.bz2"
  109. cat <<EOF > "$destdir/Release"
  110. Archive: $dist
  111. Component: $section
  112. Origin: $ORIGIN
  113. Label: $LABEL
  114. Architecture: $arch
  115. EOF
  116. else
  117. debugprint "purge empty list at \"$destdir/\"" "2"
  118. rm -f "$destdir/$file" "$destdir/$file.gz" "$destdir/$file.bz2" "$destdir/Release"
  119. rmdir -p --ignore-fail-on-non-empty "$destdir"
  120. fi
  121. }
  122. genrelease() {
  123. dist="$1"
  124. shift
  125. sections="$@"
  126. archs="$(archsfromdirs "$PRVBASE/sections"/*/"$dist")"
  127. archs="$(compactlist $archs)"
  128. case "$dist" in
  129. etch) suite="stable";;
  130. lenny) suite="testing";;
  131. sid) suite="unstable";;
  132. esac
  133. cat <<EOF > "$PUBBASE/dists/$dist/Release"
  134. Origin: $ORIGIN
  135. Label: $LABEL
  136. Suite: $suite
  137. Codename: $dist
  138. Architectures: $archs
  139. Components: $sections
  140. EOF
  141. }
  142. packages="$@"
  143. packages="$(compactlist $packages)"
  144. debugprint "Packages: \"$packages\""
  145. case "$packages" in
  146. -a|--all)
  147. pkg_re=".*"
  148. ;;
  149. "")
  150. echo 1>&2 "ERROR: No package(s) provided."
  151. exit 1
  152. ;;
  153. *)
  154. pkg_re="\b$(regexfromlist $packages)\b"
  155. ;;
  156. esac
  157. # Find packages in $prvpkgdir belonging to $sections
  158. #
  159. # $PRVBASE/$buildhost/pool-$pool/$package/
  160. #
  161. batchsections="$( \
  162. find "$PRVBASE" -type f -regex '.*/'"$pkg_re"'/HINTS' -exec cat '{}' ';' \
  163. | sectionsfromhintstream
  164. )"
  165. batchsections="$(compactlist $batchsections)"
  166. debugprint "Sections in batch: \"$batchsections\""
  167. batchsections_re=
  168. if [ -n "$batchsections" ]; then
  169. batchsections_re="\b$(regexfromlist $batchsections)\b"
  170. else
  171. echo 1>&2 "ERROR: Package(s) $@ was not found in any section."
  172. exit 1
  173. fi
  174. debugprint "Clean dangling symlinks below \"$PRVBASE\" and \"$PUBBASE\"..."
  175. symlinks -dr ${DEBUG:+-v} "$PRVBASE" "$PUBBASE"
  176. # Create/update symlink farms $prvgrpdir and $pubpkgdir
  177. #
  178. # $PRVBASE/sections/$section/$dist/$section/$package/$pool/$buildhost
  179. # $PUBBASE/pkg/$package/$pool/$buildhost
  180. #
  181. cd "$PRVBASE" && find * -type f -name HINTS -exec grep -q "^Sections:.*$batchsections_re" '{}' ';' -printf '%h\n' \
  182. | while read prvpkgdir; do
  183. debugprint "prvpkgdir: \"$prvpkgdir\""
  184. set -- $(pkginfofromprvpkgdir "$prvpkgdir")
  185. package="$1" pool="$2" dist="$3" buildhost="$4"
  186. shift 4
  187. pkgsections="$(cat "$PRVBASE/$prvpkgdir/HINTS" | sectionsfromhintstream)"
  188. pkgsections="$(compactlist $pkgsections)"
  189. for section in $pkgsections; do
  190. subdir="$section/$package/$pool"
  191. mkdir -p "$PUBBASE/pkg/$subdir"
  192. ln -sf -T "$PRVBASE/$prvpkgdir" "$PUBBASE/pkg/$subdir/$buildhost"
  193. mkdir -p "$PRVBASE/sections/$section/$dist/$subdir"
  194. ln -sf -T "../../../../../../$prvpkgdir" "$PRVBASE/sections/$section/$dist/$subdir/$buildhost"
  195. done
  196. done
  197. # Create/update package lists
  198. #
  199. # $PUBBASE/dists/$dist/$section/{binary-$arch,source}
  200. #
  201. for section in $batchsections; do
  202. dists="$(distsfromprvgrpdirs "$PRVBASE/sections/$section")"
  203. for dist in $dists; do
  204. debugprint "genlists \"\$PRVBASE/sections/$section/$dist\" -> \"\$PUBBASE/dists/$dist/$section\""
  205. prvgrpdir="$PRVBASE/sections/$section/$dist/$section"
  206. pubpkgdir="$PUBBASE/dists/$dist/$section"
  207. archs="$(archsfromdirs "$prvgrpdir")"
  208. for arch in $archs; do
  209. genlist "$section" "$dist" "$arch" "$prvgrpdir" "$pubpkgdir"
  210. done
  211. [ -z "$archs" ] || genlist "$section" "$dist" "source" "$prvgrpdir" "$pubpkgdir"
  212. done
  213. done
  214. # Create/update Release files
  215. #
  216. # $PUBBASE/dists/$dist/Release
  217. #
  218. allsections="$( \
  219. find "$PRVBASE" -type f -name HINTS -exec cat '{}' ';' \
  220. | sectionsfromhintstream
  221. )"
  222. allsections="$(compactlist $allsections)"
  223. debugprint "All sections: \"$allsections\""
  224. dists="$(distsfromprvgrpdirs "$PRVBASE/sections")"
  225. dists="$(compactlist $dists)"
  226. for dist in $dists; do
  227. genrelease "$dist" ${allsections}
  228. done
  229. exit 0