Make install.sh idempotent - safe to rerun

main
Ryan Collier 2 weeks ago
parent 02308c2c2a
commit 4e3f4d1bd4

@ -36,69 +36,107 @@ echo ""
source "$REPO_DIR/sites/$SITE/site.conf"
# Install dependencies
echo "Installing dependencies..."
apt-get update -qq
apt-get install -y git build-essential nlohmann-json3-dev libssl-dev python3 libmosquitto-dev
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
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..."
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
echo "Configuring serial port..."
# Modern Pi OS - config in /boot/firmware/config.txt
CONFIG_FILE="/boot/firmware/config.txt"
if [ ! -f "$CONFIG_FILE" ]; then
CONFIG_FILE="/boot/config.txt"
fi
# Disable Bluetooth and enable UART for MMDVM board
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 so Linux doesn't use the UART
echo "Disabling serial console..."
systemctl stop serial-getty@ttyAMA0.service 2>/dev/null || true
systemctl disable serial-getty@ttyAMA0.service 2>/dev/null || true
# 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
# Remove serial console from cmdline.txt
CMDLINE_FILE="/boot/firmware/cmdline.txt"
if [ ! -f "$CMDLINE_FILE" ]; then
CMDLINE_FILE="/boot/cmdline.txt"
fi
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"
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
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
echo "Applying patches..."
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/"
# 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"
python3 "$REPO_DIR/src/patch_conf_cpp.py"
python3 "$REPO_DIR/src/patch_mmdvm_host_cpp.py"
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..."
@ -138,12 +176,22 @@ echo ""
echo "ZeroTier status:"
zerotier-cli status
echo ""
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
# 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 "Run 'sudo reboot' when ready."
echo "MMDVMHost will start automatically after reboot."
echo "Restarting MMDVMHost..."
systemctl restart mmdvmhost
echo ""
echo "Service status:"
systemctl status mmdvmhost --no-pager
fi

Loading…
Cancel
Save

Powered by TurnKey Linux.