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