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-26 16:57:24 -03:00
|
|
|
# It accepts optional --index=<int>, --subnet=<subnet>, --serial-speed=<speed>, and --port=<port> arguments
|
|
|
|
# to specify the XBEE_INDEX, BASE_SUBNET, XBEE_BAUDRATE, and XBEE_PORT values.
|
2024-08-22 13:17:24 -03:00
|
|
|
# If no index is provided, it defaults to 1. If no subnet is provided, it defaults to 192.168.1.
|
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-21 10:48:40 -03:00
|
|
|
#
|
|
|
|
# Usage:
|
2024-08-26 16:57:24 -03:00
|
|
|
# ./run-single.sh # Runs with default index (1), default subnet (192.168.1), default speed (230400), and default port (/dev/ttyUSB0)
|
|
|
|
# ./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
|
|
|
|
|
2024-08-21 10:48:40 -03:00
|
|
|
# IPs assigned:
|
2024-08-26 16:57:24 -03:00
|
|
|
# BASE_SUBNET: eg.: 10.10.10
|
|
|
|
# DEFAULT_GATEWAY: ${BASE_SUBNET}.1, eg.: 10.10.10.1
|
|
|
|
# DEFAULT_IPVLAN_IP: ${BASE_SUBNET}.20 eg.: 10.10.10.20
|
|
|
|
# DEFAULT_MACVLAN_IP: ${BASE_SUBNET}.30 eg.: 10.10.10.30
|
|
|
|
# XBEE_NET_SRC_IP: ${BASE_SUBNET}.20${index} eg.: 10.10.10.201 (all Xbnets will be in the 200+ range)
|
2024-08-21 10:48:40 -03:00
|
|
|
|
|
|
|
#!/bin/bash
|
|
|
|
|
2024-08-22 13:17:24 -03:00
|
|
|
# Default values
|
2024-08-26 16:57:24 -03:00
|
|
|
INDEX=1
|
|
|
|
BASE_SUBNET="10.10.10"
|
|
|
|
XBEE_BAUDRATE=230400
|
|
|
|
XBEE_PORT="/dev/ttyUSB0"
|
2024-08-21 10:48:40 -03:00
|
|
|
|
|
|
|
# Parse command-line arguments
|
|
|
|
for arg in "$@"
|
|
|
|
do
|
|
|
|
case $arg in
|
|
|
|
--index=*)
|
2024-08-26 16:57:24 -03:00
|
|
|
INDEX="${arg#*=}"
|
2024-08-21 10:48:40 -03:00
|
|
|
shift # Remove --index=<int> from processing
|
|
|
|
;;
|
2024-08-22 13:17:24 -03:00
|
|
|
--subnet=*)
|
|
|
|
BASE_SUBNET="${arg#*=}"
|
|
|
|
shift # Remove --subnet=<subnet> from processing
|
|
|
|
;;
|
2024-08-26 16:57:24 -03:00
|
|
|
--serial-speed=*)
|
|
|
|
XBEE_BAUDRATE="${arg#*=}"
|
|
|
|
shift # Remove --serial-speed=<speed> from processing
|
|
|
|
;;
|
|
|
|
--port=*)
|
|
|
|
XBEE_PORT="${arg#*=}"
|
|
|
|
shift # Remove --port=<port> from processing
|
|
|
|
;;
|
2024-08-21 10:48:40 -03:00
|
|
|
*)
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
# Create a .env file with the specified parameters
|
|
|
|
cat <<EOF > .env
|
|
|
|
# Base params
|
|
|
|
BASE_SUBNET=${BASE_SUBNET}
|
2024-08-26 16:57:24 -03:00
|
|
|
XBEE_INDEX=${INDEX}
|
2024-08-21 10:48:40 -03:00
|
|
|
|
|
|
|
# Default params
|
|
|
|
DEFAULT_GATEWAY=${BASE_SUBNET}.1
|
|
|
|
DEFAULT_IPVLAN_IP=${BASE_SUBNET}.20 # Required only when running ipvlan net (look in docker compose)
|
|
|
|
DEFAULT_MACVLAN_IP=${BASE_SUBNET}.30 # Required only when running macvlan net (look in docker compose)
|
|
|
|
|
2024-08-26 16:57:24 -03:00
|
|
|
# Configuration for xbnet
|
|
|
|
XBEE_PORT=${XBEE_PORT}
|
|
|
|
XBEE_BAUDRATE=${XBEE_BAUDRATE}
|
|
|
|
XBEE_NET_SRC_IP=${BASE_SUBNET}.20${INDEX} # Ensure this IP matches the network range
|
|
|
|
XBEE_NET_IFACE_NAME=xbnet${INDEX}
|
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
|