2024-08-28 10:36:39 -03:00
|
|
|
#!/bin/bash
|
|
|
|
|
2024-08-21 10:48:40 -03:00
|
|
|
# run-single.sh
|
|
|
|
#
|
|
|
|
# This script sets up the environment for running a Docker Compose configuration with XBee networks.
|
2024-08-28 10:36:39 -03:00
|
|
|
# It accepts optional --index=<int>, --subnet=<subnet>, --serial-speed=<speed>, --port=<port>, and --interface-type=<type> arguments
|
2024-09-03 10:09:03 -03:00
|
|
|
# to specify the XBEE_INDEX, XBNET_BASE_SUBNET, XBEE_BAUDRATE, XBEE_PORT, and XBNET_INTERFACE_TYPE values.
|
|
|
|
# If no index is provided, it defaults to 1. If no subnet is provided, it defaults to 10.10.10.
|
2024-08-26 16:57:24 -03:00
|
|
|
# If no serial-speed is provided, it defaults to 230400. If no port is provided, it defaults to /dev/ttyUSB0.
|
2024-08-28 10:36:39 -03:00
|
|
|
# If no interface-type is provided, it defaults to "router".
|
2024-08-21 10:48:40 -03:00
|
|
|
#
|
|
|
|
# Usage:
|
2024-09-03 10:09:03 -03:00
|
|
|
# ./run-single.sh # Runs with default index (1), default subnet (10.10.10), default speed (230400), and default port (/dev/ttyUSB0)
|
2024-08-28 10:36:39 -03:00
|
|
|
# ./run-single.sh --index=2 # Runs with index 2 and default values for other options
|
|
|
|
# ./run-single.sh --subnet=192.168.50 # Runs with default index (1), specified subnet, and default values for other options
|
|
|
|
# ./run-single.sh --index=3 --subnet=192.168.50 # Runs with specified index, specified subnet, and default values for speed and port
|
|
|
|
# ./run-single.sh --serial-speed=115200 --port=/dev/ttyUSB1 # Runs with specified serial-speed and port with default values for other options
|
|
|
|
# ./run-single.sh --interface-type=gateway # Runs with specified interface type as gateway
|
2024-08-26 16:57:24 -03:00
|
|
|
|
2024-08-22 13:17:24 -03:00
|
|
|
# Default values
|
2024-09-03 10:09:03 -03:00
|
|
|
XBEE_INDEX=1
|
|
|
|
XBNET_BASE_SUBNET="10.10.10"
|
2024-08-26 16:57:24 -03:00
|
|
|
XBEE_BAUDRATE=230400
|
|
|
|
XBEE_PORT="/dev/ttyUSB0"
|
2024-09-03 10:09:03 -03:00
|
|
|
XBNET_INTERFACE_TYPE="router" # Options: ["gateway", "router"]
|
2024-08-21 10:48:40 -03:00
|
|
|
|
|
|
|
# Parse command-line arguments
|
|
|
|
for arg in "$@"
|
|
|
|
do
|
|
|
|
case $arg in
|
|
|
|
--index=*)
|
2024-09-03 10:09:03 -03:00
|
|
|
XBEE_INDEX="${arg#*=}"
|
2024-08-28 10:36:39 -03:00
|
|
|
shift
|
2024-08-21 10:48:40 -03:00
|
|
|
;;
|
2024-08-22 13:17:24 -03:00
|
|
|
--subnet=*)
|
2024-09-03 10:09:03 -03:00
|
|
|
XBNET_BASE_SUBNET="${arg#*=}"
|
2024-08-28 10:36:39 -03:00
|
|
|
shift
|
2024-08-22 13:17:24 -03:00
|
|
|
;;
|
2024-08-26 16:57:24 -03:00
|
|
|
--serial-speed=*)
|
|
|
|
XBEE_BAUDRATE="${arg#*=}"
|
2024-08-28 10:36:39 -03:00
|
|
|
shift
|
2024-08-26 16:57:24 -03:00
|
|
|
;;
|
|
|
|
--port=*)
|
|
|
|
XBEE_PORT="${arg#*=}"
|
2024-08-28 10:36:39 -03:00
|
|
|
shift
|
|
|
|
;;
|
|
|
|
--interface-type=*)
|
2024-09-03 10:09:03 -03:00
|
|
|
XBNET_INTERFACE_TYPE="${arg#*=}"
|
2024-08-28 10:36:39 -03:00
|
|
|
shift
|
2024-08-26 16:57:24 -03:00
|
|
|
;;
|
2024-08-21 10:48:40 -03:00
|
|
|
*)
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2024-08-28 10:36:39 -03:00
|
|
|
# Determine the source IP based on interface type
|
2024-09-03 10:09:03 -03:00
|
|
|
if [ "$XBNET_INTERFACE_TYPE" = "gateway" ]; then
|
|
|
|
XBNET_IP="${XBNET_BASE_SUBNET}.1"
|
|
|
|
XBNET_INTERFACE_NAME="xbnet_gateway"
|
2024-08-28 10:36:39 -03:00
|
|
|
else
|
2024-09-03 10:09:03 -03:00
|
|
|
XBNET_IP="${XBNET_BASE_SUBNET}.20${XBEE_INDEX}"
|
|
|
|
XBNET_INTERFACE_NAME="xbnet_router_${XBEE_INDEX}"
|
2024-08-28 10:36:39 -03:00
|
|
|
fi
|
|
|
|
|
2024-08-21 10:48:40 -03:00
|
|
|
# Create a .env file with the specified parameters
|
|
|
|
cat <<EOF > .env
|
|
|
|
# Base params
|
2024-09-03 10:09:03 -03:00
|
|
|
XBNET_BASE_SUBNET=${XBNET_BASE_SUBNET}
|
|
|
|
XBEE_INDEX=${XBEE_INDEX}
|
2024-08-21 10:48:40 -03:00
|
|
|
|
|
|
|
# Default params
|
2024-09-03 10:09:03 -03:00
|
|
|
XBNET_DEFAULT_GATEWAY=${XBNET_BASE_SUBNET}.1
|
|
|
|
XBNET_DEFAULT_IPVLAN_IP=${XBNET_BASE_SUBNET}.20 # Required only when running ipvlan net (look in docker compose)
|
|
|
|
XBNET_DEFAULT_MACVLAN_IP=${XBNET_BASE_SUBNET}.30 # Required only when running macvlan net (look in docker compose)
|
2024-08-21 10:48:40 -03:00
|
|
|
|
2024-08-26 16:57:24 -03:00
|
|
|
# Configuration for xbnet
|
|
|
|
XBEE_PORT=${XBEE_PORT}
|
|
|
|
XBEE_BAUDRATE=${XBEE_BAUDRATE}
|
2024-09-03 10:09:03 -03:00
|
|
|
XBNET_IP=${XBNET_IP} # Set based on interface type
|
|
|
|
XBNET_INTERFACE_NAME=${XBNET_INTERFACE_NAME} # Set based on interface type
|
2024-08-21 10:48:40 -03:00
|
|
|
EOF
|
|
|
|
|
2024-08-22 13:17:24 -03:00
|
|
|
# Restart Docker Compose services
|
2024-08-21 10:48:40 -03:00
|
|
|
docker compose -f docker-compose-run-single.yml down
|
|
|
|
docker compose -f docker-compose-run-single.yml up --build
|