Files
DRBv3/client/Makefile
Logan Cusano 7b91667414
Some checks failed
DRB Build Tests / drb_build_and_test (push) Failing after 2m26s
#10 Update Makefiles
- Removed the client_dir var as it's not needed
2024-04-21 01:31:04 -04:00

122 lines
5.6 KiB
Makefile

# Define variables
OP25_DIR := op25
PDAB_DIR := discordAudioBot/pdab
.PHONY: all pre_flight_checks install_dependencies setup_pulse_audio install_node install_pdab generate_env_file add_systems_to_presets install_op25 set_permissions reboot
all: pre_flight_checks install_dependencies setup_pulse_audio install_node install_pdab generate_env_file add_systems_to_presets install_op25 set_permissions reboot
pre_flight_checks:
# Exit on error
set -e
# Check if the script is run as root
if [ "$(shell 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 "$(shell pwd)/package.json" ]; then \
echo "Error: Please make sure the working directory is 'client' and contains package.json."; \
exit 1; \
fi
install_dependencies:
# Install necessary dependencies
sudo apt update
sudo apt upgrade -y
sudo apt install -y nodejs portaudio19-dev libportaudio2 libpulse-dev pulseaudio apulse git ffmpeg git python3 python3-pip
setup_pulse_audio:
# Setup Pulse Audio
sudo systemctl --global disable pulseaudio.service pulseaudio.socket
sudo sed -i 's/autospawn = .*$/autospawn = no/' /etc/pulse/client.conf
sudo echo "[Unit]" > /etc/systemd/system/PulseAudio.service
sudo echo "Description=PulseAudio system server" >> /etc/systemd/system/PulseAudio.service
sudo echo "" >> /etc/systemd/system/PulseAudio.service
sudo echo "[Service]" >> /etc/systemd/system/PulseAudio.service
sudo echo "Type=notify" >> /etc/systemd/system/PulseAudio.service
sudo echo "ExecStart=pulseaudio --daemonize=no --system --realtime --log-target=journal" >> /etc/systemd/system/PulseAudio.service
sudo echo "" >> /etc/systemd/system/PulseAudio.service
sudo echo "[Install]" >> /etc/systemd/system/PulseAudio.service
sudo echo "WantedBy=multi-user.target" >> /etc/systemd/system/PulseAudio.service
sudo usermod -aG pulse-access root
sudo usermod -aG pulse-access pi
sudo systemctl enable PulseAudio.service
sudo systemctl stop PulseAudio.service
install_node:
# Install Node Repo
cpu_arch=$(shell uname -m)
echo "Detected CPU Architecture: $$cpu_arch"
if [ "$$cpu_arch" == "armv6"* ]; then \
echo "----- CPU Architecture is ARMv6 or compatible. -----\n----- CPU Architectre is not compatible with dependencies of this project, please use a newer CPU architecture -----\n"; \
exit; \
fi
curl -fsSL https://deb.nodesource.com/setup_current.x | sudo -E bash -
install_pdab:
# Install Python DAB
git clone -b DRBv3 https://git.vpn.cusano.net/logan/Python-Discord-Audio-Bot.git ./$(PDAB_DIR)/pdab
pip3 install --system -r ./$(PDAB_DIR)/pdab/requirements.txt
generate_env_file:
# Generate .env file
echo "# Client Config" > .env
echo "CLIENT_NUID=0" >> .env
client_name=$$(shell read -p "Enter the name for this node: " input && echo $$input)
echo "CLIENT_NAME=$$client_name" >> .env
client_location=$$(shell read -p "Enter the location of this node: " input && echo $$input)
echo "CLIENT_LOCATION=$$client_location" >> .env
client_capabilities=$$(shell read -p "Select CLIENT_CAPABILITIES (comma-separated, default: radio): " input && echo "$${input:-radio}")
echo "CLIENT_CAPABILITIES=$$client_capabilities" >> .env
# Additional configuration (SERVER_IP, SERVER_PORT, OP25_FULL_PATH, CONFIG_PATH, AUDIO_DEVICE_ID, PDAB_PORT, NODE_ENV) can be added here
add_systems_to_presets:
# Create a JSON object to store nearby systems
systems_json="{"
while true; do \
systems_json+="$$($(shell 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\"},"))"
read -p "Do you want to add another system? (yes/no): " choice; \
if [ "$$choice" != "yes" ]; then \
break; \
fi; \
done
systems_json=$$(echo "$$systems_json" | sed 's/,$$//') # Remove trailing comma
systems_json+="}"
mkdir -p ./config
echo "$$systems_json" > "./config/radioPresets.json"
install_op25:
# Clone OP25 from the git repository
git clone -b gr310 https://github.com/boatbod/op25.git $(OP25_DIR)
# Edit the startup script to use the active.cfg.json config file generated by the app
sudo sed -i 's/p25_rtl_example.json/active.cfg.json/g' $(OP25_DIR)/op25-multi_rx.sh
# Move the startup script to the apps dir
sudo mv $(OP25_DIR)/op25-multi_rx.sh $(OP25_DIR)/op25/gr-op25_repeater/apps/
# Install OP25 using the provided installation script
sudo bash $(OP25_DIR)/install.sh
set_permissions:
# Setting permissions on the directories created
sudo chown -R 1000:1000 ./*
sudo chown 1000:1000 .env
reboot:
# Prompt the user for reboot confirmation
read -p "This script has installed all required components for the DRB client. Are you okay with rebooting? If not, you will have to reboot later before running the applications to finish the installation. (Reboot?: y/n): " confirm
confirm=$$(echo "$$confirm" | tr '[:upper:]' '[:lower:]') # Convert to lowercase
if [ "$$confirm" != "y" ] && [ "$$confirm" != "yes" ]; then \
# Prompt user to press any key before rebooting
read -rsp $$'System will now reboot, press any key to continue or Ctrl+C to cancel...\n' -n1 key; \
echo "Rebooting..."; \
sudo reboot; \
else \
echo "Please restart your device to complete the installation"; \
fi