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