Skip to content

Commit aa28c9c

Browse files
committed
Enhanced dw-start.sh script and better documentation.
1 parent 7f77b29 commit aa28c9c

File tree

3 files changed

+142
-71
lines changed

3 files changed

+142
-71
lines changed

doc/Raspberry-Pi-APRS.pdf

55.7 KB
Binary file not shown.

doc/User-Guide.pdf

10.5 KB
Binary file not shown.

dw-start.sh

+142-71
Original file line numberDiff line numberDiff line change
@@ -1,100 +1,171 @@
11
#!/bin/bash
22

3-
#
43
# Run this from crontab periodically to start up
54
# Dire Wolf automatically.
5+
6+
# Versioning
7+
#-----------
8+
# v1.2 - KI6ZHD - support different versions of VNC
9+
# v1.1 - KI6ZHD - expanded version to support running on text-only displays with
10+
# auto support; log placement change
11+
# v1.0 - WB2OSZ - original version for Xwindow displays only
12+
13+
14+
15+
#How are you running Direwolf : within a GUI (Xwindows / VNC) or CLI mode
616
#
7-
# I prefer this method instead of putting something
8-
# in ~/.config/autostart. That would start an application
9-
# only when the desktop first starts up.
10-
#
11-
# This method will restart the application if it
12-
# crashes or stops for any other reason.
17+
# AUTO mode is design to try starting direwolf with GUI support and then
18+
# if no GUI environment is available, it reverts to CLI support with screen
1319
#
14-
# This script has some specifics the Raspberry Pi.
15-
# Some adjustments might be needed for other Linux variations.
20+
# GUI mode is suited for users with the machine running LXDE/Gnome/KDE or VNC
21+
# which auto-logs on (sitting at a login prompt won't work)
1622
#
23+
# CLI mode is suited for say a Raspberry Pi running the Jessie LITE version
24+
# where it will run from the CLI w/o requiring Xwindows - uses screen
1725

26+
RUNMODE=AUTO
27+
28+
29+
#Direwolf start up command :: two examples where example one is enabled
30+
#
31+
# 1. For normal operation as TNC, digipeater, IGate, etc.
32+
# Print audio statistics each 100 seconds for troubleshooting.
33+
# Change this command to however you wish to start Direwolf
34+
DWCMD="direwolf -a 100"
35+
#---------------------------------------------------------------
1836
#
37+
# 2. Alternative for running with SDR receiver.
38+
# Piping one application into another makes it a little more complicated.
39+
# We need to use bash for the | to be recognized.
40+
#DWCMD="bash -c 'rtl_fm -f 144.39M - | direwolf -c sdr.conf -r 24000 -D 1 -'"
41+
42+
43+
#Where will logs go - needs to be writable by non-root users
44+
LOGFILE=/var/tmp/dw-start.log
45+
46+
47+
#-------------------------------------
48+
# Main functions of the script
49+
#-------------------------------------
50+
51+
#Status variables
52+
SUCCESS=0
53+
54+
function CLI {
55+
SCREEN=`which screen`
56+
if [ $? -ne 0 ]; then
57+
echo -e "Error: screen is not installed but is required for CLI mode. Aborting"
58+
exit 1
59+
fi
60+
61+
echo "Direwolf in CLI mode start up"
62+
echo "Direwolf in CLI mode start up" >> $LOGFILE
63+
64+
# Screen commands
65+
# -d m :: starts the command in detached mode
66+
# -S :: name the session
67+
$SCREEN -d -m -S direwolf $DWCMD
68+
SUCCESS=1
69+
70+
screen -list direwolf
71+
screen -list direwolf >> $LOGFILE
72+
73+
echo "-----------------------"
74+
echo "-----------------------" >> $LOGFILE
75+
}
76+
77+
function GUI {
78+
# In this case
79+
# In my case, the Raspberry Pi is not connected to a monitor.
80+
# I access it remotely using VNC as described here:
81+
# http://learn.adafruit.com/adafruit-raspberry-pi-lesson-7-remote-control-with-vnc
82+
#
83+
# If VNC server is running, use its display number.
84+
# Otherwise default to :0 (the Xwindows on the HDMI display)
85+
#
86+
export DISPLAY=":0"
87+
88+
#Reviewing for RealVNC sessions (stock in Raspbian Pixel)
89+
if [ -n "`ps -ef | grep vncserver-x11-serviced | grep -v grep`" ]; then
90+
sleep 0.1
91+
echo -e "\nRealVNC found - defaults to connecting to the :0 root window"
92+
elif [ -n "`ps -ef | grep Xtightvnc | grep -v grep`" ]; then
93+
#Reviewing for TightVNC sessions
94+
echo -e "\nTightVNC found - defaults to connecting to the :1 root window"
95+
v=`ps -ef | grep Xtightvnc | grep -v grep`
96+
d=`echo "$v" | sed 's/.*tightvnc *\(:[0-9]\).*/\1/'`
97+
export DISPLAY="$d"
98+
fi
99+
100+
echo "Direwolf in GUI mode start up"
101+
echo "Direwolf in GUI mode start up" >> $LOGFILE
102+
echo "DISPLAY=$DISPLAY"
103+
echo "DISPLAY=$DISPLAY" >> $LOGFILE
104+
105+
#
106+
# Auto adjust the startup for your particular environment: gnome-terminal, xterm, etc.
107+
#
108+
109+
if [ -x /usr/bin/lxterminal ]; then
110+
/usr/bin/lxterminal -t "Dire Wolf" -e "$DWCMD" &
111+
SUCCESS=1
112+
elif [ -x /usr/bin/xterm ]; then
113+
/usr/bin/xterm -bg white -fg black -e "$DWCMD" &
114+
SUCCESS=1
115+
elif [ -x /usr/bin/x-terminal-emulator ]; then
116+
/usr/bin/x-terminal-emulator -e "$DWCMD" &
117+
SUCCESS=1
118+
else
119+
echo "Did not find an X terminal emulator. Reverting to CLI mode"
120+
SUCCESS=0
121+
fi
122+
echo "-----------------------"
123+
echo "-----------------------" >> $LOGFILE
124+
}
125+
126+
# -----------------------------------------------------------
127+
# Main Script start
128+
# -----------------------------------------------------------
129+
19130
# When running from cron, we have a very minimal environment
20131
# including PATH=/usr/bin:/bin.
21132
#
22-
23133
export PATH=/usr/local/bin:$PATH
24134

