services-xbee_net/run-single.sh

61 lines
1.8 KiB
Bash
Executable File

# run-single.sh
#
# This script sets up the environment for running a Docker Compose configuration with XBee networks.
# It accepts an optional --index=<int> argument to specify the XBEE_INDEX value.
# If no index is provided, it defaults to 1.
#
# Usage:
# ./run-single.sh # Runs with default index (1)
# ./run-single.sh --index=2 # Runs with index 2
#
# IPs assigned:
# BASE_SUBNET: eg.: 192.168.1
# DEFAULT_GATEWAY: ${BASE_SUBNET}.1, eg.: 192.168.1.1
# DEFAULT_IPVLAN_IP: ${BASE_SUBNET}.20 eg.: 192.168.1.20
# DEFAULT_MACVLAN_IP: ${BASE_SUBNET}.30 eg.: 192.168.1.30
# XBEE_NET_SRC_IP: ${BASE_SUBNET}.20${index} eg.: 192.168.1.201 (all Xbnets will be in the 200+ range)
#!/bin/bash
# Default index value
index=1
# Parse command-line arguments
for arg in "$@"
do
case $arg in
--index=*)
index="${arg#*=}"
shift # Remove --index=<int> from processing
;;
*)
;;
esac
done
# Set BASE_SUBNET
BASE_SUBNET="192.168.1"
# Create a .env file with the specified parameters
cat <<EOF > .env
# Base params
BASE_SUBNET=${BASE_SUBNET}
XBEE_INDEX=${index}
# 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)
# Configuration for xbnet0
XBEE_PORT=/dev/ttyUSB0
XBEE_BAUDRATE=230400
XBEE_NET_SRC_IP=${BASE_SUBNET}.20${index} # Ensure this IP matches the network range
XBEE_NET_IFACE_NAME=xbnet0
EOF
# Restart Docker Composes services
docker compose -f docker-compose-run-single.yml down
docker compose -f docker-compose-run-single.yml up --build