summaryrefslogtreecommitdiff
path: root/localdebpool
blob: 2820662a16559fd261a9ae48ed41c3953a0b45ec (plain)
  1. #!/bin/sh
  2. set -e
  3. ORIGIN="Jones"
  4. LABEL="Jones"
  5. DISTS="etch lenny squeeze 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="oldstable";;
  130. lenny) suite="stable";;
  131. squeeze) suite="testing";;
  132. sid) suite="unstable";;
  133. esac
  134. cat <<EOF > "$PUBBASE/dists/$dist/Release"
  135. Origin: $ORIGIN
  136. Label: $LABEL
  137. Suite: $suite
  138. Codename: $dist
  139. Architectures: $archs
  140. Components: $sections
  141. EOF
  142. }
  143. packages="$@"
  144. packages="$(compactlist $packages)"
  145. debugprint "Packages: \"$packages\""
  146. case "$packages" in
  147. -a|--all)
  148. pkg_re=".*"
  149. ;;
  150. "")
  151. echo 1>&2 "ERROR: No package(s) provided."
  152. exit 1
  153. ;;
  154. *)
  155. pkg_re="\b$(regexfromlist $packages)\b"
  156. ;;
  157. esac
  158. # Find packages in $prvpkgdir belonging to $sections
  159. #
  160. # $PRVBASE/$buildhost/pool-$pool/$package/
  161. #
  162. batchsections="$( \
  163. find "$PRVBASE" -type f -regex '.*/'"$pkg_re"'/HINTS' -exec cat '{}' ';' \
  164. | sectionsfromhintstream
  165. )"
  166. batchsections="$(compactlist $batchsections)"
  167. debugprint "Sections in batch: \"$batchsections\""
  168. batchsections_re=
  169. if [ -n "$batchsections" ]; then
  170. batchsections_re="\b$(regexfromlist $batchsections)\b"
  171. else
  172. echo 1>&2 "ERROR: Package(s) $@ was not found in any section."
  173. exit 1
  174. fi
  175. debugprint "Clean dangling symlinks below \"$PRVBASE\" and \"$PUBBASE\"..."
  176. symlinks -dr ${DEBUG:+-v} "$PRVBASE" "$PUBBASE"
  177. # Create/update symlink farms $prvgrpdir and $pubpkgdir
  178. #
  179. # $PRVBASE/sections/$section/$dist/$section/$package/$pool/$buildhost
  180. # $PUBBASE/pkg/$package/$pool/$buildhost
  181. #
  182. cd "$PRVBASE" && find * -type f -name HINTS -exec grep -q "^Sections:.*$batchsections_re" '{}' ';' -printf '%h\n' \
  183. | while read prvpkgdir; do
  184. debugprint "prvpkgdir: \"$prvpkgdir\""
  185. set -- $(pkginfofromprvpkgdir "$prvpkgdir")
  186. package="$1" pool="$2" dist="$3" buildhost="$4"
  187. shift 4
  188. pkgsections="$(cat "$PRVBASE/$prvpkgdir/HINTS" | sectionsfromhintstream)"
  189. pkgsections="$(compactlist $pkgsections)"
  190. for section in $pkgsections; do
  191. subdir="$section/$package/$pool"
  192. mkdir -p "$PUBBASE/pkg/$subdir"
  193. ln -sf -T "$PRVBASE/$prvpkgdir" "$PUBBASE/pkg/$subdir/$buildhost"
  194. mkdir -p "$PRVBASE/sections/$section/$dist/$subdir"
  195. ln -sf -T "../../../../../../$prvpkgdir" "$PRVBASE/sections/$section/$dist/$subdir/$buildhost"
  196. done
  197. done
  198. # Create/update package lists
  199. #
  200. # $PUBBASE/dists/$dist/$section/{binary-$arch,source}
  201. #
  202. for section in $batchsections; do
  203. dists="$(distsfromprvgrpdirs "$PRVBASE/sections/$section")"
  204. for dist in $dists; do
  205. debugprint "genlists \"\$PRVBASE/sections/$section/$dist\" -> \"\$PUBBASE/dists/$dist/$section\""
  206. prvgrpdir="$PRVBASE/sections/$section/$dist/$section"
  207. pubpkgdir="$PUBBASE/dists/$dist/$section"
  208. archs="$(archsfromdirs "$prvgrpdir")"
  209. for arch in $archs; do
  210. genlist "$section" "$dist" "$arch" "$prvgrpdir" "$pubpkgdir"
  211. done
  212. [ -z "$archs" ] || genlist "$section" "$dist" "source" "$prvgrpdir" "$pubpkgdir"
  213. done
  214. done
  215. # Create/update Release files
  216. #
  217. # $PUBBASE/dists/$dist/Release
  218. #
  219. allsections="$( \
  220. find "$PRVBASE" -type f -name HINTS -exec cat '{}' ';' \
  221. | sectionsfromhintstream
  222. )"
  223. allsections="$(compactlist $allsections)"
  224. debugprint "All sections: \"$allsections\""
  225. dists="$(distsfromprvgrpdirs "$PRVBASE/sections")"
  226. dists="$(compactlist $dists)"
  227. for dist in $dists; do
  228. genrelease "$dist" ${allsections}
  229. done
  230. exit 0