A shell script to create and configure multiple independent instances of DVSwitch for DMR operation. This script automates the creation of separate configurations, systemd services, and port assignments for each instance.
This script creates isolated DVSwitch instances (2 through 5) by:
- Copying and configuring MMDVM_Bridge, DVSwitch, and Analog_Bridge configuration files
- Creating unique port assignments for each instance (automatically checked for availability)
- Generating systemd service files for each instance
- Setting up separate log directories
- Enabling and starting the services
Download the script directly from the repository:
wget https://raw.githubusercontent.com/hardenedpenguin/dvswitch_instance/refs/heads/main/dvswitch_instance.sh
chmod +x dvswitch_instance.sh- Root or sudo access (required for systemd and file operations)
- DVSwitch already installed with default configurations:
/opt/MMDVM_Bridge/MMDVM_Bridge.ini/opt/MMDVM_Bridge/DVSwitch.ini/opt/Analog_Bridge/Analog_Bridge.ini
- Systemd service files present:
/lib/systemd/system/mmdvm_bridge.service/lib/systemd/system/analog_bridge.service/lib/systemd/system/md380-emu.service
ssornetstatcommand available (for port checking)- An editor configured via
$EDITORenvironment variable (defaults tonano)
sudo ./dvswitch_instance.sh <instance_number># Create instance 2
sudo ./dvswitch_instance.sh 2
# Create instance 3
sudo ./dvswitch_instance.sh 3Note: Instance numbers must be between 2 and 5 (inclusive).
- Configuration:
/etc/dvswitch/<instance>/ - Logs:
/var/log/mmdvm<instance>/and/var/log/dvswitch<instance>/
The script copies (if they don't already exist):
MMDVM_Bridge.ini→/etc/dvswitch/<instance>/MMDVM_Bridge.iniDVSwitch.ini→/etc/dvswitch/<instance>/DVSwitch.iniAnalog_Bridge.ini→/etc/dvswitch/<instance>/Analog_Bridge.ini
Automatically disables all modes except DMR in MMDVM_Bridge.ini, then enables:
- DMR mode
- DMR Network
The script dynamically assigns ports for each instance, ensuring no conflicts:
| Port Type | Base Port | Instance Offset | Calculation |
|---|---|---|---|
| DMR TX | 31100 | +20 per instance | 31100 + (instance-1)*20 + offset*2 |
| DMR RX | DMR TX + 3 | N/A | Calculated from DMR TX |
| USRP TX | 32001 | +20 per instance | 32001 + (instance-1)*20 + offset*2 |
| USRP RX | USRP TX + 2000 | N/A | Calculated from USRP TX |
| Local | 62032 | +20 per instance | 62032 + (instance-1)*20 + offset*2 |
| Emulator | 2470 | +20 per instance | 2470 + (instance-1)*20 + offset*2 |
Example for Instance 2:
- Instance offset:
(2-1) * 20 = 20 - DMR TX Port:
31100 + 20 = 31120(if available) - DMR RX Port:
31120 + 3 = 31123 - USRP TX Port:
32001 + 20 = 32021(if available) - USRP RX Port:
32021 + 2000 = 34021
The script checks port availability before assignment and will find an available port if the calculated port is in use.
For each configuration file, the script will:
- Display the specific values that need to be set
- Prompt you to press Enter
- Open the file in your default editor (
$EDITORornano)
MMDVM_Bridge.ini:
- Id: Unique ID for this instance
- [Log] -> FilePath:
/var/log/mmdvm<instance> - [DMR Network] -> Local: Assigned local port
DVSwitch.ini:
- [DMR] -> TXPort: Assigned DMR TX port
- [DMR] -> RXPort: Assigned DMR RX port
- [DMR] -> exportTG: Your talkgroup
- [STFU] -> StartTG: Brandmeister talkgroup (if needed)
Analog_Bridge.ini:
- [GENERAL]emulatorAddress:
127.0.0.1:<emulator_port> - [AMBE_AUDIO]Ports:
txPort = <DMR_RX_PORT>,rxPort = <DMR_TX_PORT> - ambeMod: DMR
- repeaterID: Match essid
- txTg: Default talkgroup (optional)
- [USRP] -> txPort/rxPort: Assigned USRP TX/RX ports
For each service (mmdvm_bridge, analog_bridge, md380-emu), the script:
- Copies the base service file from
/lib/systemd/system/to/etc/systemd/system/ - Appends the instance number to the service name (e.g.,
mmdvm_bridge2.service) - Updates paths, ports, and log directories specific to the instance
- Reloads systemd daemon
After you confirm all configuration files are edited, the script:
- Enables all three services for the instance
- Starts all three services
- Displays confirmation messages
After the script completes, you need to:
- Create the second public node by running
sudo asl-menu - Set up the node for USRP (no private node needed)
- Configure the rxchannel to match your instance ports:
rxchannel = USRP/127.0.0.1:<USRP_RX_PORT>:<USRP_TX_PORT>
The script will display the exact rxchannel value before exiting.
After installation, manage your instance services with:
# Check status
sudo systemctl status mmdvm_bridge<instance>.service
sudo systemctl status analog_bridge<instance>.service
sudo systemctl status md380-emu<instance>.service
# Stop services
sudo systemctl stop mmdvm_bridge<instance>.service analog_bridge<instance>.service md380-emu<instance>.service
# Restart services
sudo systemctl restart mmdvm_bridge<instance>.service analog_bridge<instance>.service md380-emu<instance>.service- The script is currently configured for DMR mode only. It can be modified to support other modes (D-STAR, YSF, P25, etc.).
- Port assignments are checked automatically to prevent conflicts with existing services.
- Configuration files are only copied if they don't already exist (won't overwrite existing configs).
- Each instance is completely isolated with its own configuration, logs, and ports.
Copyright (C) 2025 Jory A. Pratt - W5GLE
Released under the GNU General Public License v2 or later.
