Skip to content

Commit 8e38a23

Browse files
author
Juan Chong
committed
Added additional tests, path validation, etc. Improved documentation in script comments.
1 parent 8248565 commit 8e38a23

File tree

1 file changed

+49
-3
lines changed

1 file changed

+49
-3
lines changed

dw-start-cli.sh

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,31 @@
55
# Run this from crontab periodically to check whether direwolf is running
66
# and force it to start up automatically.
77

8+
# In order to execute this script periodically using crontab, do the following:
9+
# 1.- Configure the script to your liking and save changes.
10+
# 2.- Type "crontab -e" without quotes in the terminal
11+
# 2a.- If this is your first time editing crontab, select your preferred text editor. My favorite is nano.
12+
# 3.- Add the line below to the crontab file. This will force the script to run every minute.
13+
#
14+
# * * * * * /absolute/path/to/this/file/dw-start-cli.sh >/dev/null 2>&1
15+
#
16+
# 4.- Save and close the crontab file.
17+
# 5.- Optional: Use top to check whether direwolf was started. I highly recommend
18+
# testing this script by manually executing it before adding it to the crontab.
19+
# Execute the script manually by typing: ./dw-start-cli.sh
20+
821
# Versioning (this file, not direwolf version)
922
#-----------
10-
# v1.4 - KE5WSG - removed support for the GUI and vastly simplified the script
23+
# v1.4 - KE5WSG - Removed support for the GUI and vastly simplified the script.
24+
# Improved error checking and logging.
1125
# v1.3 - KI6ZHD - added variable support for direwolf binary location
1226
# v1.2 - KI6ZHD - support different versions of VNC
1327
# v1.1 - KI6ZHD - expanded version to support running on text-only displays with
1428
# auto support; log placement change
1529
# v1.0 - WB2OSZ - original version for Xwindow displays only
1630

1731
# Enable (true) / disable (false) logging everything to the log file.
32+
# Setting this to 'false' is recommended to keep from unnecessarily filling the log file.
1833
DEBUG=false
1934

2035
#Where will be stored. The directory must be writable by non-root users.
@@ -33,14 +48,18 @@ DWPATH="/home/pi/direwolf"
3348

3449
DWCONFIG="/home/pi/direwolf"
3550

51+
# Name of the direwolf configuration file.
52+
53+
DWCONFIGFILE="direwolf.conf"
54+
3655
# Direwolf start up command. Examples for both a simple and SDR config are provided.
3756
#
3857
# 1. For normal operation as TNC, digipeater, IGate, etc.
3958
# Print audio statistics each 100 seconds for troubleshooting.
4059
# Change this command to however you wish to start Direwolf.
4160
# Be sure to use variables as necessary when building your command.
4261

43-
DWCMD="$DWPATH/direwolf -a 100 -c $DWCONFIG/direwolf.conf"
62+
DWCMD="$DWPATH/direwolf -a 100 -c $DWCONFIG/$DWCONFIGFILE"
4463

4564
#---------------------------------------------------------------
4665
#
@@ -56,6 +75,33 @@ export PATH=/usr/local/bin:$PATH
5675

5776
# Error checking before attempting to start direwolf
5877

78+
# Check to see whether the direwolf directory exists
79+
if ! [ -d "$DWPATH" ]; then
80+
echo -e "ERROR: The direwolf path (DWPATH) is invalid! Aborting."
81+
echo "-----------------------" >> $LOGFILE
82+
date >> $LOGFILE
83+
echo "ERROR: The direwolf path (DWPATH) is invalid! Aborting." >> $LOGFILE
84+
exit 1
85+
fi
86+
87+
# Check to see whether the direwolf application exists
88+
if ! [ -f "$DWPATH/direwolf" ]; then
89+
echo -e "ERROR: The direwolf application (DWPATH/direwolf) cannot be found! Aborting."
90+
echo "-----------------------" >> $LOGFILE
91+
date >> $LOGFILE
92+
echo "ERROR: The direwolf application (DWPATH/direwolf) cannot be found! Aborting." >> $LOGFILE
93+
exit 1
94+
fi
95+
96+
# Check to see whether the direwolf configuration file exists
97+
if ! [ -f "$DWCONFIG/$DWCONFIGFILE" ]; then
98+
echo -e "ERROR: The direwolf configuration file specified cannot be found! Aborting."
99+
echo "-----------------------" >> $LOGFILE
100+
date >> $LOGFILE
101+
echo "ERROR: The direwolf configuration file specified cannot be found! Aborting." >> $LOGFILE
102+
exit 1
103+
fi
104+
59105
# Check to see whether screen is installed
60106
if ! type "screen" > /dev/null; then
61107
echo -e "ERROR: screen is not installed. Please install using 'sudo apt-get install screen' Aborting."
@@ -76,7 +122,7 @@ if screen -list | grep -q "direwolf"; then
76122
exit
77123
fi
78124

79-
# It looks like we have everything we need to start direwolf, let's try!
125+
# It looks like none of the errors forced the application to exit. Let's try running direwolf!
80126

81127
# Wait a little while in case we just rebooted and you're using an old RPi.
82128
# Feel free to adjust this delay as needed.

0 commit comments

Comments
 (0)