# run-single.sh # # This script sets up the environment for running a Docker Compose configuration with XBee networks. # It accepts optional --index= and --subnet= arguments to specify the XBEE_INDEX and BASE_SUBNET values. # If no index is provided, it defaults to 1. If no subnet is provided, it defaults to 192.168.1. # # Usage: # ./run-single.sh # Runs with default index (1) and default subnet (192.168.1) # ./run-single.sh --index=2 # Runs with index 2 and default subnet (192.168.1) # ./run-single.sh --subnet=192.168.50 # Runs with default index (1) and subnet 192.168.50 # ./run-single.sh --index=3 --subnet=192.168.50 # Runs with index 3 and subnet 192.168.50 # # 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 values index=1 BASE_SUBNET="192.168.1" # Parse command-line arguments for arg in "$@" do case $arg in --index=*) index="${arg#*=}" shift # Remove --index= from processing ;; --subnet=*) BASE_SUBNET="${arg#*=}" shift # Remove --subnet= from processing ;; *) ;; esac done # Create a .env file with the specified parameters cat < .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 Compose services docker compose -f docker-compose-run-single.yml down docker compose -f docker-compose-run-single.yml up --build