Skip to content

Commit ef00a37

Browse files
author
David Ranch
committed
Improved support for cron start, new checks startup method, added STDOUT filtering to avoid chatty cron emails or log
1 parent 6c9f3fa commit ef00a37

File tree

1 file changed

+121
-64
lines changed

1 file changed

+121
-64
lines changed

Diff for: dw-start.sh

+121-64
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,19 @@
1010

1111
# Versioning (this file, not direwolf version)
1212
#-----------
13-
# v1.6 - KI6ZHD - Update to auto-detect binary paths and updated GUI start
14-
# v1.3 - KI6ZHD - added variable support for direwolf binary location
15-
# v1.2 - KI6ZHD - support different versions of VNC
16-
# v1.1 - KI6ZHD - expanded version to support running on text-only displays with
17-
# auto support; log placement change
18-
# v1.0 - WB2OSZ - original version for Xwindow displays only
13+
# v1.6.1 - KI6ZHD - Improved support for cron start, new checks startup method,
14+
# added STDOUT filtering to avoid chatty cron emails or logs
15+
# v1.6 - KI6ZHD - Update to auto-detect binary paths and updated GUI start
16+
# v1.3 - KI6ZHD - added variable support for direwolf binary location
17+
# v1.2 - KI6ZHD - support different versions of VNC
18+
# v1.1 - KI6ZHD - expanded version to support running on text-only displays with
19+
# auto support; log placement change
20+
# v1.0 - WB2OSZ - original version for Xwindow displays only
1921

2022

23+
#-------------------------------------
24+
# User settable variables
25+
#-------------------------------------
2126

2227
#How are you running Direwolf : within a GUI (Xwindows / VNC) or CLI mode
2328
#
@@ -64,8 +69,16 @@ DWCMD="$DIREWOLF -a 100 -t 0"
6469

6570

6671
#Where will logs go - needs to be writable by non-root users
72+
6773
LOGFILE=/var/tmp/dw-start.log
6874

75+
#Script STDOUT and logging output control
76+
# Set this varaible to 0 if you won't want to see all STDOUT
77+
# logging once you get everything working properly
78+
79+
VERBOSE=1
80+
81+
6982

7083
#-------------------------------------
7184
# Main functions of the script
@@ -89,30 +102,40 @@ function CLI {
89102
exit 1
90103
fi
91104

92-
echo "Direwolf in CLI mode start up. All log output recorded to $LOGFILE"
93-
echo "Direwolf in CLI mode start up. All log output recorded to $LOGFILE" >> $LOGFILE
105+
if [ $VERBOSE -eq 1 ]; then
106+
echo "Direwolf in CLI mode start up. All log output recorded to $LOGFILE"
107+
echo "Direwolf in CLI mode start up. All log output recorded to $LOGFILE" >> $LOGFILE
108+
fi
94109

95110
# Screen commands
96111
# -d m :: starts the command in detached mode
97112
# -S :: name the session
98113
# --
99-
# Remove the "-d m" if you don't want screen to detach and not show direwolf"
100-
$SCREEN -d -m -S direwolf $DWCMD >> $LOGFILE
114+
# Options:
115+
# 1. Remove the "-d m" parameters if you don't want screen to automatically detach
116+
# and instead say in the foreground
117+
# 2. Remove the " >> $LOGFILE" if you rather keep all the Direwolf running output
118+
# in the screen session vs going to the log file
119+
#
120+
$SCREEN -d -m -S direwolf bash -c "echo 'All Direwolf output going to $LOGFILE. Enter control-c to terminate Direwolf'; $DWCMD >> $LOGFILE"
101121
CHKERR
102122
SUCCESS=1
103-
echo " "
104-
echo " " >> $LOGFILE
123+
if [ $VERBOSE -eq 1 ]; then
124+
echo " "
125+
echo " " >> $LOGFILE
126+
fi
105127

106128
$SCREEN -list direwolf
107129
CHKERR
108130
$SCREEN -list direwolf >> $LOGFILE
109-
echo -e "\nYou can re-attach to the Direwolf screen with:"
110-
echo -e " screen -dr direwolf"
111-
echo -e "\nYou can re-attach to the Direwolf screen with:" >> $LOGFILE
112-
echo -e " screen -dr direwolf" >> $LOGFILE
113-
114-
echo "-----------------------"
115-
echo "-----------------------" >> $LOGFILE
131+
if [ $VERBOSE -eq 1 ]; then
132+
echo -e "\nYou can re-attach to the Direwolf screen with the following command run via user: $USER"
133+
echo -e " screen -dr direwolf"
134+
echo -e "\nYou can re-attach to the Direwolf screen with the following command run via user: $USER" >> $LOGFILE
135+
echo -e " screen -dr direwolf" >> $LOGFILE
136+
echo -e "\n-----------------------"
137+
echo -e "\n-----------------------" >> $LOGFILE
138+
fi
116139
}
117140

