forked from oxen-io/lokinet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lokinet-bootstrap
executable file
·61 lines (51 loc) · 1.29 KB
/
lokinet-bootstrap
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
61
#!/usr/bin/env bash
# this shell script will be replaced by a proper program in the future (probably)
#
# from https://stackoverflow.com/questions/5947742/how-to-change-the-output-color-of-echo-in-linux
RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m' # No Color
set -e
helpme=
default_url="https://seed.lokinet.org/bootstrap.signed"
default_dest="$HOME/.lokinet/bootstrap.signed"
if [ "$#" -gt 2 ]; then
helpme=y
fi
if [ -z "$1" ]
then
url="$default_url"
elif [[ "$1" = -* ]]; then
helpme=y
else
url="$1"
fi
if [[ "$2" = -* ]]; then
helpme=y
elif [ -n "$2" ]; then
dest="$2"
else
dest="$default_dest"
fi
if [ -n "$helpme" ]; then
echo "Usage: $0 [URL [DEST]] -- download bootstrap file from URL (default: $default_url) and save to DEST (default: $default_dest)."
exit 1
fi
destdir="$(dirname $dest)"
if [ ! -d "$destdir" ]; then
mkdir "$destdir"
fi
echo "downloading $url"
# use temp file to not overrwrite existing bootstrap file on fail
#tmp=mktemp
tmp=/tmp/bootstrap.tmp
# MacOS does not have wget without homebrew but does have curl
# Rick also had indicated most BSDs have curl too
if curl -L "$url" >"$tmp"; then
mv "$tmp" "$dest"
echo -e "${GREEN}lokinet successfully bootstrapped${NC}"
else
echo -e "${RED}failed to download bootstrap from $url${NC}"
rm -f "$tmp"
exit 1
fi