. "${MY_PATH}/tools/myhost.sh"

This commit is contained in:
fred 2022-12-25 17:27:07 +01:00
parent 514cdeed2b
commit 8e7fbfc9c2
4 changed files with 18 additions and 34 deletions

View File

@ -13,20 +13,8 @@ MY_PATH="`dirname \"$0\"`" # relative
MY_PATH="`( cd \"$MY_PATH\" && pwd )`" # absolutized and normalized
ME="${0##*/}"
MOATS=$(date -u +"%Y%m%d%H%M%S%4N")
IPFSNODEID=$(cat ~/.ipfs/config | jq -r .Identity.PeerID)
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
. "${MY_PATH}/tools/myhost.sh"
. "${MY_PATH}/tools/template.sh"
PORT=12345
@ -111,18 +99,11 @@ while true; do
############### ############### ############### ############### templates/index.http
# REPLACE myHOST in http response template (fixing next API meeting point)
echo "$HTTPCORS" > ~/.zen/tmp/coucou/${MOATS}.myHOST.http
cat $HOME/.zen/Astroport.ONE/templates/register.html >> ~/.zen/tmp/coucou/${MOATS}.myHOST.http
sed -i "s~127.0.0.1:12345~${myHOST}:${PORT}~g" ~/.zen/tmp/coucou/${MOATS}.myHOST.http
sed -i "s~http://127.0.0.1:1234~${myASTROPORT}~g" ~/.zen/tmp/coucou/${MOATS}.myHOST.http
sed -i "s~http://127.0.0.1:8080~${myIPFS}~g" ~/.zen/tmp/coucou/${MOATS}.myHOST.http
template_register >> ~/.zen/tmp/coucou/${MOATS}.myHOST.http
sed -i "s~:12345~:${PORT}~g" ~/.zen/tmp/coucou/${MOATS}.myHOST.http
## Random Background image ;)
sed -i "s~.000.~.$(printf '%03d' $(echo ${RANDOM} % 18 | bc)).~g" ~/.zen/tmp/coucou/${MOATS}.myHOST.http
sed -i "s~_SESSIONLNK_~${myIPFS}/ipns/${SESSIONNS}~g" ~/.zen/tmp/coucou/${MOATS}.myHOST.http
sed -i "s~_IPFSNODEID_~${IPFSNODEID}~g" ~/.zen/tmp/coucou/${MOATS}.myHOST.http ## NODE PUBLISH
sed -i "s~_HOSTNAME_~$(hostname)~g" ~/.zen/tmp/coucou/${MOATS}.myHOST.http ## HOSTNAME
sed -i "s~127.0.0.1:12345~${myHOST}:${PORT}~g" ~/.zen/tmp/coucou/${MOATS}.myHOST.http
############### ############### ############### ###############
############################################################################

View File

@ -19,7 +19,7 @@ Describe 'Astroport'
echo $myHOST
echo $myIPFS
}
It 'hydrates host env variables'
It 'does my env variables'
When call myhost
The output should include astroport.
The output should include ipfs.
@ -30,9 +30,12 @@ Describe 'Astroport'
Describe 'tools/template.sh'
Include ./tools/myhost.sh
Include ./tools/template.sh
It 'creates host html register page'
It 'does host html register page'
When call template_register
The output should include $(hostname)
The stdout should include $(hostname)
The stdout should include $IPFSNODEID
The stdout should include $myASTROPORT
The stdout should include $myIPFS
The status should be success
The stderr should equal ""
End

View File

@ -1,8 +1,4 @@
#!/bin/bash
set -eu
MY_PATH="$(pwd -P)" # absolute
ME="${0##*/}"
#shellcheck shell=sh
MOATS=$(date -u +"%Y%m%d%H%M%S%4N")
IPFSNODEID=$(jq -r .Identity.PeerID ~/.ipfs/config)

View File

@ -1,6 +1,10 @@
#!/bin/sh
set -eu
#shellcheck shell=sh
template_register() {
echo $(hostname)
sed -e "s~http://127.0.0.1:1234~${myASTROPORT}~g" \
-e "s~http://127.0.0.1:8080~${myIPFS}~g" \
-e "s~_IPFSNODEID_~${IPFSNODEID}~g" \
-e "s~_HOSTNAME_~$(hostname)~g" \
-e "s~.000.~.$(printf '%03d' $(seq 0 17 |shuf -n 1)).~g" \
~/.zen/Astroport.ONE/templates/register.html
}