summaryrefslogtreecommitdiff
path: root/localdebpool
blob: 9fcc16892be3318d25798e2298a618a394bc5ab4 (plain)
  1. #!/bin/sh
  2. set -e
  3. ORIGIN="Jones"
  4. LABEL="Jones"
  5. DISTS="squeeze wheezy jessie 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. echo "$*" | perl -nlE "say for /(\S+)/g" | sort -u
  18. }
  19. regexfromlist() {
  20. echo "$*" | sed 's/[[:space:]]\+/|/g; s/+/\\+/g; s/^/(/; s/$/)/'
  21. }
  22. sectionsfromhintstream() {
  23. perl -ne 's/^Sections:\W*// && do { s/\W*,\W*/\n/g; s/\W*$/\n/; print; }'
  24. }
  25. pkginfofromprvpkgdir() {
  26. package="$(basename "$1")"
  27. pool="$(dirname "$1" | sed 's,.*/pool-\([^/]\+\)/\?.*,\1,; s,-all$,,')"
  28. dist="$(echo "$pool" | sed 's,[^a-z].*$,,')"
  29. buildhost="$(dirname "$@" | sed 's,^\([^/]\+\)/pool-.*,\1,')"
  30. echo "$package $pool $dist $buildhost"
  31. }
  32. archsfromdirs() {
  33. archs="$( \
  34. find "$@" -type l -exec find '{}'/ -type f -name '*.deb' ';' \
  35. | sed 's/^.*_\([a-z0-9-]\+\)\.deb$/\1/; s/\ball\b/'"$ARCHS"'/g' \
  36. )"
  37. archs="$(compactlist $archs)"
  38. debugprint "Archs found: \"$archs\"" "2"
  39. for arch in $archs; do
  40. valid=
  41. for arch_supported in $ARCHS; do
  42. case $arch in
  43. $arch_supported)
  44. debugprint "Arch ok: \"$arch\"" "2"
  45. echo "$arch"
  46. valid=1
  47. ;;
  48. esac
  49. done
  50. if [ -z "$valid" ]; then
  51. # TODO: Optionally just skip
  52. echo 1>&2 "ERROR: Unsupported architecture: \"$arch\"."
  53. exit 1
  54. fi
  55. done
  56. }
  57. distsfromprvgrpdirs() {
  58. dists="$( \
  59. find "$@" -type l -exec find '{}'/ -type f -name '*.deb' ';' \
  60. | sed 's,^.*/sections/[^/]*/\([^/]\+\)/.*$,\1,' \
  61. )"
  62. dists="$(compactlist $dists)"
  63. debugprint "Dists found: \"$dists\"" "2"
  64. for dist in $dists; do
  65. valid=
  66. for dist_supported in $DISTS; do
  67. case $dist in
  68. $dist_supported)
  69. debugprint "Dist ok: \"$dist\"" "2"
  70. echo "$dist"
  71. valid=1
  72. ;;
  73. esac
  74. done
  75. if [ -z "$valid" ]; then
  76. # TODO: Optionally just skip
  77. echo 1>&2 "ERROR: Unsupported distribution: \"$dist\"."
  78. exit 1
  79. fi
  80. done
  81. }
  82. genlist() {
  83. section="$1"
  84. dist="$2"
  85. arch="$3"
  86. srcdir="$4"
  87. basedir="$5"
  88. case "$arch" in
  89. source)
  90. destdir="$basedir/source";
  91. cmd="dpkg-scansources";
  92. file="Sources";
  93. ;;
  94. *)
  95. destdir="$basedir/binary-$arch";
  96. cmd="dpkg-scanpackages -a$arch";
  97. file="Packages";
  98. ;;
  99. esac
  100. mkdir -p "$destdir"
  101. debugprint "genlist: \"$cmd . /dev/null pkg/$section/\"" "2"
  102. if [ -n "$DEBUG" ] && [ "$DEBUG" -ge 2 ]; then
  103. ( cd "$srcdir" && $cmd . /dev/null pkg/$section/ ) > "$destdir/$file"
  104. else
  105. ( cd "$srcdir" && $cmd . /dev/null pkg/$section/ ) > "$destdir/$file" 2> /dev/null
  106. fi
  107. if [ -s "$destdir/$file" ]; then
  108. debugprint "Finalizing list at \"$destdir/\"" "2"
  109. gzip -c "$destdir/$file" > "$destdir/$file.gz"
  110. bzip2 -c "$destdir/$file" > "$destdir/$file.bz2"
  111. cat <<EOF > "$destdir/Release"
  112. Archive: $dist
  113. Component: $section
  114. Origin: $ORIGIN
  115. Label: $LABEL
  116. Architecture: $arch
  117. EOF
  118. else
  119. debugprint "purge empty list at \"$destdir/\"" "2"
  120. rm -f "$destdir/$file" "$destdir/$file.gz" "$destdir/$file.bz2" "$destdir/Release"
  121. rmdir -p --ignore-fail-on-non-empty "$destdir"
  122. fi
  123. }
  124. genrelease() {
  125. dist="$1"
  126. shift
  127. sections="$*"
  128. archs="$(archsfromdirs "$PRVBASE/sections"/*/"$dist")"
  129. archs="$(compactlist $archs)"
  130. case "$dist" in
  131. squeeze) suite="oldstable";;
  132. wheezy) suite="stable";;
  133. jessie) suite="testing";;
  134. sid) suite="unstable";;
  135. esac
  136. cat <<EOF > "$PUBBASE/dists/$dist/Release"
  137. Origin: $ORIGIN
  138. Label: $LABEL
  139. Suite: $suite
  140. Codename: $dist
  141. Architectures: $archs
  142. Components: $sections
  143. EOF
  144. }
  145. packages="$*"
  146. packages="$(compactlist $packages)"
  147. debugprint "Packages: \"$packages\""
  148. case "$packages" in
  149. -a|--all)
  150. pkg_re=".*"
  151. ;;
  152. "")
  153. echo 1>&2 "ERROR: No package(s) provided."
  154. exit 1
  155. ;;
  156. *)
  157. # FIXME: tighten to avoid \b (which wrongly includes - )
  158. pkg_re="\b$(regexfromlist $packages)\b"
  159. ;;
  160. esac
  161. # Find packages in $prvpkgdir belonging to $sections
  162. #
  163. # $PRVBASE/$buildhost/pool-$pool/$package/
  164. #
  165. batchsections="$( \
  166. find "$PRVBASE" -type f -regextype egrep -regex '.*/'"$pkg_re"'/HINTS' -exec cat '{}' ';' \
  167. | sectionsfromhintstream
  168. )"
  169. batchsections="$(compactlist $batchsections)"
  170. debugprint "Sections in batch: \"$batchsections\""
  171. batchsections_re=
  172. if [ -n "$batchsections" ]; then
  173. batchsections_re="\b$(regexfromlist $batchsections)(\s|\Z)"
  174. else
  175. echo 1>&2 "ERROR: Package(s) $* was not found in any section."
  176. exit 1
  177. fi
  178. echo "Clean dangling symlinks, and remove empty dirs and files..."
  179. if [ -n "$DEBUG" ] && [ "$DEBUG" -ge 3 ]; then
  180. debugprint "symlinks -dr ${DEBUG:+-v} \"$PRVBASE\" \"$PUBBASE\""
  181. symlinks -dr ${DEBUG:+-v} "$PRVBASE" "$PUBBASE"
  182. else
  183. symlinks -dr ${DEBUG:+-v} "$PRVBASE" "$PUBBASE" > /dev/null
  184. fi
  185. debugprint "find \"$PRVBASE\" -empty -delete"
  186. find "$PRVBASE" -empty -delete
  187. debugprint "find \"$PUBBASE\" -empty -delete"
  188. find "$PUBBASE" -empty -delete
  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="$(sectionsfromhintstream < "$PRVBASE/$prvpkgdir/HINTS")"
  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 " %s" "$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 " %s" "$dist"
  249. genrelease "$dist" ${allsections}
  250. done
  251. [ -n "$DEBUG" ] || echo " - Done!"
  252. exit 0