From 429c26e6b0772ae89aafc07136b3236c6806d57c Mon Sep 17 00:00:00 2001 From: Dj Merrill Date: Thu, 25 Apr 2024 17:12:36 -0400 Subject: [PATCH] First drafts of install and run scripts for Linux, supporting Debian 12 for now. --- tools/Linux/install-freedata-linux.sh | 205 ++++++++++++++++++++++++++ tools/Linux/run-freedata-linux.sh | 87 +++++++++++ 2 files changed, 292 insertions(+) create mode 100755 tools/Linux/install-freedata-linux.sh create mode 100755 tools/Linux/run-freedata-linux.sh diff --git a/tools/Linux/install-freedata-linux.sh b/tools/Linux/install-freedata-linux.sh new file mode 100755 index 00000000..a98ebda6 --- /dev/null +++ b/tools/Linux/install-freedata-linux.sh @@ -0,0 +1,205 @@ +#!/bin/bash +# +# Simple script to install FreeDATA in Linux +# Dj Merrill - 25 Apr 2024 +# +# Currently supports Debian 12 +# +# args: nothing or "main" (use main branch of FreeDATA) +# "develop" (use develop branch of FreeDATA) +# + +case $1 in + "" | "main") + args="main" + ;; + "develop") + args="develop" + ;; + *) + echo "Argument" $1 "not valid. Exiting." + exit 1 + ;; +esac + +osname=`grep -E '^(NAME)=' /etc/os-release | cut -d\" -f2` +osversion=`grep -E '^(VERSION)=' /etc/os-release | cut -d\" -f2` + +echo "Running on" $osname "version" $osversion + +echo "*************************************************************************" +echo "Installing software prerequisites" +echo "*************************************************************************" + +case $osname in + "Debian GNU/Linux") + case $osversion in + "11 (bullseye)") + sudo apt install --upgrade -y libhamlib-utils libhamlib-dev libhamlib4 fonts-noto-color-emoji git build-essential cmake npm nodejs python3 portaudio19-dev python3-pyaudio python3-pip python3-colorama + ;; + + "12 (bookworm)") + sudo apt install --upgrade -y libhamlib-utils libhamlib-dev libhamlib4 fonts-noto-color-emoji git build-essential cmake npm nodejs python3 portaudio19-dev python3-pyaudio python3-pip python3-colorama + ;; + + *) + echo "*************************************************************************" + echo "This version of Linux is not yet supported by this script." + echo $osname $osversion + echo "*************************************************************************" + exit 1 + ;; + + esac + + ;; + + *) + echo "*************************************************************************" + echo "This version of Linux is not yet supported by this script." + echo $osname $osversion + echo "*************************************************************************" + exit 1 + ;; +esac + +echo "*************************************************************************" +echo "Checking for old FreeDATA directories" +echo "*************************************************************************" +if [ -d "FreeDATA.old" ]; +then + rm -rf FreeDATA.old +fi +if [ -d "FreeDATA-venv.old" ]; +then + rm -rf FreeDATA-venv.old +fi +if [ -d "FreeDATA" ]; +then + mv FreeDATA FreeDATA.old +fi +if [ -d "FreeDATA-venv" ]; +then + mv FreeDATA-venv FreeDATA-venv.old +fi + +echo "*************************************************************************" +echo "Creating Python Virtual Environment FreeDATA-venv" +echo "*************************************************************************" +python3 -m venv FreeDATA-venv + +echo "*************************************************************************" +echo "Activating the Python Virtual Environment" +echo "*************************************************************************" +if [ -f "./FreeDATA-venv/bin/activate" ]; +then + source ./FreeDATA-venv/bin/activate +else + echo "Something went wrong. FreeDATA-venv virtual environment not created properly." + exit 1 +fi + +echo "*************************************************************************" +echo "Updating pip and wheel" +echo "*************************************************************************" +pip install --upgrade pip wheel + +echo "*************************************************************************" +echo "Downloading the FreeDATA software from the git repo" +echo "*************************************************************************" +git clone https://github.com/DJ2LS/FreeDATA.git + +echo "*************************************************************************" +echo "Changing Directory into FreeDATA" +echo "*************************************************************************" +if [ -d "FreeDATA" ]; +then + cd FreeDATA +else + echo "Something went wrong. FreeDATA software not downloaded from git." + exit 1 +fi + +if [ "$args" == "develop" ]; +then + git checkout develop +fi + +echo "*************************************************************************" +echo "Installing required Python programs into the virtual environment" +echo "*************************************************************************" +pip install --upgrade -r requirements.txt + +echo "*************************************************************************" +echo "Changing into the server directory" +echo "*************************************************************************" +if [ "$args" == "develop" ]; +then + cd freedata_server/lib +else + cd modem/lib +fi + +echo "*************************************************************************" +echo "Checking and removing any old codec2 libraries" +echo "*************************************************************************" +if [ -d "codec2" ]; +then + mv codec2 codec2.old +fi + +echo "*************************************************************************" +echo "Downloading the latest codec library" +echo "*************************************************************************" +git clone https://github.com/drowe67/codec2.git + +echo "*************************************************************************" +echo "Changing into the codec2 library directory" +echo "*************************************************************************" +if [ -d "codec2" ]; +then + cd codec2 +else + echo "Something went wrong. Codec2 software not downloaded from git." + exit 1 +fi + +if [ "$args" == "develop" ]; +then + git checkout dr-qam16-cport +fi + +echo "*************************************************************************" +echo "Setting up the codec2 build" +echo "*************************************************************************" +mkdir build_linux +cd build_linux + +echo "*************************************************************************" +echo "Building the codec2 library" +echo "*************************************************************************" +cmake .. +make -j4 + +if [ ! -f "src/libcodec2.so.1.2" ]; +then + echo "Something went wrong. Codec2 software not built." + exit 1 +fi + +echo "*************************************************************************" +echo "Building the FreeDATA GUI frontend" +echo "*************************************************************************" +cd ../../../.. +if [ "$args" == "develop" ]; +then + cd freedata_gui +else + cd gui +fi +npm i +npm audit fix --force +npm i + +# Return to the directory we started in +cd ../.. diff --git a/tools/Linux/run-freedata-linux.sh b/tools/Linux/run-freedata-linux.sh new file mode 100755 index 00000000..2a02825a --- /dev/null +++ b/tools/Linux/run-freedata-linux.sh @@ -0,0 +1,87 @@ +#!/bin/bash +# +# Simple script to run FreeDATA in Linux +# Dj Merrill - 25 Apr 2024 +# +# Run this script in the directory that contains the "FreeDATA" and +# "FreeDATA-venv" directories created by the install-freedata.sh script +# +# Two log files are created in this directory: +# FreeDATA-server.log: debug output from the server process +# FreeDATA-client.log: debug output from the GUI front end +# +# We expect the config.ini file to be at $HOME/.config/FreeDATA/config.ini +# If it isn't found, we copy config.ini.example there +# +# + +# Activate the Python Virtual Environment +source ./FreeDATA-venv/bin/activate + +# Check to see if there is an old server running, and stop it if there is +checkoldserver=`ps auxw | grep FreeDATA | grep server.py` + +if [ ! -z "$checkoldserver" ]; +then + oldserverpid=`echo $checkoldserver | cut -d" " -f2` + echo "*************************************************************************" + echo "Found old FreeDATA server at PID" $oldserverpid "- stopping it" + echo "*************************************************************************" + kill $oldserverpid + sleep 7s +fi + +echo "*************************************************************************" +echo "Running the FreeDATA server component" +echo "*************************************************************************" + +# New versions use freedata_server, old version use modem +if [ -d "FreeDATA/freedata_server" ]; +then + serverdir="FreeDATA/freedata_server" +else + serverdir="FreeDATA/modem" +fi + +if [ ! -d "$HOME/.config/FreeDATA" ]; +then + mkdir -p $HOME/.config/FreeDATA +fi +if [ ! -f "$HOME/.config/FreeDATA/config.ini" ]; +then + echo "*************************************************************************" + echo "No config file found. Copying example config file to" + echo $HOME/.config/FreeDATA/config.ini + echo "*************************************************************************" + cp $serverdir/config.ini.example $HOME/.config/FreeDATA/config.ini +fi + +FREEDATA_CONFIG=$HOME/.config/FreeDATA/config.ini python3 $serverdir/server.py > FreeDATA-server.log 2>&1 & +serverpid=$! +echo "Process ID of FreeDATA server is" $serverpid + +# Run the GUI front end +echo "*************************************************************************" +echo "Running the FreeDATA GUI front end" +echo "*************************************************************************" + +# New versions use "freedata_gui", old versions use "gui" +if [ -d "FreeDATA/freedata_gui" ]; +then + guidir="FreeDATA/freedata_gui" +else + guidir="FreeDATA/gui" +fi + +cd $guidir +npm start > ../../FreeDATA-client.log 2>&1 + +# If we are this far, then we have just quit the GUI, so let's clean up the +# server +echo "*************************************************************************" +echo "Stopping the server component" +echo "*************************************************************************" +kill $serverpid + +# Return to the directory we started in +cd ..