-
Notifications
You must be signed in to change notification settings - Fork 1
/
publish-dep.sh
executable file
·42 lines (33 loc) · 1.14 KB
/
publish-dep.sh
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
36
37
38
39
40
41
42
#! /bin/sh
# 400 - Missing hash and/or peer_id
# 403 - Not allowed
# 413 - Too big
# 200 - Ok!
if ipfs &>/dev/null; then
echo "## Publishing dependency"
mv node_modules .node_modules 2>/dev/null
HASH=$(ipfs add . -r | tail -n 1 | cut -d ' ' -f 2)
mv .node_modules node_modules 2>/dev/null
echo "Published as $HASH, pinning in your nodes..."
PEER=$(ipfs id --format '<id>')
cat ~/.stay/nodes.json | jq -rc '.[]' | while read host; do
address="$host/api/pin/add/$HASH/$PEER"
status=$(curl -X POST --silent $address)
case "$status" in
"400") echo "$host - Application Error: Missing the hash and/or peer_id"
;;
"403") echo "$host - You do not have access to pinning at this node"
;;
"413") echo "$host - The module was too big to pin!"
;;
"200") echo "$host - Pinned!"
;;
*) echo "Weird status code $status for $host"
;;
esac
done
else
echo "## Could not publish dependency to IPFS, doing the good'ol 'fetch from npm registry' way"
echo "Either 'ipfs' doesn't exists in PATH or you haven't run 'ipfs daemon' before running the command"
exit 0
fi