#!/bin/bash

sudo apt install -y git build-essential cmake npm
curl -sL https://deb.nodesource.com/setup_16.x | sudo bash -
sudo apt install -y nodejs
sudo npm install -g n
sudo n stable
sudo npm install -g npm
sudo apt install -y python3 portaudio19-dev python3-pyaudio python3-pip python3-colorama

git clone https://github.com/DJ2LS/FreeDATA.git
cd FreeDATA
pip3 install -r requirements.txt
cd gui
npm i
cd ..

cd tnc/lib
git clone https://github.com/drowe67/codec2.git
cd codec2
mkdir build_linux
cd build_linux
cmake ..
make -j4

#sudo chown root node_modules/electron/dist/chrome-sandbox
#sudo chmod 4755 node_modules/electron/dist/chrome-sandbox

# menu
cat <<EOF >${HOME}/.local/share/applications/freedata.desktop
[Desktop Entry]
Name=FreeData
Comment=send files and messages, using the codec2 HF modem
Exec=sh ~/FreeDATA/freedata_startup.sh
Icon=
Type=Application
Encoding=UTF-8
Terminal=true
Categories=HamRadio
Keywords=Radio
EOF

# startup script
cat <<EOF >${HOME}/FreeDATA/freedata_startup.sh
#! /bin/bash
flrig &
sleep 5
rigctld -m 4 &
cd $HOME/FreeDATA/tnc
python3 daemon.py &
cd $HOME/FreeDATA/gui
npm start
EOF



