2018-11-13 13:37:35 +00:00
|
|
|
#!/usr/bin/env bash
|
2018-10-23 11:51:11 +00:00
|
|
|
# this shell script will be replaced by a proper program in the future (probably)
|
|
|
|
#
|
2019-01-16 21:02:54 +00:00
|
|
|
# from https://stackoverflow.com/questions/5947742/how-to-change-the-output-color-of-echo-in-linux
|
2018-12-18 05:52:34 +00:00
|
|
|
RED='\033[0;31m'
|
|
|
|
GREEN='\033[0;32m'
|
|
|
|
NC='\033[0m' # No Color
|
|
|
|
|
2019-07-26 18:38:59 +00:00
|
|
|
set -e
|
|
|
|
|
|
|
|
helpme=
|
2019-12-30 01:12:54 +00:00
|
|
|
default_mainnet=https://seed.lokinet.org/lokinet.signed
|
|
|
|
default_testnet=https://seed.lokinet.org/testnet.signed
|
2019-07-26 18:38:59 +00:00
|
|
|
default_dest="$HOME/.lokinet/bootstrap.signed"
|
|
|
|
|
|
|
|
if [ "$#" -gt 2 ]; then
|
|
|
|
helpme=y
|
|
|
|
fi
|
|
|
|
|
2019-12-30 01:12:54 +00:00
|
|
|
if [ -z "$1" ] || [ "$1" == "mainnet" ] || [ "$1" == "lokinet" ]; then
|
|
|
|
url="${default_mainnet}"
|
|
|
|
elif [ "$1" == "testnet" ]; then
|
|
|
|
url="${default_testnet}"
|
2019-07-26 18:38:59 +00:00
|
|
|
elif [[ "$1" = -* ]]; then
|
|
|
|
helpme=y
|
2018-12-08 04:37:48 +00:00
|
|
|
else
|
|
|
|
url="$1"
|
|
|
|
fi
|
|
|
|
|
2019-07-26 18:38:59 +00:00
|
|
|
if [[ "$2" = -* ]]; then
|
|
|
|
helpme=y
|
|
|
|
elif [ -n "$2" ]; then
|
|
|
|
dest="$2"
|
|
|
|
else
|
|
|
|
dest="$default_dest"
|
|
|
|
fi
|
2018-12-08 04:37:48 +00:00
|
|
|
|
2019-07-26 18:38:59 +00:00
|
|
|
if [ -n "$helpme" ]; then
|
2019-12-15 20:03:38 +00:00
|
|
|
echo "Usage: $0 [URL [DEST]] -- download bootstrap file from URL (default: lokinet) and save to DEST (default: $default_dest)."
|
|
|
|
echo "URL can be a full URL, or else 'lokinet' or 'testnet' to use the default lokinet/testnet seed URL. 'mainnet' can be used"
|
|
|
|
echo "as an alias for 'lokinet'."
|
2019-07-26 18:38:59 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
destdir="$(dirname $dest)"
|
|
|
|
if [ ! -d "$destdir" ]; then
|
|
|
|
mkdir "$destdir"
|
2018-11-21 03:07:34 +00:00
|
|
|
fi
|
2018-12-08 04:37:48 +00:00
|
|
|
|
2019-07-26 18:38:59 +00:00
|
|
|
echo "downloading $url"
|
|
|
|
|
2019-01-07 11:37:15 +00:00
|
|
|
# use temp file to not overrwrite existing bootstrap file on fail
|
2019-03-30 11:40:58 +00:00
|
|
|
#tmp=mktemp
|
|
|
|
tmp=/tmp/bootstrap.tmp
|
2019-01-07 11:37:15 +00:00
|
|
|
|
2018-12-18 05:52:34 +00:00
|
|
|
# MacOS does not have wget without homebrew but does have curl
|
|
|
|
# Rick also had indicated most BSDs have curl too
|
2019-12-15 20:05:27 +00:00
|
|
|
if curl -fsSL "$url" >"$tmp"; then
|
2019-07-26 18:38:59 +00:00
|
|
|
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
|