forked from victorb/ipfscrape
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.sh
executable file
·52 lines (37 loc) · 1.49 KB
/
run.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
#! /usr/bin/env bash
RED="$(tput setaf 1 2>/dev/null || :)"
GREEN="$(tput setaf 2 2>/dev/null || :)"
BLUE="$(tput setaf 4 2>/dev/null || :)"
NC="$(tput sgr0 2>/dev/null || :)"
command -v ipfs >/dev/null 2>&1 || { echo -e >&2 "${RED}You need \"IPFS\" but it was not found.${NC} Aborting..."; exit 1; }
command -v wget >/dev/null 2>&1 || { echo -e >&2 "${RED}You need \"wget\" but it was not found.${NC} Aborting..."; exit 1; }
# Just to check if we're online or not
ipfs swarm peers >& /dev/null
RETVAL=$?
[ $RETVAL -ne 0 ] && echo -e "${RED}You need to have the IPFS daemon running! ${NC} Aborting..." && exit 1
set -e
set -o pipefail
URL=$1
echo ""
echo -e "${GREEN}Dumping \"$URL\" into IPFS${NC}"
echo -e "${BLUE}"
mkdir -p /tmp/ipfscrape/site
cd /tmp/ipfscrape/site
wget -q --show-progress --page-requisites --html-extension --convert-links --random-wait -e robots=off -nd --span-hosts $URL || true
test -f index.html || {
INDEX_FILE=$(ls -S | grep -i .html | head -n1)
echo "Moving $INDEX_FILE to index.html"
mv /tmp/ipfscrape/site/$INDEX_FILE /tmp/ipfscrape/site/index.html
}
ipfs add -r . > ipfs_log
HASH=$(tail -n 1 ipfs_log | cut -d ' ' -f 2)
[ "$HASH" = "" ] && echo -e "${RED}Didn't add anything to IPFS...?! :'( ${NC} Aborting..." && exit 1
echo -e "${NC}"
echo "###############"
echo -e "## ${GREEN}DUMP COMPLETE${NC}"
echo "##"
echo "## Urls:"
echo -e "## ${BLUE}http://localhost:8080/ipfs/$HASH${NC}"
echo -e "## ${BLUE}https://ipfs.io/ipfs/$HASH${NC}"
echo ""
rm -rf /tmp/ipfscrape/site