summaryrefslogtreecommitdiff
path: root/localdebpool
blob: 34e3abfddb4e217814d66501181e22f2da876a82 (plain)
  1. #!/bin/sh
  2. set -e
  3. ORIGIN="Jones"
  4. LABEL="Jones"
  5. DISTS="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, and remove empty dirs and files..."
  182. if [ -n "$DEBUG" ] && [ "$DEBUG" -ge 3 ]; then
  183. debugprint "symlinks -dr ${DEBUG:+-v} \"$PRVBASE\" \"$PUBBASE\""
  184. symlinks -dr ${DEBUG:+-v} "$PRVBASE" "$PUBBASE"
  185. else
  186. symlinks -dr ${DEBUG:+-v} "$PRVBASE" "$PUBBASE" > /dev/null
  187. fi
  188. debugprint "find \"$PRVBASE\" -empty -delete"
  189. find "$PRVBASE" -empty -delete
  190. debugprint "find \"$PUBBASE\" -empty -delete"
  191. find "$PUBBASE" -empty -delete
  192. # Create/update symlink farms $prvgrpdir and $pubpkgdir
  193. #
  194. # $PRVBASE/sections/$section/$dist/$section/$package/$pool/$buildhost
  195. # $PUBBASE/pkg/$package/$pool/$buildhost
  196. #
  197. cd "$PRVBASE" && find * -type f -name HINTS -exec grep -Pq "^Sections:.*$batchsections_re" '{}' ';' -printf '%h\n' \
  198. | while read prvpkgdir; do
  199. debugprint "prvpkgdir: \"$prvpkgdir\""
  200. set -- $(pkginfofromprvpkgdir "$prvpkgdir")
  201. package="$1" pool="$2" dist="$3" buildhost="$4"
  202. shift 4
  203. pkgsections="$(cat "$PRVBASE/$prvpkgdir/HINTS" | sectionsfromhintstream)"
  204. pkgsections="$(compactlist $pkgsections)"
  205. for section in $pkgsections; do
  206. subdir="$section/$package/$pool"
  207. mkdir -p "$PUBBASE/pkg/$subdir"
  208. ln -sf -T "$PRVBASE/$prvpkgdir" "$PUBBASE/pkg/$subdir/$buildhost"
  209. mkdir -p "$PRVBASE/sections/$section/$dist/$subdir"
  210. ln -sf -T "../../../../../../$prvpkgdir" "$PRVBASE/sections/$section/$dist/$subdir/$buildhost"
  211. done
  212. done
  213. # Create/update package lists
  214. #
  215. # $PUBBASE/dists/$dist/$section/{binary-$arch,source}
  216. #
  217. [ -n "$DEBUG" ] || printf "Creating/updating package sections:"
  218. for section in $batchsections; do
  219. [ -n "$DEBUG" ] || printf " $section"
  220. dists="$(distsfromprvgrpdirs "$PRVBASE/sections/$section")"
  221. for dist in $dists; do
  222. if [ -n "$DEBUG" ]; then
  223. debugprint "genlists \"\$PRVBASE/sections/$section/$dist\" -> \"\$PUBBASE/dists/$dist/$section\""
  224. else
  225. printf .
  226. fi
  227. prvgrpdir="$PRVBASE/sections/$section/$dist/$section"
  228. pubpkgdir="$PUBBASE/dists/$dist/$section"
  229. archs="$(archsfromdirs "$prvgrpdir")"
  230. for arch in $archs; do
  231. genlist "$section" "$dist" "$arch" "$prvgrpdir" "$pubpkgdir"
  232. done
  233. [ -z "$archs" ] || genlist "$section" "$dist" "source" "$prvgrpdir" "$pubpkgdir"
  234. done
  235. done
  236. [ -n "$DEBUG" ] || echo " - Done!"
  237. # Create/update Release files
  238. #
  239. # $PUBBASE/dists/$dist/Release
  240. #
  241. [ -n "$DEBUG" ] || printf "Creating/updating release files:"
  242. allsections="$( \
  243. find "$PRVBASE" -type f -name HINTS -exec cat '{}' ';' \
  244. | sectionsfromhintstream
  245. )"
  246. allsections="$(compactlist $allsections)"
  247. debugprint "All sections: \"$allsections\"" "2"
  248. dists="$(distsfromprvgrpdirs "$PRVBASE/sections")"
  249. dists="$(compactlist $dists)"
  250. for dist in $dists; do
  251. [ -n "$DEBUG" ] || printf " $dist"
  252. genrelease "$dist" ${allsections}
  253. done
  254. [ -n "$DEBUG" ] || echo " - Done!"
  255. exit 0