forked from Linaro/lite_bootstrap_server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run-server.sh
executable file
·87 lines (68 loc) · 2.53 KB
/
run-server.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/usr/bin/env bash
# Copyright (c) 2022, Linaro. All rights reserved.
# SPDX-License-Identifier: BSD-3-Clause
# Exit on command failure
set -o errexit
# Fail on unset variable
# Use "${VARNAME-}" instead of "$VARNAME" to access unset variable(s)
set -o nounset
# Enable debug mode if $TRACE is set
# To enable, run with: "env TRACE=1 ./run-server.sh"
if [[ "${TRACE-0}" == "1" ]]; then
set -o xtrace
fi
# Check for too many parameters
if [ $# -gt 1 ]
then
echo "Too many paramters provided."
echo "Run './run-server.sh -h' for help."
exit 1
fi
# Check if the first arg is -h or --help
if [[ "${1-}" =~ ^-*h(elp)?$ ]]; then
echo "Usage: ./run-server.sh [hostname]
Starts the bootstrap server and CA.
HOSTNAME
--------
If you wish to use a specific HOSTNAME for the servers, set the correct value
before running this script via one of:
1. Setting the optional [hostname] parameter in this script:
$ ./run-server.sh myhostname.local
2. Adding 'hostname = \"myhostname.local\"' to .liteboot.toml
3. Setting 'CAHOSTNAME' before executing this script:
$ export CAHOSTNAME=myhostname.local
$ ./run-server.sh
NOTE: 'localhost' is useful for testing, particularly if you are behind a NAT,
but won't allow access from a remote device. In order for this server to work
in that network topology, you'll need to set the hostname to a valid DNS name
that resolves to this host.
This hostname must be used consistently in your network layout, since the name
will be included in the generated certificates, and the TLS handshake will fail
if the hostname used by the servers and the value defined in the certificate(s)
don't match.
If you get an error like 'failed: Connection refused', make sure that you are
setting the correct hostname value before running this script.
"
exit
fi
if [ ! -f certs/CA.crt ] || [ ! -f certs/CA.key ]; then
echo "Server certificates not present. Please run ./setup-ca.sh"
exit 1
fi
# Build liteboot if necessary
go build -o liteboot || exit 1
# Run the server, listening by default on port 1443.
if [ $# -eq 1 ]
then
# Use command line parameter for hostname value
./liteboot server start -p 1443 --hostname="$1"
else
# Let liteboot resolve hostname on it's own
./liteboot server start -p 1443
fi
# This will serve web pages from root, and handle REST API requests
# from the `/api/v1` sub-path, with page routing handled in
# `httpserver.go`.
#
# Note: A secondary TCP server is started at the same time to test
# mutual TLS (mTLS) connections. This can be ignored at this point.