#!/bin/bash ####------------------- Pre-Flight Checks # Exit on error set -e # Check if the script is run as root if [[ $(id -u) -ne 0 ]]; then echo "Please run this script as root." exit 1 fi # Check if the working directory is 'client' and contains package.json if [[ ! -f "$(pwd)/package.json" ]]; then echo "Error: Please make sure the working directory is 'client' and contains package.json." exit 1 fi ####------------------- Functions # Function to prompt user for input with a specific message and store the result in a variable prompt_user() { read -p "$1: " input echo "$input" } # Function to prompt user for capabilities options and store the result in a variable prompt_capabilities() { default_capabilities="radio" # Default value read -p "Select CLIENT_CAPABILITIES (comma-separated, default: $default_capabilities): " capabilities capabilities="${capabilities:-$default_capabilities}" # Use default value if input is empty echo "$capabilities" } # Function to prompt user for nearby systems details prompt_nearby_system() { local system_name="" local frequencies="" local mode="" local trunk_file="" local whitelist_file="" read -p "Enter system name: " system_name read -p "Enter frequencies (comma-separated): " frequencies read -p "Enter mode (p25/nbfm): " mode if [[ "$mode" == "p25" ]]; then read -p "Enter trunk file: " trunk_file read -p "Enter whitelist file: " whitelist_file fi echo "\"$system_name\": { \"frequencies\": [\"$(echo "$frequencies" | sed 's/,/","/g')\"], \"mode\": \"$mode\", \"trunkFile\": \"$trunk_file\", \"whitelistFile\": \"$whitelist_file\" }," } ####------------------- Initial Prereqs and init steps # Update the system echo "Updating system..." apt update && apt upgrade -y # Install required dependencies: nodejs, ffmpeg echo "Installing dependencies..." apt install -y nodejs ffmpeg git ####------------------- Install and setup node # Run npm install to install dependencies listed in package.json echo "Installing npm dependencies..." npm install # Generate .env file echo "# Client Config" > .env echo "CLIENT_NUID=0" >> .env client_name=$(prompt_user "Enter the name for this node") echo "CLIENT_NAME=$client_name" >> .env client_location=$(prompt_user "Enter the location of this node") echo "CLIENT_LOCATION=$client_location" >> .env client_capabilities=$(prompt_capabilities) echo "CLIENT_CAPABILITIES=$client_capabilities" >> .env # Server configuration (preset values) echo "" >> .env echo "# Configuration for the connection to the server" >> .env echo "SERVER_IP=vpn.cusano.net" >> .env echo "SERVER_PORT=3000" >> .env # OP25 configuration (preset values) echo "" >> .env echo "# Configuration for OP25" >> .env op25_full_path="$(pwd)/op25/op25/gr-op25_repeater/apps" # Update this with the actual path echo "OP25_FULL_PATH=$op25_full_path" >> .env # Core configuration (preset value) echo "" >> .env echo "# Core config, DO NOT TOUCH UNLESS YOU KNOW WHAT YOU ARE DOING" >> .env echo "CONFIG_PATH=./config/radioPresets.json" >> .env echo ".env file generated successfully." # Create a JSON object to store nearby systems systems_json="{" while true; do systems_json+="$(prompt_nearby_system)" read -p "Do you want to add another system? (yes/no): " choice if [[ "$choice" != "yes" ]]; then break fi done systems_json="${systems_json%,}" # Remove trailing comma systems_json+="}" # Append the created systems to the presets file mkdir -p ./config echo "$systems_json" >> "./config/radioPresets.json" echo "Systems added to radioPresets.json." # Create a systemd service file echo "Adding DRB Node service..." service_content="[Unit] Description=Discord-Radio-Bot_v3 After=syslog.target network.target nss-lookup.target network-online.target Requires=network-online.target [Service] User=1000 Group=1000 WorkingDirectory=$(pwd) ExecStart=/bin/bash -- serviceStart.sh RestartSec=5 Restart=on-failure [Install] WantedBy=multi-user.target" # Write the systemd service file echo "$service_content" > /etc/systemd/system/discord-radio-bot.service # Reload systemd daemon systemctl daemon-reload systemctl stop discord-radio-bot.service echo "\n\n\t\tDiscord Client Node install completed!\n\n" ####------------------- OP25 Installation # Clone OP25 from the git repository echo "Cloning OP25 from the git repository..." git clone https://github.com/boatbod/op25.git # Navigate to the OP25 directory cd op25 # Edit the startup script to use the active.cfg.json config file generated by the app echo "Editing startup script..." sed -i 's/p25_rtl_example.json/active.cfg.json/g' op25-multi_rx.sh # Move the startup script to the apps dir mv op25-multi_rx.sh op25/gr-op25_repeater/apps/ # Install the OP25 service echo "Adding OP25 service..." service_content="[Unit] Description=op25-multi_rx After=syslog.target network.target nss-lookup.target network-online.target Requires=network-online.target [Service] User=1000 Group=1000 WorkingDirectory=$(pwd)/op25/gr-op25_repeater/apps ExecStart=/bin/bash -- op25-multi_rx.sh RestartSec=5 Restart=on-failure [Install] WantedBy=multi-user.target" # Write the systemd service file echo "$service_content" > /etc/systemd/system/op25-multi_rx.service # Reload systemd daemon systemctl daemon-reload systemctl stop op25-multi_rx.service # Install OP25 using the provided installation script echo "Installing OP25..." ./install.sh echo "\n\n\t\tOP25 installation completed!\n\n"