10
10
11
11
# Versioning (this file, not direwolf version)
12
12
# -----------
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
19
21
20
22
23
+ # -------------------------------------
24
+ # User settable variables
25
+ # -------------------------------------
21
26
22
27
# How are you running Direwolf : within a GUI (Xwindows / VNC) or CLI mode
23
28
#
@@ -64,8 +69,16 @@ DWCMD="$DIREWOLF -a 100 -t 0"
64
69
65
70
66
71
# Where will logs go - needs to be writable by non-root users
72
+
67
73
LOGFILE=/var/tmp/dw-start.log
68
74
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
+
69
82
70
83
# -------------------------------------
71
84
# Main functions of the script
@@ -89,30 +102,40 @@ function CLI {
89
102
exit 1
90
103
fi
91
104
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
94
109
95
110
# Screen commands
96
111
# -d m :: starts the command in detached mode
97
112
# -S :: name the session
98
113
# --
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 "
101
121
CHKERR
102
122
SUCCESS=1
103
- echo " "
104
- echo " " >> $LOGFILE
123
+ if [ $VERBOSE -eq 1 ]; then
124
+ echo " "
125
+ echo " " >> $LOGFILE
126
+ fi
105
127
106
128
$SCREEN -list direwolf
107
129
CHKERR
108
130
$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
116
139
}
117
140
118
141
function GUI {
@@ -125,52 +148,68 @@ function GUI {
125
148
# Otherwise default to :0 (the Xwindows on the HDMI display)
126
149
#
127
150
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
130
155
fi
131
156
132
157
# Reviewing for RealVNC sessions (stock in Raspbian Pixel)
133
158
if [ -n " ` ps -ef | grep vncserver-x11-serviced | grep -v grep` " ]; then
134
159
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
136
163
elif [ -n " ` ps -ef | grep Xtightvnc | grep -v grep` " ]; then
137
164
# 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
139
168
v=` ps -ef | grep Xtightvnc | grep -v grep`
140
169
d=` echo " $v " | sed ' s/.*tightvnc *\(:[0-9]\).*/\1/' `
141
170
export DISPLAY=" $d "
142
171
fi
143
172
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
152
179
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
168
207
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
171
212
fi
172
- echo " -----------------------"
173
- echo " -----------------------" >> $LOGFILE
174
213
}
175
214
176
215
# -----------------------------------------------------------
@@ -187,18 +226,28 @@ if [ ! -x $DIREWOLF ]; then
187
226
echo -e " \nError: Direwolf program not found per the DIREWOLF variable in script. Aborting.\n" >> $LOGFILE
188
227
exit 1
189
228
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
190
234
191
235
# First wait a little while in case we just rebooted
192
236
# and the desktop hasn't started up yet.
193
237
#
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
202
251
sleep 30
203
252
204
253
@@ -207,26 +256,34 @@ sleep 30
207
256
#
208
257
209
258
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
215
268
fi
216
269
217
270
# Main execution of the script
218
271
219
272
if [ $RUNMODE == " AUTO" ]; then
220
273
GUI
221
274
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
222
279
CLI
223
280
fi
224
281
elif [ $RUNMODE == " GUI" ]; then
225
282
GUI
226
283
elif [ $RUNMODE == " CLI" ]; then
227
284
CLI
228
285
else
229
- echo -e " ERROR: illegal run mode given . Giving up"
286
+ echo -e " ERROR: illegal dw-start run mode configured . Giving up"
230
287
exit 1
231
288
fi
232
289
0 commit comments