-
Notifications
You must be signed in to change notification settings - Fork 0
/
submarine.sh
executable file
·60 lines (49 loc) · 1.72 KB
/
submarine.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env bash
# Copyright (c) 2022 Keir Finlow-Bates <[email protected]>
# Edited by Alessandro De Cristofaro <[email protected]>
# Setup directories
IPFS_PUBLIC=./ipfs-public #change if you already run a public node
IPFS_PRIVATE=./ipfs-private #this can remain the same
# First check that ipfs is installed and that the folder to submarine exists
if which ipfs >/dev/null; then
echo "IPFS installed: proceeding"
else
echo "Run ./install.sh first"
exit 1
fi
if [[ ! -d ./ipfs-private ]]
then
echo "No private IPFS found - have you run ./install.sh?"
exit 1
fi
if [[ ! -d /Users/alessandrodecristofaro/.ipfs/ ]]
then
echo "No public IPFS found - have you run ./install.sh?"
exit 1
fi
if [ -z "$1" ]
then
echo "No folder to submarine provided."
exit 1
fi
if [[ ! -d "$1" ]]
then
echo "Folder $1 not found. Exiting."
exit 1
fi
if [[ -z `ls $1` ]]
then
echo "There are no files in $1. Exiting."
exit 1
fi
HERE=`echo "$(realpath $0)" | sed 's|\(.*\)/.*|\1|'`
OUTPUT=`IPFS_PATH=$IPFS_PRIVATE ipfs add --pin=false --recursive --cid-version=1 $1`
FOLDERCID=`echo $OUTPUT | sed 's/.*added bafy/bafy/' | sed 's/ .*//'`
IPFS_PATH=$IPFS_PRIVATE ipfs block get $FOLDERCID > tmp/$FOLDERCID.bin
IPFS_PATH=$IPFS_PRIVATE ipfs repo gc
cat tmp/$FOLDERCID.bin | IPFS_PATH=$IPFS_PUBLIC ipfs dag put --store-codec dag-pb --input-codec dag-pb
IPFS_PATH=$IPFS_PUBLIC ipfs pin add --recursive=false $FOLDERCID
echo "Your folder is now publicly pinned, but you can't see it or the files until you add them individually."
echo
echo "Open the following link to see the folder, but note that the server will hang if you try to view one of the files:"
echo "http://127.0.0.1:5001/ipfs/{{CHANGE_WITH_YOUR}}/#/ipfs/$FOLDERCID"