From 514cdeed2b384336230e2a9edb039c1c8b7864a5 Mon Sep 17 00:00:00 2001 From: fred Date: Sun, 25 Dec 2022 15:39:47 +0100 Subject: [PATCH] function myhost --- specs/astroport_spec.sh | 17 ++++++++++++++++- tools/myhost.sh | 4 ++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/specs/astroport_spec.sh b/specs/astroport_spec.sh index 6beeddc2..9f877db0 100644 --- a/specs/astroport_spec.sh +++ b/specs/astroport_spec.sh @@ -13,7 +13,22 @@ Describe 'Dependency' End Describe 'Astroport' - Describe 'template_register' + Describe 'tools/myhost.sh' + Include ./tools/myhost.sh + myhost() { + echo $myHOST + echo $myIPFS + } + It 'hydrates host env variables' + When call myhost + The output should include astroport. + The output should include ipfs. + The status should be success + The stderr should equal "" + End + End + Describe 'tools/template.sh' + Include ./tools/myhost.sh Include ./tools/template.sh It 'creates host html register page' When call template_register diff --git a/tools/myhost.sh b/tools/myhost.sh index 7217a464..efcad7f7 100755 --- a/tools/myhost.sh +++ b/tools/myhost.sh @@ -9,7 +9,7 @@ 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" +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 @@ -17,4 +17,4 @@ 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 +[ -z "$isLAN" ] && myIPFS="https://ipfs.${myDOMAINName}" && myASTROPORT="https://astroport.${myDOMAINName}" ||: ## WAN STATION