You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

198 lines
6.0 KiB

#!/bin/bash
# D-Star Site Install Script
# For Raspberry Pi 3B running Raspberry Pi OS Lite (64-bit)
# Usage: sudo bash install.sh
set -e
REPO_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
MMDVM_SOURCE_DIR="/home/pi/MMDVM-Host"
MMDVM_REPO="https://github.com/g4klx/MMDVMHost.git"
ZEROTIER_NETWORK="c5029fdad4ccf9c5"
echo "================================================"
echo " D-Star Site Installer"
echo "================================================"
echo ""
# Select site
echo "Available sites: $(ls $REPO_DIR/sites/ | grep -v template)"
echo ""
read -p "Enter site name (max 8 chars): " SITE
SITE="${SITE^^}" # force uppercase
SITE="${SITE:0:8}" # limit to 8 chars
if [ ! -d "$REPO_DIR/sites/$SITE" ]; then
echo "ERROR: Site '$SITE' not found"
echo "Available sites: $(ls $REPO_DIR/sites/ | grep -v template)"
exit 1
fi
echo ""
echo "Installing site: $SITE"
echo ""
# Load site config
source "$REPO_DIR/sites/$SITE/site.conf"
# Install dependencies
if ! dpkg -l | grep -q nlohmann-json3-dev; then
echo "Installing dependencies..."
apt-get update -qq
apt-get install -y git build-essential nlohmann-json3-dev libssl-dev python3 libmosquitto-dev
else
echo "Dependencies already installed, skipping..."
fi
# Install ZeroTier
if ! command -v zerotier-cli &>/dev/null; then
echo "Installing ZeroTier..."
curl -s https://install.zerotier.com | bash
zerotier-cli join $ZEROTIER_NETWORK
echo "ZeroTier installed and joined network $ZEROTIER_NETWORK"
echo ""
echo "NOTE: Approve this device in ZeroTier Central before continuing"
read -p "Press ENTER once device is approved..."
else
echo "ZeroTier already installed, skipping..."
# Make sure we're joined to the network
if ! zerotier-cli listnetworks | grep -q $ZEROTIER_NETWORK; then
zerotier-cli join $ZEROTIER_NETWORK
echo "Joined ZeroTier network $ZEROTIER_NETWORK"
read -p "Approve device in ZeroTier Central then press ENTER..."
else
echo "Already joined ZeroTier network $ZEROTIER_NETWORK"
fi
fi
# Configure serial port for MMDVM board
CONFIG_FILE="/boot/firmware/config.txt"
if [ ! -f "$CONFIG_FILE" ]; then
CONFIG_FILE="/boot/config.txt"
fi
if ! grep -q "dtoverlay=disable-bt" "$CONFIG_FILE"; then
echo "Configuring serial port..."
echo "" >> "$CONFIG_FILE"
echo "# MMDVM Board - disable BT, enable hardware UART" >> "$CONFIG_FILE"
echo "dtoverlay=disable-bt" >> "$CONFIG_FILE"
echo "enable_uart=1" >> "$CONFIG_FILE"
echo "Serial port configured in $CONFIG_FILE"
else
echo "Serial port already configured, skipping..."
fi
# Disable serial console
if systemctl is-enabled serial-getty@ttyAMA0.service &>/dev/null; then
echo "Disabling serial console..."
systemctl stop serial-getty@ttyAMA0.service 2>/dev/null || true
systemctl disable serial-getty@ttyAMA0.service 2>/dev/null || true
else
echo "Serial console already disabled, skipping..."
fi
CMDLINE_FILE="/boot/firmware/cmdline.txt"
if [ ! -f "$CMDLINE_FILE" ]; then
CMDLINE_FILE="/boot/cmdline.txt"
fi
if grep -q "console=serial0\|console=ttyAMA0" "$CMDLINE_FILE"; then
sed -i 's/console=serial0,[0-9]* //' "$CMDLINE_FILE"
sed -i 's/console=ttyAMA0,[0-9]* //' "$CMDLINE_FILE"
echo "Serial console removed from $CMDLINE_FILE"
fi
# Add pi user to dialout
usermod -a -G dialout pi 2>/dev/null || true
# Clone MMDVMHost if not present
if [ ! -d "$MMDVM_SOURCE_DIR" ]; then
echo "Cloning MMDVMHost..."
git clone "$MMDVM_REPO" "$MMDVM_SOURCE_DIR"
else
echo "MMDVMHost source already present, skipping clone..."
fi
# Copy patched source files and apply patches
if ! grep -q "writeRegister" "$MMDVM_SOURCE_DIR/DStarNetwork.cpp"; then
echo "Copying patched source files..."
cp "$REPO_DIR/src/DStarNetwork.cpp" "$MMDVM_SOURCE_DIR/"
cp "$REPO_DIR/src/DStarNetwork.h" "$MMDVM_SOURCE_DIR/"
cp "$REPO_DIR/src/Conf.h" "$MMDVM_SOURCE_DIR/"
else
echo "DStarNetwork already patched, skipping..."
fi
cd "$MMDVM_SOURCE_DIR"
if ! grep -q "m_dstarNetworkName" Conf.cpp; then
echo "Patching Conf.cpp..."
python3 "$REPO_DIR/src/patch_conf_cpp.py"
else
echo "Conf.cpp already patched, skipping..."
fi
if ! grep -q "getDStarNetworkName" MMDVM-Host.cpp; then
echo "Patching MMDVM-Host.cpp..."
python3 "$REPO_DIR/src/patch_mmdvm_host_cpp.py"
else
echo "MMDVM-Host.cpp already patched, skipping..."
fi
# Compile
echo "Compiling MMDVMHost..."
make -j$(nproc)
# Install binary
echo "Installing binary..."
cp MMDVM-Host /usr/local/bin/MMDVM-Host
chmod 755 /usr/local/bin/MMDVM-Host
# Generate config from template
echo "Generating config for $SITE..."
sed \
-e "s/%%CALLSIGN%%/$CALLSIGN/g" \
-e "s/%%MODULE%%/$MODULE/g" \
-e "s/%%SITE_NAME%%/$SITE_NAME/g" \
-e "s/%%GATEWAY_ADDRESS%%/$GATEWAY_ADDRESS/g" \
-e "s/%%GATEWAY_PORT%%/$GATEWAY_PORT/g" \
-e "s/%%LOCAL_PORT%%/$LOCAL_PORT/g" \
-e "s/%%MODEM_PORT%%/$MODEM_PORT/g" \
-e "s/%%MODEM_SPEED%%/$MODEM_SPEED/g" \
"$REPO_DIR/sites/mmdvmhost.template" > /etc/mmdvmhost
echo "Config written to /etc/mmdvmhost"
# Install service
echo "Installing systemd service..."
cp "$REPO_DIR/services/mmdvmhost.service" /etc/systemd/system/
systemctl daemon-reload
systemctl enable mmdvmhost
echo ""
echo "================================================"
echo " Installation complete for site: $SITE"
echo "================================================"
echo ""
echo "ZeroTier status:"
zerotier-cli status
echo ""
# Only prompt reboot if serial config was changed
if ! systemctl is-active mmdvmhost &>/dev/null; then
echo "A reboot is required to activate serial port changes."
echo ""
read -p "Reboot now? [y/N]: " REBOOT
if [ "$REBOOT" = "y" ] || [ "$REBOOT" = "Y" ]; then
reboot
else
echo "Run 'sudo reboot' when ready."
echo "MMDVMHost will start automatically after reboot."
fi
else
echo "Restarting MMDVMHost..."
systemctl restart mmdvmhost
echo ""
echo "Service status:"
systemctl status mmdvmhost --no-pager
fi

Powered by TurnKey Linux.