diff --git a/Makefile b/Makefile index 67b7b72c..59de963b 100644 --- a/Makefile +++ b/Makefile @@ -37,16 +37,25 @@ player-%: $(call make,stack-User-$*,$(MYOS),$(PLAYER_MAKE_VARS)) \ ) -.PHONY: shellcheck -shellcheck: +.PHONY: upgrade +upgrade: migrate-home migrate-ipfs install + +## TESTS + +.PHONY: check +check: shellcheck $(SHELL_FILES) ||: .PHONY: shellcheck-% shellcheck-%: shellcheck $*/*.sh -.PHONY: tests -tests: shellcheck +.PHONY: shellspec +specs: shellspec-specs; -.PHONY: upgrade -upgrade: migrate-home migrate-ipfs install +.PHONY: shellspec-% +shellspec-%: + shellspec -f tap $* + +.PHONY: tests +tests: check specs diff --git a/specs/astroport_spec.sh b/specs/astroport_spec.sh new file mode 100644 index 00000000..6beeddc2 --- /dev/null +++ b/specs/astroport_spec.sh @@ -0,0 +1,25 @@ +#shellcheck shell=sh +set -eu + +Describe 'Dependency' + Describe 'ipfs:' + It 'is available' + When run ipfs --help + The output should include "ipfs" + The status should be success + The stderr should equal "" + End + End +End + +Describe 'Astroport' + Describe 'template_register' + Include ./tools/template.sh + It 'creates host html register page' + When call template_register + The output should include $(hostname) + The status should be success + The stderr should equal "" + End + End +End diff --git a/tools/myhost.sh b/tools/myhost.sh new file mode 100755 index 00000000..7217a464 --- /dev/null +++ b/tools/myhost.sh @@ -0,0 +1,20 @@ +#!/bin/bash +set -eu + +MY_PATH="$(pwd -P)" # absolute +ME="${0##*/}" + +MOATS=$(date -u +"%Y%m%d%H%M%S%4N") +IPFSNODEID=$(jq -r .Identity.PeerID ~/.ipfs/config) +myIP=$(hostname -I | awk '{print $1}' | head -n 1) +isLAN=$(route -n |awk '$1 == "0.0.0.0" {print $2}' | grep -E "/(^127\.)|(^192\.168\.)|(^10\.)|(^172\.1[6-9]\.)|(^172\.2[0-9]\.)|(^172\.3[0-1]\.)|(^::1$)|(^[fF][cCdD])/") + +myDOMAINName=$(hostname -d 2>/dev/null) && [ -z "$myDOMAINName" ] && myDOMAINName=$(domainname 2>/dev/null) && [[ "$myDOMAINName" == "(none)" ]] && myDOMAINName="localhost" +myHOSTName=$(hostname |sed 's/\.'${myDOMAINName}'$//') +[ -n "$myDOMAINName" ] && myHOSTName="${myHOSTName}.${myDOMAINName}" || myDOMAINName=${myHOSTName#*.} +[ -z "$myDOMAINName" ] && myDOMAINName=localhost +myHOST="astroport.${myDOMAINName}" +myIPFS="http://ipfs.${myDOMAINName}:8080" +myASTROPORT="http://astroport.${myDOMAINName}:1234" + +[[ ! $isLAN || $USER == "zen" ]] && myIPFS="https://ipfs.${myDOMAINName}" && myASTROPORT="https://astroport.${myDOMAINName}" ## WAN STATION diff --git a/tools/template.sh b/tools/template.sh new file mode 100755 index 00000000..2fbd758c --- /dev/null +++ b/tools/template.sh @@ -0,0 +1,6 @@ +#!/bin/sh +set -eu + +template_register() { + echo $(hostname) +}