Make install.sh idempotent - safe to rerun

main
Ryan Collier 3 months ago
parent 02308c2c2a
commit 4e3f4d1bd4

@ -36,69 +36,107 @@ echo ""
source "$REPO_DIR/sites/$SITE/site.conf" source "$REPO_DIR/sites/$SITE/site.conf"
# Install dependencies # Install dependencies
echo "Installing dependencies..." if ! dpkg -l | grep -q nlohmann-json3-dev; then
apt-get update -qq echo "Installing dependencies..."
apt-get install -y git build-essential nlohmann-json3-dev libssl-dev python3 libmosquitto-dev 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 # Install ZeroTier
echo "Installing ZeroTier..." if ! command -v zerotier-cli &>/dev/null; then
curl -s https://install.zerotier.com | bash echo "Installing ZeroTier..."
zerotier-cli join $ZEROTIER_NETWORK curl -s https://install.zerotier.com | bash
echo "ZeroTier installed and joined network $ZEROTIER_NETWORK" zerotier-cli join $ZEROTIER_NETWORK
echo "" echo "ZeroTier installed and joined network $ZEROTIER_NETWORK"
echo "NOTE: Approve this device in ZeroTier Central before continuing" echo ""
read -p "Press ENTER once device is approved..." 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 # 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" CONFIG_FILE="/boot/firmware/config.txt"
if [ ! -f "$CONFIG_FILE" ]; then if [ ! -f "$CONFIG_FILE" ]; then
CONFIG_FILE="/boot/config.txt" CONFIG_FILE="/boot/config.txt"
fi fi
# Disable Bluetooth and enable UART for MMDVM board
if ! grep -q "dtoverlay=disable-bt" "$CONFIG_FILE"; then if ! grep -q "dtoverlay=disable-bt" "$CONFIG_FILE"; then
echo "Configuring serial port..."
echo "" >> "$CONFIG_FILE" echo "" >> "$CONFIG_FILE"
echo "# MMDVM Board - disable BT, enable hardware UART" >> "$CONFIG_FILE" echo "# MMDVM Board - disable BT, enable hardware UART" >> "$CONFIG_FILE"
echo "dtoverlay=disable-bt" >> "$CONFIG_FILE" echo "dtoverlay=disable-bt" >> "$CONFIG_FILE"
echo "enable_uart=1" >> "$CONFIG_FILE" echo "enable_uart=1" >> "$CONFIG_FILE"
echo "Serial port configured in $CONFIG_FILE" echo "Serial port configured in $CONFIG_FILE"
else
echo "Serial port already configured, skipping..."
fi fi
# Disable serial console so Linux doesn't use the UART # Disable serial console
echo "Disabling serial console..." if systemctl is-enabled serial-getty@ttyAMA0.service &>/dev/null; then
systemctl stop serial-getty@ttyAMA0.service 2>/dev/null || true echo "Disabling serial console..."
systemctl disable serial-getty@ttyAMA0.service 2>/dev/null || true 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" CMDLINE_FILE="/boot/firmware/cmdline.txt"
if [ ! -f "$CMDLINE_FILE" ]; then if [ ! -f "$CMDLINE_FILE" ]; then
CMDLINE_FILE="/boot/cmdline.txt" CMDLINE_FILE="/boot/cmdline.txt"
fi fi
sed -i 's/console=serial0,[0-9]* //' "$CMDLINE_FILE" if grep -q "console=serial0\|console=ttyAMA0" "$CMDLINE_FILE"; then
sed -i 's/console=ttyAMA0,[0-9]* //' "$CMDLINE_FILE" sed -i 's/console=serial0,[0-9]* //' "$CMDLINE_FILE"
echo "Serial console removed from $CMDLINE_FILE" sed -i 's/console=ttyAMA0,[0-9]* //' "$CMDLINE_FILE"
echo "Serial console removed from $CMDLINE_FILE"
fi
# Add pi user to dialout # Add pi user to dialout
usermod -a -G dialout pi usermod -a -G dialout pi 2>/dev/null || true
# Clone MMDVMHost if not present # Clone MMDVMHost if not present
if [ ! -d "$MMDVM_SOURCE_DIR" ]; then if [ ! -d "$MMDVM_SOURCE_DIR" ]; then
echo "Cloning MMDVMHost..." echo "Cloning MMDVMHost..."
git clone "$MMDVM_REPO" "$MMDVM_SOURCE_DIR" git clone "$MMDVM_REPO" "$MMDVM_SOURCE_DIR"
else
echo "MMDVMHost source already present, skipping clone..."
fi fi
# Copy patched source files # Copy patched source files and apply patches
echo "Applying patches..." if ! grep -q "writeRegister" "$MMDVM_SOURCE_DIR/DStarNetwork.cpp"; then
cp "$REPO_DIR/src/DStarNetwork.cpp" "$MMDVM_SOURCE_DIR/" echo "Copying patched source files..."
cp "$REPO_DIR/src/DStarNetwork.h" "$MMDVM_SOURCE_DIR/" cp "$REPO_DIR/src/DStarNetwork.cpp" "$MMDVM_SOURCE_DIR/"
cp "$REPO_DIR/src/Conf.h" "$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" 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 # Compile
echo "Compiling MMDVMHost..." echo "Compiling MMDVMHost..."
@ -138,12 +176,22 @@ echo ""
echo "ZeroTier status:" echo "ZeroTier status:"
zerotier-cli status zerotier-cli status
echo "" echo ""
echo "A reboot is required to activate serial port changes."
echo "" # Only prompt reboot if serial config was changed
read -p "Reboot now? [y/N]: " REBOOT if ! systemctl is-active mmdvmhost &>/dev/null; then
if [ "$REBOOT" = "y" ] || [ "$REBOOT" = "Y" ]; 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 reboot
else else
echo "Run 'sudo reboot' when ready." echo "Run 'sudo reboot' when ready."
echo "MMDVMHost will start automatically after reboot." 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 fi

Loading…
Cancel
Save

Powered by TurnKey Linux.