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