Skip to content
This repository was archived by the owner on Dec 27, 2024. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions start_common.sh
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
# Defaults to TTN server v2, EU region
TTN_STACK_VERSION=${TTN_STACK_VERSION:-2}
TTN_STACK_VERSION=${TTN_STACK_VERSION:-3}
if [ $TTN_STACK_VERSION -eq 2 ]; then
TTN_REGION=${TTN_REGION:-"eu"}
TC_URI=${TC_URI:-"wss://lns.${TTN_REGION}.thethings.network:443"}
TC_TRUST=${TC_TRUST:-$(curl --silent "https://letsencrypt.org/certs/trustid-x3-root.pem.txt")}
elif [ $TTN_STACK_VERSION -eq 3 ]; then
TTN_REGION=${TTN_REGION:-"eu1"}
TC_URI=${TC_URI:-"wss://${TTN_REGION}.cloud.thethings.network:8887"}
TC_TRUST=${TC_TRUST:-$(curl --silent "https://letsencrypt.org/certs/{trustid-x3-root.pem.txt,isrgrootx1.pem}")}
else
echo -e "\033[91mERROR: Wrong TTN_STACK_VERSION value, should be either 2 o 3.\033[0m"
balena-idle
fi

# Get certificate
TC_TRUST=${TC_TRUST:-$(curl --silent "https://letsencrypt.org/certs/{trustid-x3-root.pem.txt,isrgrootx1.pem}")}

# Sanitize TC_TRUST
TC_TRUST=$(echo $TC_TRUST | sed 's/\s//g' | sed 's/-----BEGINCERTIFICATE-----/-----BEGIN CERTIFICATE-----\n/g' | sed 's/-----ENDCERTIFICATE-----/\n-----END CERTIFICATE-----\n/g' | sed 's/\n+/\n/g')

# Check configuration
if [ "$TC_URI" == "" ] || [ "$TC_TRUST" == "" ]
then
Expand All @@ -22,9 +26,6 @@ fi

echo "Server: $TC_URI"

# Sanitize TC_TRUST
#TC_TRUST=$(echo $TC_TRUST | sed 's/-----BEGIN CERTIFICATE-----/-----BEGIN CERTIFICATE-----\n/' | sed 's/-----END CERTIFICATE-----/\n-----END CERTIFICATE-----/' | sed 's/\n\n/\n/g')

# declare map of hardware pins to GPIO on Raspberry Pi
declare -a pinToGPIO
pinToGPIO=( -1 -1 -1 2 -1 3 -1 4 14 -1 15 17 18 27 -1 22 23 -1 24 10 -1 9 25 11 8 -1 7 0 1 5 -1 6 12 13 -1 19 16 26 20 -1 21)
Expand Down