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