summaryrefslogtreecommitdiff
path: root/www/generate/src/gomod
blob: 596c49b38436d222e860c70256719f796bc1111e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/bin/rc

domain = $1
gitdir = /var/git
if (~ $domain ()) {
	domain = `hostname
}
wwwdir = /var/www/htdocs/go.$domain


tmpdir = `{mktemp -d}
if (!cd $tmpdir) {
	exit 1
}

fn sigexit {
	rm -rf $tmpdir
}

for (repo in $gitdir/*) {
	name = `{basename $repo}
	dest = $wwwdir/$name

	if (test -e go.mod) {
		rm go.mod
	}

	if (git archive --remote=$repo HEAD go.mod >[2]/dev/null | tar -xf - >[2]/dev/null) {
		echo GEN go.$domain $name
		mkdir -p $dest
		modname = `{head -1 go.mod | sed 's/^module //'}
		printf '<!DOCTYPE html><html><head><meta name="go-import" content="%s git %s"></head></html>' \
			$modname https://src.$domain/$name > $dest/index.html
	}	
}