mkrepopage (7177B)
1 #!/bin/sh 2 # mkrepopage DIR: index.html for the repo in DIR (DIR/x86_64, DIR/x86 and the key), with a list-ARCH.tsv of every 3 # package mag can install from the repos in REPOS, for the search on it 4 set -e 5 [ $# = 1 ] && [ -d "$1/x86_64" ] || { echo "usage: mkrepopage DIR" >&2; exit 2; } 6 dir=$1 7 here=$(cd "$(dirname "$0")/.." && pwd) 8 repos=${REPOS:-$here/pkg/chamesle-base/repos} 9 tmp=$(mktemp -d "$dir/.page.XXXXXX") 10 trap 'rm -rf "$tmp"' EXIT 11 12 esc() { sed 's/&/\&/g; s/</\</g; s/>/\>/g'; } 13 14 # idx FILE REPO: name, version, repo, installed size, description and dependencies, a line each 15 idx() { 16 tar -xzOf "$1" APKINDEX | awk -v r="$2" -F: ' 17 /^P:/ { p = substr($0, 3) } /^V:/ { v = substr($0, 3) } /^I:/ { i = substr($0, 3) } 18 /^T:/ { t = substr($0, 3); gsub(/\t/, " ", t) } 19 /^D:/ { n = split(substr($0, 3), x, " "); d = ""; for (j = 1; j <= n; j++) if (x[j] !~ /^(so|pc|cmd):/) d = d (d == "" ? "" : " ") x[j] } 20 /^$/ { if (p != "") print p "\t" v "\t" r "\t" i "\t" t "\t" d; p = v = i = t = d = "" } 21 END { if (p != "") print p "\t" v "\t" r "\t" i "\t" t "\t" d }' 22 } 23 24 for a in x86_64 x86; do 25 : > "$tmp/$a" 26 while read -r u; do 27 case $u in ''|'#'*) continue;; esac 28 case $u in 29 *chamesle.org/repo*) f=$dir/$a/APKINDEX.tar.gz r=chamesle;; 30 *) f=$tmp/$a.idx r=${u##*/}; curl -fsSL "$u/$a/APKINDEX.tar.gz" -o "$f";; 31 esac 32 idx "$f" "$r" >> "$tmp/$a" 33 done < "$repos" 34 sort -t "$(printf '\t')" -k1,1 -u "$tmp/$a" > "$dir/list-$a.tsv" 35 done 36 37 own() { 38 tar -xzOf "$dir/$1/APKINDEX.tar.gz" APKINDEX | awk -F: ' 39 /^P:/ { p = substr($0, 3) } /^V:/ { v = substr($0, 3) } /^S:/ { s = substr($0, 3) } 40 /^I:/ { i = substr($0, 3) } /^T:/ { t = substr($0, 3) } /^D:/ { d = substr($0, 3) } 41 /^$/ { if (p != "") print p "|" v "|" s "|" i "|" t "|" d; p = v = s = i = t = d = "" } 42 END { if (p != "") print p "|" v "|" s "|" i "|" t "|" d }' | 43 while IFS='|' read -r p v s i t d; do 44 f=$p-$v.apk 45 sum=$(sha256sum "$dir/$1/$f" | cut -c1-64) 46 deps= 47 for x in $d; do deps="$deps <a href=\"#$x\">$x</a>"; done 48 printf '<tr><td><b>%s</b><br>%s</td><td>%s</td><td>%s K<br>%s K installed</td><td><a href="%s/%s">%s</a><br><code class="sum">%s</code></td></tr>\n' \ 49 "$p" "$v" "$(printf '%s' "$t" | esc)${deps:+<br><small>needs$deps</small>}" "$1" "$((s / 1024))" "$((i / 1024))" "$1" "$f" "$f" "$sum" 50 done 51 } 52 53 key=$(ls "$dir"/*.rsa.pub | head -1) 54 fp=$(openssl pkey -pubin -in "$key" -outform DER | sha256sum | cut -c1-64) 55 now=$(date +%Y-%m-%d) 56 n64=$(wc -l < "$dir/list-x86_64.tsv") 57 58 cat > "$dir/index.html" <<H 59 <!doctype html> 60 <html lang="en"> 61 <head> 62 <meta charset="utf-8"> 63 <meta name="viewport" content="width=device-width, initial-scale=1"> 64 <title>Repo - Chamesle</title> 65 <meta name="description" content="Chamesle's package repo, and a search over every package mag can install."> 66 <link rel="canonical" href="https://chamesle.org/repo/"> 67 <link rel="stylesheet" href="../style.css?19"> 68 <link rel="icon" href="../img/logo.png"> 69 <style> 70 #q { width: 100%; box-sizing: border-box; font: inherit; padding: 4px; } 71 #hits td, .own td { vertical-align: top; } 72 .sum { font-size: 11px; word-break: break-all; } 73 .pkg { margin: 12px 0; padding: 8px; border: 1px solid #888; } 74 .pkg pre { margin: 6px 0 0; } 75 </style> 76 </head> 77 <body> 78 79 <div id="page"> 80 81 <div id="top"> 82 <h1><a href="../"><img src="../img/banner-dark.png" alt="Chamesle Linux" width="223" height="56"></a></h1> 83 </div> 84 85 <div id="nav"> 86 <a href="../">Home</a> | 87 <a href="../download.html">Download</a> | 88 <a href="../docs.html">Handbook</a> | 89 <a href="../packages.html">Packages</a> | 90 <b>Repo</b> | 91 <a href="../new.html">News</a> | 92 <a href="../board.html">Board</a> | 93 <a href="../source.html">Source</a> | 94 <a href="../about.html">About</a> 95 </div> 96 97 <main> 98 <h2>The repo</h2> 99 <p><code>https://chamesle.org/repo</code> has Chamesle's own packages, for <code>x86_64</code> and <code>x86</code>. 100 mag reads it next to the musl repo with everything else; both are in <code>/etc/mag/repos</code> of every install. 101 The index and every package are signed with <a href="$(basename "$key")">$(basename "$key")</a>, whose key has the 102 SHA-256 <code class="sum">$fp</code></p> 103 <pre>https://chamesle.org/repo 104 cp $(basename "$key") /etc/mag/keys/</pre> 105 106 <h2>Search</h2> 107 <p>Every package mag can install, $n64 of them for x86_64. <label><input type="radio" name="arch" value="x86_64" checked> x86_64</label> 108 <label><input type="radio" name="arch" value="x86"> x86</label></p> 109 <input id="q" type="search" placeholder="a name or a word, like tmux or irc" autocomplete="off"> 110 <div id="pkg"></div> 111 <table id="hits"></table> 112 113 <h2>Chamesle's packages</h2> 114 <h3>x86_64</h3> 115 <table class="own"> 116 $(own x86_64) 117 </table> 118 <h3>x86</h3> 119 <table class="own"> 120 $(own x86) 121 </table> 122 </main> 123 124 <hr> 125 <div id="foot"> 126 Made by <code>mkrepopage</code> from <a href="https://github.com/tortr-rs/system">system</a> on $now. 127 </div> 128 129 </div> 130 131 <script> 132 var lists = {}, arch = 'x86_64', q = document.getElementById('q'), hits = document.getElementById('hits'), one = document.getElementById('pkg'); 133 function e(s) { return s.replace(/&/g, '&').replace(/</g, '<'); } 134 function load(a, then) { 135 if (lists[a]) return then(); 136 fetch('list-' + a + '.tsv').then(function (r) { return r.text(); }).then(function (t) { 137 var m = {}, l = t.split('\\n').filter(Boolean).map(function (x) { var f = x.split('\\t'); m[f[0]] = f; return f; }); 138 lists[a] = { all: l, by: m }; then(); 139 }); 140 } 141 function find() { 142 var w = q.value.trim().toLowerCase(), l = lists[arch].all, out = []; 143 if (w.length < 2) { hits.innerHTML = ''; return; } 144 l.forEach(function (f) { 145 var n = f[0].toLowerCase(), r = n == w ? 0 : n.indexOf(w) == 0 ? 1 : n.indexOf(w) > 0 ? 2 : f[4].toLowerCase().indexOf(w) >= 0 ? 3 : -1; 146 if (r >= 0) out.push([r, f]); 147 }); 148 out.sort(function (a, b) { return a[0] - b[0] || a[1][0].localeCompare(b[1][0]); }); 149 hits.innerHTML = out.slice(0, 100).map(function (x) { 150 var f = x[1]; 151 return '<tr><td><a href="#' + e(f[0]) + '">' + e(f[0]) + '</a></td><td>' + e(f[1]) + '</td><td>' + e(f[4]) + '</td></tr>'; 152 }).join('') + (out.length > 100 ? '<tr><td colspan="3"><i>' + (out.length - 100) + ' more, say more</i></td></tr>' : ''); 153 } 154 function show() { 155 var n = decodeURIComponent(location.hash.slice(1)), f = lists[arch] && lists[arch].by[n]; 156 if (!n) { one.innerHTML = ''; return; } 157 if (!f) { one.innerHTML = '<div class="pkg">no <b>' + e(n) + '</b> for ' + arch + '</div>'; return; } 158 var d = f[5] ? f[5].split(' ').map(function (x) { var b = x.replace(/[<>=~].*/, '').replace(/^so:|^cmd:|^pc:/, ''); return lists[arch].by[b] ? '<a href="#' + e(b) + '">' + e(x) + '</a>' : e(x); }).join(' ') : 'nothing'; 159 one.innerHTML = '<div class="pkg"><b>' + e(f[0]) + '</b> ' + e(f[1]) + ', from ' + e(f[2]) + ', ' + Math.round(f[3] / 1024) + ' K installed<br>' + e(f[4]) + '<br><small>needs ' + d + '</small><pre>mag install ' + e(f[0]) + '</pre></div>'; 160 } 161 document.querySelectorAll('input[name=arch]').forEach(function (r) { r.onchange = function () { arch = r.value; load(arch, function () { find(); show(); }); }; }); 162 q.oninput = find; 163 window.onhashchange = show; 164 load(arch, function () { find(); show(); }); 165 </script> 166 </body> 167 </html> 168 H 169 echo "$dir/index.html: $n64 packages for x86_64"