118141
function GUI {
@@ -125,52 +148,68 @@ function GUI {
125148
# Otherwise default to :0 (the Xwindows on the HDMI display)
126149
#
127150
if [ ! $DISPLAY ]; then
128-
echo "No Xdisplay set"
129-
#export DISPLAY=":0"
151+
if [ $VERBOSE -eq 1 ]; then
152+
echo "No initial X-windows DISPLAY variable set"
153+
#export DISPLAY=":0"
154+
fi
130155
fi
131156

132157
#Reviewing for RealVNC sessions (stock in Raspbian Pixel)
133158
if [ -n "`ps -ef | grep vncserver-x11-serviced | grep -v grep`" ]; then
134159
sleep 0.1
135-
echo -e "\nRealVNC found - defaults to connecting to the :0 root window"
160+
if [ $VERBOSE -eq 1 ]; then
161+
echo -e "\nRealVNC found - defaults to connecting to the :0 root window"
162+
fi
136163
elif [ -n "`ps -ef | grep Xtightvnc | grep -v grep`" ]; then
137164
#Reviewing for TightVNC sessions
138-
echo -e "\nTightVNC found - defaults to connecting to the :1 root window"
165+
if [ $VERBOSE -eq 1 ]; then
166+
echo -e "\nTightVNC found - defaults to connecting to the :1 root window"
167+
fi
139168
v=`ps -ef | grep Xtightvnc | grep -v grep`
140169
d=`echo "$v" | sed 's/.*tightvnc *\(:[0-9]\).*/\1/'`
141170
export DISPLAY="$d"
142171
fi
143172

144-
echo "Direwolf in GUI mode start up. All log output recorded to $LOGFILE"
145-
echo "Direwolf in GUI mode start up. All log output recorded to $LOGFILE" >> $LOGFILE
146-
echo "DISPLAY=$DISPLAY"
147-
echo "DISPLAY=$DISPLAY" >> $LOGFILE
148-
149-
#
150-
# Auto adjust the startup for your particular environment: gnome-terminal, xterm, etc.
151-
#
173+
if [ $VERBOSE -eq 1 ]; then
174+
echo -e "Direwolf in GUI mode start up. All log output recorded to $LOGFILE"
175+
echo -e "Direwolf in GUI mode start up. All log output recorded to $LOGFILE" >> $LOGFILE
176+
echo -e "Xwindows display to be used for all Direwolf output: $DISPLAY\n"
177+
echo -e "Xwindows display to be used for all Direwolf output: $DISPLAY\n" >> $LOGFILE
178+
fi
152179

153-
if [ $(which lxterminal) ]; then
154-
#echo "DEBUG: lxterminal stanza"
155-
$(which lxterminal) -l -t "Dire Wolf" -e "$DWCMD" &
156-
CHKERR
157-
SUCCESS=1
158-
elif [ $(which xterm) ]; then
159-
#echo "DEBUG: xterm stanza"
160-
$(which xterm) -bg white -fg black -e "$DWCMD" &
161-
CHKERR
162-
SUCCESS=1
163-
elif [ $(which x-terminal-emulator) ]; then
164-
#echo "DEBUG: x-xterm-emulator stanza"
165-
$(which x-terminal-emulator) -e "$DWCMD" &
166-
CHKERR
167-
SUCCESS=1
180+
if [ "$DISPLAY" != "" ]; then
181+
#
182+
# Auto adjust the startup for your particular environment: gnome-terminal, xterm, etc.
183+
#
184+
185+
if [ $(which lxterminal) ]; then
186+
#echo "DEBUG: lxterminal stanza"
187+
$(which lxterminal) -l -t "Dire Wolf" -e "$DWCMD" &
188+
CHKERR
189+
SUCCESS=1
190+
elif [ $(which xterm) ]; then
191+
#echo "DEBUG: xterm stanza"
192+
$(which xterm) -bg white -fg black -e "$DWCMD" &
193+
CHKERR
194+
SUCCESS=1
195+
elif [ $(which x-terminal-emulator) ]; then
196+
#echo "DEBUG: x-xterm-emulator stanza"
197+
$(which x-terminal-emulator) -e "$DWCMD" &
198+
CHKERR
199+
SUCCESS=1
200+
else
201+
if [ $VERBOSE -eq 1 ]; then
202+
echo "Did not find a vaild X terminal program. Reverting to CLI mode"
203+
echo "Did not find a vaild X terminal program. Reverting to CLI mode" >> $LOGFILE
204+
fi
205+
SUCCESS=0
206+
fi
168207
else
169-
echo "Did not find an X terminal emulator. Reverting to CLI mode"
170-
SUCCESS=0
208+
if [ $VERBOSE -eq 1 ]; then
209+
echo -e "\nXwindows DISPLAY variable unable to be set. Reverting to CLI mode"
210+
echo -e "\nXwindows DISPLAY variable unable to be set. Reverting to CLI mode" >> $LOGFILE
211+
fi
171212
fi
172-
echo "-----------------------"
173-
echo "-----------------------" >> $LOGFILE
174213
}
175214

176215
# -----------------------------------------------------------
@@ -187,18 +226,28 @@ if [ ! -x $DIREWOLF ]; then
187226
echo -e "\nError: Direwolf program not found per the DIREWOLF variable in script. Aborting.\n" >> $LOGFILE
188227
exit 1
189228
fi
229+
if [ ! -f direwolf.conf ]; then
230+
echo -e "\nError: direwolf.conf config file not found in `pwd`. Aborting.\n"
231+
echo -e "\nError: direwolf.conf config file not found in `pwd`. Aborting.\n" >> $LOGFILE
232+
exit 1
233+
fi
190234

191235
# First wait a little while in case we just rebooted
192236
# and the desktop hasn't started up yet.
193237
#
194-
echo -e "\ndw-start.sh"
195-
echo -e "-----------"
196-
#Log the start of the script run and re-run
197-
date
198-
date >> $LOGFILE
199-
200-
#echo -e "Sleeping for 30 seconds to let any boot/reboot delays conclude"
201-
echo -e "Sleeping for 30 seconds to let any boot/reboot delays conclude"
238+
if [ $VERBOSE -eq 1 ]; then
239+
echo -e "\ndw-start.sh"
240+
echo -e "\ndw-start.sh" >> $LOGFILE
241+
echo -e "-----------"
242+
echo -e "-----------" >> $LOGFILE
243+
#Log the start of the script run and re-run
244+
date
245+
date >> $LOGFILE
246+
echo -e "Running in verbose mode. Change the VERBOSE variable in the dw-script.sh to not see this and other text output"
247+
echo -e "Running in verbose mode. Change the VERBOSE variable in the dw-script.sh to not see this and other text output" >> $LOGFILE
248+
echo -e "Sleeping for 30 seconds to let any boot/reboot delays conclude"
249+
echo -e "Sleeping for 30 seconds to let any boot/reboot delays conclude" >> $LOGFILE
250+
fi
202251
sleep 30
203252

204253

@@ -207,26 +256,34 @@ sleep 30
207256
#
208257

209258
a=`ps ax | grep direwolf | grep -vi -e bash -e screen -e grep | awk '{print $1}'`
210-
if [ -n "$a" ]
211-
then
212-
#date >> /tmp/dw-start.log
213-
#echo "Direwolf already running." >> $LOGFILE
214-
exit
259+
if [ -n "$a" ]; then
260+
if [ $VERBOSE -eq 1 ]; then
261+
# Don't send this to STDOUT if running from cron or you'll geta cron email saying that
262+
# direwolf is already running every minute! Ok to send to the log file if you turn on
263+
# VERBOSE
264+
#date >> /tmp/dw-start.log
265+
echo "Direwolf already running. Not starting a new instance." >> $LOGFILE
266+
fi
267+
exit
215268
fi
216269

217270
# Main execution of the script
218271

219272
if [ $RUNMODE == "AUTO" ];then
220273
GUI
221274
if [ $SUCCESS -eq 0 ]; then
275+
#if [ $VERBOSE -eq 1 ]; then
276+
# echo "GUI mode startup failed. Reverting to CLI mode"
277+
# echo "GUI mode startup failed. Reverting to CLI mode" >> $LOGFILE
278+
#fi
222279
CLI
223280
fi
224281
elif [ $RUNMODE == "GUI" ];then
225282
GUI
226283
elif [ $RUNMODE == "CLI" ];then
227284
CLI
228285
else
229-
echo -e "ERROR: illegal run mode given. Giving up"
286+
echo -e "ERROR: illegal dw-start run mode configured. Giving up"
230287
exit 1
231288
fi
232289

0 commit comments

Comments
 (0)