Merge pull request #736 from jagerman/bootstrap-script-improvements

lokinet-bootstrap improvements
This commit is contained in:
Jeff 2019-07-26 15:35:19 -04:00 committed by GitHub
commit 788ca463c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -6,27 +6,56 @@ RED='\033[0;31m'
GREEN='\033[0;32m' GREEN='\033[0;32m'
NC='\033[0m' # No Color NC='\033[0m' # No Color
set -e
helpme=
default_url="https://i2p.rocks/i2procks.signed"
default_dest="$HOME/.lokinet/bootstrap.signed"
if [ "$#" -gt 2 ]; then
helpme=y
fi
if [ -z "$1" ] if [ -z "$1" ]
then then
url="https://i2p.rocks/i2procks.signed" url="$default_url"
elif [[ "$1" = -* ]]; then
helpme=y
else else
url="$1" url="$1"
fi fi
echo "downloading $url" if [[ "$2" = -* ]]; then
helpme=y
if [ ! -d "$HOME/.lokinet" ] elif [ -n "$2" ]; then
then dest="$2"
mkdir $HOME/.lokinet else
dest="$default_dest"
fi 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 # use temp file to not overrwrite existing bootstrap file on fail
#tmp=mktemp #tmp=mktemp
tmp=/tmp/bootstrap.tmp tmp=/tmp/bootstrap.tmp
# MacOS does not have wget without homebrew but does have curl # MacOS does not have wget without homebrew but does have curl
# Rick also had indicated most BSDs have curl too # Rick also had indicated most BSDs have curl too
curl -o "$tmp" "$url" && \ if curl -L "$url" >"$tmp"; then
(mv "$tmp" "$HOME/.lokinet/bootstrap.signed" && echo -e "${GREEN}lokinet successfully bootstrapped${NC}" ) \ mv "$tmp" "$dest"
|| echo -e "${RED}failed to download bootstrap from $url${NC}" echo -e "${GREEN}lokinet successfully bootstrapped${NC}"
rm -f "$tmp" else
echo -e "${RED}failed to download bootstrap from $url${NC}"
rm -f "$tmp"
exit 1
fi