summaryrefslogtreecommitdiff
path: root/localdebpool
blob: 4b5ac3dec45aa1bcd3c6f9ab2b5e13e524fc695c (plain)
  1. #!/bin/sh
  2. set -e
  3. ORIGIN="Jones"
  4. LABEL="Jones"
  5. DISTS="etch lenny squeeze wheezy 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. # FIXME: tighten to avoid \b (which wrongly includes - )
  161. pkg_re="\b$(regexfromlist $packages)\b"
  162. ;;
  163. esac
  164. # Find packages in $prvpkgdir belonging to $sections
  165. #
  166. # $PRVBASE/$buildhost/pool-$pool/$package/
  167. #
  168. batchsections="$( \
  169. find "$PRVBASE" -type f -regextype egrep -regex '.*/'"$pkg_re"'/HINTS' -exec cat '{}' ';' \
  170. | sectionsfromhintstream
  171. )"
  172. batchsections="$(compactlist $batchsections)"
  173. debugprint "Sections in batch: \"$batchsections\""
  174. batchsections_re=
  175. if [ -n "$batchsections" ]; then
  176. batchsections_re="\b$(regexfromlist ${batchsections/+/\\\\+})(\s|\Z)"
  177. else
  178. echo 1>&2 "ERROR: Package(s) $@ was not found in any section."
  179. exit 1
  180. fi
  181. echo "Clean dangling symlinks..."
  182. if [ -n "$DEBUG" ] && [ "$DEBUG" -ge 3 ]; then
  183. echo "Clean dangling symlinks below \"$PRVBASE\" and \"$PUBBASE\"..."
  184. debugprint "symlinks -dr ${DEBUG:+-v} \"$PRVBASE\" \"$PUBBASE\""
  185. symlinks -dr ${DEBUG:+-v} "$PRVBASE" "$PUBBASE"
  186. else
  187. symlinks -dr ${DEBUG:+-v} "$PRVBASE" "$PUBBASE" > /dev/null
  188. fi
  189. # Create/update symlink farms $prvgrpdir and $pubpkgdir
  190. #
  191. # $PRVBASE/sections/$section/$dist/$section/$package/$pool/$buildhost
  192. # $PUBBASE/pkg/$package/$pool/$buildhost
  193. #
  194. cd "$PRVBASE" && find * -type f -name HINTS -exec grep -Pq "^Sections:.*$batchsections_re" '{}' ';' -printf '%h\n' \
  195. | while read prvpkgdir; do
  196. debugprint "prvpkgdir: \"$prvpkgdir\""
  197. set -- $(pkginfofromprvpkgdir "$prvpkgdir")
  198. package="$1" pool="$2" dist="$3" buildhost="$4"
  199. shift 4
  200. pkgsections="$(cat "$PRVBASE/$prvpkgdir/HINTS" | sectionsfromhintstream)"
  201. pkgsections="$(compactlist $pkgsections)"
  202. for section in $pkgsections; do
  203. subdir="$section/$package/$pool"
  204. mkdir -p "$PUBBASE/pkg/$subdir"
  205. ln -sf -T "$PRVBASE/$prvpkgdir" "$PUBBASE/pkg/$subdir/$buildhost"
  206. mkdir -p "$PRVBASE/sections/$section/$dist/$subdir"
  207. ln -sf -T "../../../../../../$prvpkgdir" "$PRVBASE/sections/$section/$dist/$subdir/$buildhost"
  208. done
  209. done
  210. # Create/update package lists
  211. #
  212. # $PUBBASE/dists/$dist/$section/{binary-$arch,source}
  213. #
  214. [ -n "$DEBUG" ] || printf "Creating/updating package sections:"
  215. for section in $batchsections; do
  216. [ -n "$DEBUG" ] || printf " $section"
  217. dists="$(distsfromprvgrpdirs "$PRVBASE/sections/$section")"
  218. for dist in $dists; do
  219. if [ -n "$DEBUG" ]; then
  220. debugprint "genlists \"\$PRVBASE/sections/$section/$dist\" -> \"\$PUBBASE/dists/$dist/$section\""
  221. else
  222. printf .
  223. fi
  224. prvgrpdir="$PRVBASE/sections/$section/$dist/$section"
  225. pubpkgdir="$PUBBASE/dists/$dist/$section"
  226. archs="$(archsfromdirs "$prvgrpdir")"
  227. for arch in $archs; do
  228. genlist "$section" "$dist" "$arch" "$prvgrpdir" "$pubpkgdir"
  229. done
  230. [ -z "$archs" ] || genlist "$section" "$dist" "source" "$prvgrpdir" "$pubpkgdir"
  231. done
  232. done
  233. [ -n "$DEBUG" ] || echo " - Done!"
  234. # Create/update Release files
  235. #
  236. # $PUBBASE/dists/$dist/Release
  237. #
  238. [ -n "$DEBUG" ] || printf "Creating/updating release files:"
  239. allsections="$( \
  240. find "$PRVBASE" -type f -name HINTS -exec cat '{}' ';' \
  241. | sectionsfromhintstream
  242. )"
  243. allsections="$(compactlist $allsections)"
  244. debugprint "All sections: \"$allsections\"" "2"
  245. dists="$(distsfromprvgrpdirs "$PRVBASE/sections")"
  246. dists="$(compactlist $dists)"
  247. for dist in $dists; do
  248. [ -n "$DEBUG" ] || printf " $dist"
  249. genrelease "$dist" ${allsections}
  250. done
  251. [ -n "$DEBUG" ] || echo " - Done!"
  252. exit 0