warbo-utilities: cb14e839090e8349cc671876fe7df9b60cb08b85
1: {
2: attrsToDirs,
3: bash,
4: ipfs,
5: runCommand,
6: wrap,
7: writeScript,
8: }:
9:
10: with rec {
11: ipfsBin = wrap {
12: name = "ipfsBin";
13: script = ''
14: #!${bash}/bin/bash
15: if command -v ipfs > /dev/null
16: then
17: ipfs "$@"
18: else
19: echo "Can't find 'ipfs', using potentially incompatible fallback" 1>&2
20: "${ipfs}/bin/ipfs" "$@"
21: fi
22: '';
23: };
24: };
25: wrap {
26: name = "git2ipfs";
27: paths = [
28: (attrsToDirs {
29: bin = {
30: inherit ipfsBin;
31: };
32: })
33: ];
34: script = ''
35: #!${bash}/bin/bash
36: set -e
37: [[ -n "$1" ]] || {
38: echo "No repo given, aborting" 1>&2
39: exit 1
40: }
41:
42: NAME=$(basename "$1" .git)
43:
44: ipfsBin key list | grep -q -Fx "$NAME" || {
45: echo "Couldn't find key for '$NAME', can't push" 1>&2
46: exit 1
47: }
48:
49: if [[ -n "$PAGES" ]]
50: then
51: echo "Using pages from '$PAGES'" 1>&2
52: else
53: echo "Generating pages" 1>&2
54: PAGES=$(repoPath="$1" htmlInOut=1 inNixedDir genGitHtml)
55: echo "Saved in $PAGES" 1>&2
56: fi
57:
58: echo "Pushing to IPFS" 1>&2
59: IPFSHASH=$(ipfsBin add -rHq "$PAGES" | tail -n1)
60:
61: echo "Hash is $IPFSHASH" 1>&2
62:
63: echo "Publishing to IPNS" 1>&2
64: ipfsBin name publish -k "$NAME" "$IPFSHASH"
65: '';
66: }
Generated by git2html.