135+
#Log the start of the script run and re-run
136+
date >> $LOGFILE
137+
25138
# First wait a little while in case we just rebooted
26139
# and the desktop hasn't started up yet.
27140
#
28-
29141
sleep 30
30-
LOGFILE=/tmp/dw-start.log
142+
31143

32144
#
33-
# Nothing to do if it is already running.
145+
# Nothing to do if Direwolf is already running.
34146
#
35147

36-
a=`pgrep direwolf`
37-
if [ "$a" != "" ]
148+
a=`ps ax | grep direwolf | grep -vi -e bash -e screen -e grep | awk '{print $1}'`
149+
if [ -n "$a" ]
38150
then
39151
#date >> /tmp/dw-start.log
40-
#echo "Already running." >> $LOGFILE
152+
#echo "Direwolf already running." >> $LOGFILE
41153
exit
42154
fi
43155

44-
#
45-
# In my case, the Raspberry Pi is not connected to a monitor.
46-
# I access it remotely using VNC as described here:
47-
# http://learn.adafruit.com/adafruit-raspberry-pi-lesson-7-remote-control-with-vnc
48-
#
49-
# If VNC server is running, use its display number.
50-
# Otherwise default to :0.
51-
#
52-
53-
date >> $LOGFILE
54-
55-
export DISPLAY=":0"
56-
57-
v=`ps -ef | grep Xtightvnc | grep -v grep`
58-
if [ "$v" != "" ]
59-
then
60-
d=`echo "$v" | sed 's/.*tightvnc *\(:[0-9]\).*/\1/'`
61-
export DISPLAY="$d"
62-
fi
63-
64-
echo "DISPLAY=$DISPLAY" >> $LOGFILE
65-
66-
echo "Start up application." >> $LOGFILE
67-
68-
#
69-
# For normal operation as TNC, digipeater, IGate, etc.
70-
# Print audio statistics each 100 seconds for troubleshooting.
71-
#
72-
73-
DWCMD="direwolf -a 100"
74-
75-
# Alternative for running with SDR receiver.
76-
# Piping one application into another makes it a little more complicated.
77-
# We need to use bash for the | to be recognized.
78-
79-
#DWCMD="bash -c 'rtl_fm -f 144.39M - | direwolf -c sdr.conf -r 24000 -D 1 -'"
80-
81-
#
82-
# Adjust for your particular situation: gnome-terminal, xterm, etc.
83-
#
84-
85-
86-
if [ -x /usr/bin/lxterminal ]
87-
then
88-
/usr/bin/lxterminal -t "Dire Wolf" -e "$DWCMD" &
89-
elif [ -x /usr/bin/xterm ]
90-
then
91-
/usr/bin/xterm -bg white -fg black -e "$DWCMD" &
92-
elif [ -x /usr/bin/x-terminal-emulator ]
93-
then
94-
/usr/bin/x-terminal-emulator -e "$DWCMD" &
95-
else
96-
echo "Did not find an X terminal emulator."
156+
# Main execution of the script
157+
158+
if [ $RUNMODE == "AUTO" ];then
159+
GUI
160+
if [ $SUCCESS -eq 0 ]; then
161+
CLI
162+
fi
163+
elif [ $RUNMODE == "GUI" ];then
164+
GUI
165+
elif [ $RUNMODE == "CLI" ];then
166+
CLI
167+
else
168+
echo -e "ERROR: illegal run mode given. Giving up"
169+
exit 1
97170
fi
98171

99-
echo "-----------------------" >> $LOGFILE
100-

0 commit comments

Comments
 (0)