209 lines
6.2 KiB
Bash
209 lines
6.2 KiB
Bash
#!/bin/bash
|
|
|
|
# Check if the user is root
|
|
if [ "$EUID" -ne 0 ]
|
|
then echo "Please run as root"
|
|
exit
|
|
fi
|
|
|
|
# Prompt the user for reboot confirmation
|
|
read -p "This script will install all required components for the DRB client. Are you okay with rebooting afterward? If not, you will have to reboot later before running the applications to finish the installation. (Reboot?: y/n): " confirm
|
|
|
|
# Convert user input to lowercase for case-insensitive comparison
|
|
confirm="${confirm,,}"
|
|
|
|
if [[ "$confirm" != "y" && "$confirm" != "yes" ]]; then
|
|
echo "Script will not reboot."
|
|
should_reboot=false
|
|
else
|
|
echo "Script will reboot after completion."
|
|
should_reboot=true
|
|
fi
|
|
|
|
echo "----- Starting Radio Node Client Install Script -----"
|
|
|
|
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
|
|
|
|
# Copy the example env file
|
|
cp .env.example .env
|
|
|
|
# Copy the radio config example file
|
|
cp config/radioPresets.json.EXAMPLE config/radioPresets.json
|
|
|
|
echo "----- Collecting Setup Information -----"
|
|
|
|
# Ask the user for input and store in variables
|
|
echo " \\Client Config"
|
|
read -p " Enter Node Name: " nodeName
|
|
read -p " Enter Node IP: " nodeIP
|
|
read -p " Enter Node Port: " nodePort
|
|
read -p " Enter Node Location: " nodeLocation
|
|
read -p " Enter Audio Device ID: " audioDeviceID
|
|
echo " \\Server Config"
|
|
read -p " Enter Server IP (leave blank if using hostname): " serverIP
|
|
if [ -z "$serverIP" ]; then
|
|
read -p " Enter Server Hostname: " serverHostname
|
|
fi
|
|
read -p " Enter Server Port: " serverPort
|
|
|
|
# Update the values in the env file using sed
|
|
sed -i "s/^AUDIO_DEVICE_ID=\".*\"$/AUDIO_DEVICE_ID=\"$audioDeviceID\"/" .env
|
|
sed -i "s/^CLIENT_NAME=\".*\"$/CLIENT_NAME=\"$nodeName\"/" .env
|
|
sed -i "s/^CLIENT_IP=\".*\"$/CLIENT_IP=\"$nodeIP\"/" .env
|
|
sed -i "s/^CLIENT_PORT=.*$/CLIENT_PORT=$nodePort/" .env
|
|
sed -i "s/^CLIENT_LOCATION=\".*\"$/CLIENT_LOCATION=\"$nodeLocation\"/" .env
|
|
if [ -z "$serverIP" ]; then
|
|
sed -i "s/^SERVER_HOSTNAME=\".*\"$/SERVER_HOSTNAME=\"$serverHostname\"/" .env
|
|
else
|
|
sed -i "s/^SERVER_IP=\".*\"$/SERVER_IP=\"$serverIP\"/" .env
|
|
fi
|
|
sed -i "s/^SERVER_PORT=\".*\"$/SERVER_PORT=\"$serverPort\"/" .env
|
|
echo "----- Config file has been updated -----"
|
|
|
|
# Display the updated values
|
|
echo "----- Start of Config File -----"
|
|
cat .env
|
|
echo "----- End of Config File -----"
|
|
|
|
echo "----- Getting Dependencies -----"
|
|
|
|
# Install Node Repo
|
|
# Get the CPU architecture
|
|
cpu_arch=$(uname -m)
|
|
|
|
# Print the CPU architecture for verification
|
|
echo "Detected CPU Architecture: $cpu_arch"
|
|
|
|
# Check if the architecture is ARMv6
|
|
if [[ "$cpu_arch" == "armv6"* ]]; then
|
|
echo "----- CPU Architecture is ARMv6 or compatible. -----"
|
|
echo "----- CPU Architectre is not compatible with dependencies of this project, please use a newer CPU architecture -----"
|
|
exit
|
|
|
|
curl -fsSL https://deb.nodesource.com/setup_current.x | sudo -E bash -
|
|
|
|
# Update the system
|
|
apt-get update
|
|
apt-get upgrade -y
|
|
|
|
# Install the necessary packages
|
|
apt-get install -y nodejs portaudio19-dev libportaudio2 libpulse-dev pulseaudio apulse python3 python3-pip git
|
|
|
|
# Install the node packages from the project
|
|
npm i
|
|
|
|
# Install the python packages needed for the bot
|
|
pip install -r ./pdab/requirements.txt
|
|
|
|
echo "----- Setting up Pulse Audio -----"
|
|
|
|
# Ensure pulse audio is running as system so the service can see the audio device
|
|
systemctl --global disable pulseaudio.service pulseaudio.socket
|
|
|
|
# Update the PulseAudio config to disable autospawning
|
|
sed -i 's/autospawn = .*$/autospawn = no/' /etc/pulse/client.conf
|
|
|
|
# Add the system PulseAudio service
|
|
echo "[Unit]
|
|
Description=PulseAudio system server
|
|
|
|
[Service]
|
|
Type=notify
|
|
ExecStart=pulseaudio --daemonize=no --system --realtime --log-target=journal
|
|
|
|
[Install]
|
|
WantedBy=multi-user.target" >> /etc/systemd/system/PulseAudio.service
|
|
|
|
# Add the root user to the pulse-access group
|
|
usermod -aG pulse-access root
|
|
usermod -aG pulse-access pi
|
|
|
|
# Enable the PulseAudio service
|
|
systemctl enable PulseAudio.service
|
|
|
|
echo "----- Setting up Radio Node Service -----"
|
|
|
|
# Setup bot service
|
|
echo "[Unit]
|
|
Description=Radio Node Service
|
|
After=network.target
|
|
|
|
[Service]
|
|
WorkingDirectory=$SCRIPT_DIR/
|
|
ExecStart=/usr/bin/node .
|
|
Restart=always
|
|
RestartDelay=10
|
|
Environment=\"DEBUG='client:*'\"
|
|
|
|
[Install]
|
|
WantedBy=multi-user.target" >> /etc/systemd/system/RadioNode.service
|
|
|
|
# Enable the Radio Node service
|
|
systemctl enable RadioNode.service
|
|
|
|
echo "----- Setting up Radio Node Update Service -----"
|
|
|
|
# Setup bot update service
|
|
echo "[Unit]
|
|
Description=Radio Node Updater Service
|
|
After=network.target
|
|
|
|
[Service]
|
|
WorkingDirectory=$SCRIPT_DIR/
|
|
ExecStart=/usr/bin/bash update.sh
|
|
Restart=on-failure
|
|
|
|
[Install]
|
|
WantedBy=multi-user.target" >> /etc/systemd/system/RadioNodeUpdater.service
|
|
|
|
# Install OP25
|
|
echo "----- Installing OP25 from Source -----"
|
|
# Clone the OP25 Git
|
|
cd /opt/
|
|
git clone https://github.com/boatbod/op25.git
|
|
cd op25
|
|
|
|
# Run the OP25 install script
|
|
bash ./install.sh
|
|
|
|
# Create the config file for the client or user to update later
|
|
cp /opt/op25/op25/gr-op25_repeater/apps/p25_rtl_example.json /opt/op25/op25/gr-op25_repeater/apps/radioNodeOP25Config.json
|
|
|
|
# Create the OP25 service
|
|
echo "[Unit]
|
|
Description=OP25 Service
|
|
After=network.target
|
|
|
|
[Service]
|
|
WorkingDirectory=/opt/op25/op25/gr-op25_repeater/apps
|
|
ExecStart=./multi_rx.py -c radioNodeOP25Config.json
|
|
Restart=always
|
|
|
|
[Install]
|
|
WantedBy=multi-user.target" >> /etc/systemd/system/OP25.service
|
|
|
|
echo "----- OP25 Setup Complete -----"
|
|
|
|
# Enable the OP25 service, don't start it though as the user needs to config
|
|
systemctl enable OP25.service
|
|
echo "----- OP25 Enabled; Please ensure to update the configuration and start the service -----"
|
|
|
|
# Move back to the directory that the user started in (might not be needed?)
|
|
cd $SCRIPT_DIR
|
|
|
|
echo "----- Setup Complete! -----"
|
|
|
|
# Reboot if the user confirmed earlier
|
|
if [ "$should_reboot" = true ]; then
|
|
echo "To configure the app, please go to http://$nodeIP:$nodePort"
|
|
echo "Thank you for joining the network!"
|
|
# 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..."
|
|
reboot
|
|
else
|
|
echo "To configure the app, please go to http://$nodeIP:$nodePort"
|
|
echo "Thank you for joining the network!"
|
|
echo "Please restart your device to complete the installation"
|
|
fi
|