Skip to content

Commit 314cddc

Browse files
committed
added support for multiple instances, tweaked screen execution
1 parent 8619b74 commit 314cddc

File tree

1 file changed

+69
-18
lines changed

1 file changed

+69
-18
lines changed

scripts/dw-start.sh

Lines changed: 69 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,17 @@
1717

1818
# Versioning (this file, not direwolf version)
1919
#-----------
20+
# v1.4 - OK1BIL - added support for multiple instances, tweaked screen execution
2021
# v1.3 - KI6ZHD - added variable support for direwolf binary location
2122
# v1.2 - KI6ZHD - support different versions of VNC
2223
# v1.1 - KI6ZHD - expanded version to support running on text-only displays with
2324
# auto support; log placement change
2425
# v1.0 - WB2OSZ - original version for Xwindow displays only
2526

2627

28+
#-------------------------------------
29+
# Configuration
30+
#-------------------------------------
2731

2832
#How are you running Direwolf : within a GUI (Xwindows / VNC) or CLI mode
2933
#
@@ -36,40 +40,77 @@
3640
# CLI mode is suited for say a Raspberry Pi running the Jessie LITE version
3741
# where it will run from the CLI w/o requiring Xwindows - uses screen
3842

39-
RUNMODE=AUTO
43+
RUNMODE="AUTO"
4044

4145
# Location of the direwolf binary. Depends on $PATH as shown.
4246
# change this if you want to use some other specific location.
4347
# e.g. DIREWOLF="/usr/local/bin/direwolf"
4448

4549
DIREWOLF="direwolf"
4650

51+
# In case direwolf is run in CLI, it is running in a screen session in the background.
52+
# Each screen session has a name. If you want to run multiple instances of direwolf
53+
# in parallel (i.e. two SDRs over STDIN), you need to specify unique names for the sessions.
54+
# Note: screen is a linux tool to run user-interactive software in background.
55+
56+
57+
INSTANCE="direwolf"
58+
59+
60+
# Parameters for the direwolf binary can be set here. This replaces the DWCMD variable.
61+
# Uncomment onlye on of the variables.
4762

48-
#Direwolf start up command :: Uncomment only one of the examples.
49-
#
5063
# 1. For normal operation as TNC, digipeater, IGate, etc.
5164
# Print audio statistics each 100 seconds for troubleshooting.
5265
# Change this command to however you wish to start Direwolf
5366

54-
DWCMD="$DIREWOLF -a 100"
67+
DWPARAMS="-a 100"
5568

5669
# 2. FX.25 Forward Error Correction (FEC) will allow your signal to
5770
# go farther under poor radio conditions. Add "-X 1" to the command line.
5871

59-
#DWCMD="$DIREWOLF -a 100 -X 1"
72+
#DWPARAMS="-a 100 -X 1"
6073

61-
#---------------------------------------------------------------
62-
#
63-
# 3. Alternative for running with SDR receiver.
64-
# Piping one application into another makes it a little more complicated.
65-
# We need to use bash for the | to be recognized.
74+
# 3. Alternative for running with SDR receiver. In case of using this, please pay attention
75+
# to variable DWSTDIN below.
76+
77+
#DWPARAMS="-c /etc/direwolf/ok1abc-sdr.conf -t 0 -r 24000 -D 1 -"
6678

67-
#DWCMD="bash -c 'rtl_fm -f 144.39M - | direwolf -c sdr.conf -r 24000 -D 1 -'"
79+
# A command to be fed into the STDIN of the direwolf binary. Main use for this is to configure rtl-sdr input.
80+
# Leave commented if using soundcard inputs. If using rtl-sdr, uncomment folllowing lines and set parameters as needed.
6881

82+
#QRG="144.8M"
83+
#GAIN="43"
84+
#PPM="1"
85+
#DWSTDIN="rtl_fm -f $QRG -g $GAIN -p $PPM -"
6986

70-
#Where will logs go - needs to be writable by non-root users
71-
LOGFILE=/var/tmp/dw-start.log
7287

88+
# Where will logs go - needs to be writable by non-root users
89+
LOGFILE="/var/tmp/dw-start.log"
90+
91+
# Startup delay in seconds - how long should the script wait before executing (default 30)
92+
STARTUP_DELAY=30
93+
94+
#-------------------------------------
95+
# Internal use functions
96+
#-------------------------------------
97+
98+
# This function is to be recursively called from outside of this script. Its purpose
99+
# is to avoid passing commands to screen or bash as strings, which is tricky.
100+
101+
function RUN_CLI () {
102+
103+
PARAMS=$1
104+
STDIN=$2
105+
106+
if [ -z "$2" ]; then
107+
$DIREWOLF $PARAMS
108+
else
109+
$STDIN | $DIREWOLF $PARAMS
110+
fi
111+
exit 0
112+
113+
}
73114

74115
#-------------------------------------
75116
# Main functions of the script
@@ -91,11 +132,15 @@ function CLI {
91132
# Screen commands
92133
# -d m :: starts the command in detached mode
93134
# -S :: name the session
94-
$SCREEN -d -m -S direwolf $DWCMD >> $LOGFILE
135+
#
136+
# Screen is instructed to run this script again with a parameter (to execute direwolf with
137+
# necessary parameters). This way commands do not need to be passed as string. Additionally,
138+
# this allows for some pre-flight checks withing the screen session, should they be needed.
139+
$SCREEN -d -m -S $INSTANCE $0 -runcli >> $LOGFILE
95140
SUCCESS=1
96141

97-
$SCREEN -list direwolf
98-
$SCREEN -list direwolf >> $LOGFILE
142+
$SCREEN -list $INSTANCE
143+
$SCREEN -list $INSTANCE >> $LOGFILE
99144

100145
echo "-----------------------"
101146
echo "-----------------------" >> $LOGFILE
@@ -165,21 +210,27 @@ date >> $LOGFILE
165210
# First wait a little while in case we just rebooted
166211
# and the desktop hasn't started up yet.
167212
#
168-
sleep 30
213+
sleep $STARTUP_DELAY
169214

170215

171216
#
172217
# Nothing to do if Direwolf is already running.
173218
#
174219

175-
a=`ps ax | grep direwolf | grep -vi -e bash -e screen -e grep | awk '{print $1}'`
220+
a=`ps ax | grep $INSTANCE | grep -vi -e bash -e screen -e grep | awk '{print $1}'`
176221
if [ -n "$a" ]
177222
then
178223
#date >> /tmp/dw-start.log
179224
#echo "Direwolf already running." >> $LOGFILE
180225
exit
181226
fi
182227

228+
# Check for parameter to recursively run this script and execute direwolf in cli
229+
if [ $# -eq 1 ] && [ $1 == "-runcli" ]; then
230+
RUN_CLI "$DWPARAMS" "$DWSTDIN"
231+
exit 0
232+
fi
233+
183234
# Main execution of the script
184235

185236
if [ $RUNMODE == "AUTO" ];then

0 commit comments

Comments
 (0)