|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +set -e |
| 4 | +source scripts/package-lib |
| 5 | + |
| 6 | +usage="$0 [OPTION]... RECIPESDIR WORKDIR |
| 7 | +
|
| 8 | +Builds the package listing as a webpage |
| 9 | +
|
| 10 | +The WORKDIR must be a non-existent directory in which the builds are performed. |
| 11 | +
|
| 12 | +Options: |
| 13 | +
|
| 14 | + -h Show this help message." |
| 15 | + |
| 16 | +helpflag= |
| 17 | + |
| 18 | +while getopts h name; do |
| 19 | + case $name in |
| 20 | + h) helpflag=1 ;; |
| 21 | + *) error "Invalid option. Use the -h flag for more information." ;; |
| 22 | + esac |
| 23 | +done |
| 24 | + |
| 25 | +shift $((OPTIND - 1)) |
| 26 | + |
| 27 | +if [[ -n $helpflag ]]; then |
| 28 | + echo "$usage" |
| 29 | + exit |
| 30 | +fi |
| 31 | + |
| 32 | +if [[ $# -eq 0 ]]; then |
| 33 | + error "Missing RECIPESDIR and WORKDIR arguments. Use the -h flag for more information." |
| 34 | +fi |
| 35 | + |
| 36 | +if [[ $# -eq 1 ]]; then |
| 37 | + error "Missing WORKDIR argument. Use the -h flag for more information." |
| 38 | +fi |
| 39 | + |
| 40 | +if [[ $# -gt 2 ]]; then |
| 41 | + error "Extraneous arguments. Use the -h flag for more information." |
| 42 | +fi |
| 43 | + |
| 44 | +recipesdir="$1" |
| 45 | +workdir="$2" |
| 46 | + |
| 47 | +pkgsworkdir="$workdir"/ |
| 48 | +mkdir -p "$pkgsworkdir" |
| 49 | + |
| 50 | +cat >"${pkgsworkdir}/index.html" <<WEBS |
| 51 | +<html> |
| 52 | +<head> |
| 53 | +<meta charset="utf-8"> |
| 54 | +<style> |
| 55 | + body { |
| 56 | + font-family: monospace; |
| 57 | + background-color: #f8fcf8; |
| 58 | + } |
| 59 | + table { |
| 60 | + width: 100%; |
| 61 | + } |
| 62 | + table td { |
| 63 | + padding: 0 20px; |
| 64 | + } |
| 65 | + table tr:nth-child(even) { |
| 66 | + background-color: #dcdfdc; |
| 67 | + } |
| 68 | +
|
| 69 | + table thead { |
| 70 | + border-bottom: 1px dotted gray; |
| 71 | + } |
| 72 | +
|
| 73 | + table th { |
| 74 | + text-align: left; |
| 75 | + padding-left: 20px; |
| 76 | + } |
| 77 | +</style> |
| 78 | +</head> |
| 79 | +
|
| 80 | +<body> |
| 81 | +
|
| 82 | +<a href="../">Back to Repository Home Page</a> |
| 83 | +
|
| 84 | +<h1>Toltec Package Listing</h1> |
| 85 | +<table> |
| 86 | +
|
| 87 | +<thead> <tr> |
| 88 | + <th>Name</th> <th>Description</th> <th>Version</th> <th>Category</th> <th>License</th> |
| 89 | +</tr></thead> |
| 90 | +WEBS |
| 91 | + |
| 92 | +# Build packages index |
| 93 | +section "Making packages index ${pkgsworkdir}/index.html" |
| 94 | + |
| 95 | +# Build each package or get it from the remote server |
| 96 | +for recipedir in "$recipesdir"/*; do |
| 97 | + ( |
| 98 | + load-recipe "$recipedir" |
| 99 | + |
| 100 | + status "Adding table entry for $pkgname $pkgver" |
| 101 | + |
| 102 | + pkgworkdir="$pkgsworkdir"/"$pkgname" |
| 103 | + if [[ -z "${url}" ]]; then |
| 104 | + href="${url}" |
| 105 | + else |
| 106 | + href="<a target='_new' href='${url}'>${pkgname}</a>" |
| 107 | + fi |
| 108 | + |
| 109 | + cat >>"${workdir}/index.html" <<WEBS |
| 110 | +<tr> |
| 111 | + <td>${href}</td> |
| 112 | + <td>${pkgdesc}</td> |
| 113 | + <td>${pkgver}</td> |
| 114 | + <td>${section}</td> |
| 115 | + <td><a href='https://spdx.org/licenses/$license.html'>${license}</a></td> |
| 116 | +</tr> |
| 117 | +WEBS |
| 118 | + ) |
| 119 | + |
| 120 | +done |
| 121 | + |
| 122 | +cat >>"${pkgsworkdir}/index.html" <<WEBS |
| 123 | +</table> |
| 124 | +</body> |
| 125 | +</html> |
| 126 | +WEBS |
| 127 | +section "Done. Result is in ${pkgsworkdir}" |
0 commit comments