mirror of https://github.com/wb2osz/direwolf.git
Improved support for cron start, new checks startup method, added STDOUT filtering to avoid chatty cron emails or log
This commit is contained in:
parent
6c9f3fa401
commit
ef00a37d3e
189
dw-start.sh
189
dw-start.sh
|
@ -10,14 +10,19 @@
|
||||||
|
|
||||||
# Versioning (this file, not direwolf version)
|
# Versioning (this file, not direwolf version)
|
||||||
#-----------
|
#-----------
|
||||||
# v1.6 - KI6ZHD - Update to auto-detect binary paths and updated GUI start
|
# v1.6.1 - KI6ZHD - Improved support for cron start, new checks startup method,
|
||||||
# v1.3 - KI6ZHD - added variable support for direwolf binary location
|
# added STDOUT filtering to avoid chatty cron emails or logs
|
||||||
# v1.2 - KI6ZHD - support different versions of VNC
|
# v1.6 - KI6ZHD - Update to auto-detect binary paths and updated GUI start
|
||||||
# v1.1 - KI6ZHD - expanded version to support running on text-only displays with
|
# v1.3 - KI6ZHD - added variable support for direwolf binary location
|
||||||
# auto support; log placement change
|
# v1.2 - KI6ZHD - support different versions of VNC
|
||||||
# v1.0 - WB2OSZ - original version for Xwindow displays only
|
# v1.1 - KI6ZHD - expanded version to support running on text-only displays with
|
||||||
|
# auto support; log placement change
|
||||||
|
# v1.0 - WB2OSZ - original version for Xwindow displays only
|
||||||
|
|
||||||
|
|
||||||
|
#-------------------------------------
|
||||||
|
# User settable variables
|
||||||
|
#-------------------------------------
|
||||||
|
|
||||||
#How are you running Direwolf : within a GUI (Xwindows / VNC) or CLI mode
|
#How are you running Direwolf : within a GUI (Xwindows / VNC) or CLI mode
|
||||||
#
|
#
|
||||||
|
@ -64,8 +69,16 @@ DWCMD="$DIREWOLF -a 100 -t 0"
|
||||||
|
|
||||||
|
|
||||||
#Where will logs go - needs to be writable by non-root users
|
#Where will logs go - needs to be writable by non-root users
|
||||||
|
|
||||||
LOGFILE=/var/tmp/dw-start.log
|
LOGFILE=/var/tmp/dw-start.log
|
||||||
|
|
||||||
|
#Script STDOUT and logging output control
|
||||||
|
# Set this varaible to 0 if you won't want to see all STDOUT
|
||||||
|
# logging once you get everything working properly
|
||||||
|
|
||||||
|
VERBOSE=1
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#-------------------------------------
|
#-------------------------------------
|
||||||
# Main functions of the script
|
# Main functions of the script
|
||||||
|
@ -89,30 +102,40 @@ function CLI {
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Direwolf in CLI mode start up. All log output recorded to $LOGFILE"
|
if [ $VERBOSE -eq 1 ]; then
|
||||||
echo "Direwolf in CLI mode start up. All log output recorded to $LOGFILE" >> $LOGFILE
|
echo "Direwolf in CLI mode start up. All log output recorded to $LOGFILE"
|
||||||
|
echo "Direwolf in CLI mode start up. All log output recorded to $LOGFILE" >> $LOGFILE
|
||||||
|
fi
|
||||||
|
|
||||||
# Screen commands
|
# Screen commands
|
||||||
# -d m :: starts the command in detached mode
|
# -d m :: starts the command in detached mode
|
||||||
# -S :: name the session
|
# -S :: name the session
|
||||||
# --
|
# --
|
||||||
# Remove the "-d m" if you don't want screen to detach and not show direwolf"
|
# Options:
|
||||||
$SCREEN -d -m -S direwolf $DWCMD >> $LOGFILE
|
# 1. Remove the "-d m" parameters if you don't want screen to automatically detach
|
||||||
|
# and instead say in the foreground
|
||||||
|
# 2. Remove the " >> $LOGFILE" if you rather keep all the Direwolf running output
|
||||||
|
# in the screen session vs going to the log file
|
||||||
|
#
|
||||||
|
$SCREEN -d -m -S direwolf bash -c "echo 'All Direwolf output going to $LOGFILE. Enter control-c to terminate Direwolf'; $DWCMD >> $LOGFILE"
|
||||||
CHKERR
|
CHKERR
|
||||||
SUCCESS=1
|
SUCCESS=1
|
||||||
echo " "
|
if [ $VERBOSE -eq 1 ]; then
|
||||||
echo " " >> $LOGFILE
|
echo " "
|
||||||
|
echo " " >> $LOGFILE
|
||||||
|
fi
|
||||||
|
|
||||||
$SCREEN -list direwolf
|
$SCREEN -list direwolf
|
||||||
CHKERR
|
CHKERR
|
||||||
$SCREEN -list direwolf >> $LOGFILE
|
$SCREEN -list direwolf >> $LOGFILE
|
||||||
echo -e "\nYou can re-attach to the Direwolf screen with:"
|
if [ $VERBOSE -eq 1 ]; then
|
||||||
echo -e " screen -dr direwolf"
|
echo -e "\nYou can re-attach to the Direwolf screen with the following command run via user: $USER"
|
||||||
echo -e "\nYou can re-attach to the Direwolf screen with:" >> $LOGFILE
|
echo -e " screen -dr direwolf"
|
||||||
echo -e " screen -dr direwolf" >> $LOGFILE
|
echo -e "\nYou can re-attach to the Direwolf screen with the following command run via user: $USER" >> $LOGFILE
|
||||||
|
echo -e " screen -dr direwolf" >> $LOGFILE
|
||||||
echo "-----------------------"
|
echo -e "\n-----------------------"
|
||||||
echo "-----------------------" >> $LOGFILE
|
echo -e "\n-----------------------" >> $LOGFILE
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function GUI {
|
function GUI {
|
||||||
|
@ -125,52 +148,68 @@ function GUI {
|
||||||
# Otherwise default to :0 (the Xwindows on the HDMI display)
|
# Otherwise default to :0 (the Xwindows on the HDMI display)
|
||||||
#
|
#
|
||||||
if [ ! $DISPLAY ]; then
|
if [ ! $DISPLAY ]; then
|
||||||
echo "No Xdisplay set"
|
if [ $VERBOSE -eq 1 ]; then
|
||||||
#export DISPLAY=":0"
|
echo "No initial X-windows DISPLAY variable set"
|
||||||
|
#export DISPLAY=":0"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
#Reviewing for RealVNC sessions (stock in Raspbian Pixel)
|
#Reviewing for RealVNC sessions (stock in Raspbian Pixel)
|
||||||
if [ -n "`ps -ef | grep vncserver-x11-serviced | grep -v grep`" ]; then
|
if [ -n "`ps -ef | grep vncserver-x11-serviced | grep -v grep`" ]; then
|
||||||
sleep 0.1
|
sleep 0.1
|
||||||
echo -e "\nRealVNC found - defaults to connecting to the :0 root window"
|
if [ $VERBOSE -eq 1 ]; then
|
||||||
|
echo -e "\nRealVNC found - defaults to connecting to the :0 root window"
|
||||||
|
fi
|
||||||
elif [ -n "`ps -ef | grep Xtightvnc | grep -v grep`" ]; then
|
elif [ -n "`ps -ef | grep Xtightvnc | grep -v grep`" ]; then
|
||||||
#Reviewing for TightVNC sessions
|
#Reviewing for TightVNC sessions
|
||||||
echo -e "\nTightVNC found - defaults to connecting to the :1 root window"
|
if [ $VERBOSE -eq 1 ]; then
|
||||||
|
echo -e "\nTightVNC found - defaults to connecting to the :1 root window"
|
||||||
|
fi
|
||||||
v=`ps -ef | grep Xtightvnc | grep -v grep`
|
v=`ps -ef | grep Xtightvnc | grep -v grep`
|
||||||
d=`echo "$v" | sed 's/.*tightvnc *\(:[0-9]\).*/\1/'`
|
d=`echo "$v" | sed 's/.*tightvnc *\(:[0-9]\).*/\1/'`
|
||||||
export DISPLAY="$d"
|
export DISPLAY="$d"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Direwolf in GUI mode start up. All log output recorded to $LOGFILE"
|
if [ $VERBOSE -eq 1 ]; then
|
||||||
echo "Direwolf in GUI mode start up. All log output recorded to $LOGFILE" >> $LOGFILE
|
echo -e "Direwolf in GUI mode start up. All log output recorded to $LOGFILE"
|
||||||
echo "DISPLAY=$DISPLAY"
|
echo -e "Direwolf in GUI mode start up. All log output recorded to $LOGFILE" >> $LOGFILE
|
||||||
echo "DISPLAY=$DISPLAY" >> $LOGFILE
|
echo -e "Xwindows display to be used for all Direwolf output: $DISPLAY\n"
|
||||||
|
echo -e "Xwindows display to be used for all Direwolf output: $DISPLAY\n" >> $LOGFILE
|
||||||
#
|
fi
|
||||||
# Auto adjust the startup for your particular environment: gnome-terminal, xterm, etc.
|
|
||||||
#
|
if [ "$DISPLAY" != "" ]; then
|
||||||
|
#
|
||||||
if [ $(which lxterminal) ]; then
|
# Auto adjust the startup for your particular environment: gnome-terminal, xterm, etc.
|
||||||
#echo "DEBUG: lxterminal stanza"
|
#
|
||||||
$(which lxterminal) -l -t "Dire Wolf" -e "$DWCMD" &
|
|
||||||
CHKERR
|
if [ $(which lxterminal) ]; then
|
||||||
SUCCESS=1
|
#echo "DEBUG: lxterminal stanza"
|
||||||
elif [ $(which xterm) ]; then
|
$(which lxterminal) -l -t "Dire Wolf" -e "$DWCMD" &
|
||||||
#echo "DEBUG: xterm stanza"
|
CHKERR
|
||||||
$(which xterm) -bg white -fg black -e "$DWCMD" &
|
SUCCESS=1
|
||||||
CHKERR
|
elif [ $(which xterm) ]; then
|
||||||
SUCCESS=1
|
#echo "DEBUG: xterm stanza"
|
||||||
elif [ $(which x-terminal-emulator) ]; then
|
$(which xterm) -bg white -fg black -e "$DWCMD" &
|
||||||
#echo "DEBUG: x-xterm-emulator stanza"
|
CHKERR
|
||||||
$(which x-terminal-emulator) -e "$DWCMD" &
|
SUCCESS=1
|
||||||
CHKERR
|
elif [ $(which x-terminal-emulator) ]; then
|
||||||
SUCCESS=1
|
#echo "DEBUG: x-xterm-emulator stanza"
|
||||||
else
|
$(which x-terminal-emulator) -e "$DWCMD" &
|
||||||
echo "Did not find an X terminal emulator. Reverting to CLI mode"
|
CHKERR
|
||||||
SUCCESS=0
|
SUCCESS=1
|
||||||
|
else
|
||||||
|
if [ $VERBOSE -eq 1 ]; then
|
||||||
|
echo "Did not find a vaild X terminal program. Reverting to CLI mode"
|
||||||
|
echo "Did not find a vaild X terminal program. Reverting to CLI mode" >> $LOGFILE
|
||||||
|
fi
|
||||||
|
SUCCESS=0
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
if [ $VERBOSE -eq 1 ]; then
|
||||||
|
echo -e "\nXwindows DISPLAY variable unable to be set. Reverting to CLI mode"
|
||||||
|
echo -e "\nXwindows DISPLAY variable unable to be set. Reverting to CLI mode" >> $LOGFILE
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
echo "-----------------------"
|
|
||||||
echo "-----------------------" >> $LOGFILE
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# -----------------------------------------------------------
|
# -----------------------------------------------------------
|
||||||
|
@ -187,18 +226,28 @@ if [ ! -x $DIREWOLF ]; then
|
||||||
echo -e "\nError: Direwolf program not found per the DIREWOLF variable in script. Aborting.\n" >> $LOGFILE
|
echo -e "\nError: Direwolf program not found per the DIREWOLF variable in script. Aborting.\n" >> $LOGFILE
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
if [ ! -f direwolf.conf ]; then
|
||||||
|
echo -e "\nError: direwolf.conf config file not found in `pwd`. Aborting.\n"
|
||||||
|
echo -e "\nError: direwolf.conf config file not found in `pwd`. Aborting.\n" >> $LOGFILE
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
# First wait a little while in case we just rebooted
|
# First wait a little while in case we just rebooted
|
||||||
# and the desktop hasn't started up yet.
|
# and the desktop hasn't started up yet.
|
||||||
#
|
#
|
||||||
echo -e "\ndw-start.sh"
|
if [ $VERBOSE -eq 1 ]; then
|
||||||
echo -e "-----------"
|
echo -e "\ndw-start.sh"
|
||||||
#Log the start of the script run and re-run
|
echo -e "\ndw-start.sh" >> $LOGFILE
|
||||||
date
|
echo -e "-----------"
|
||||||
date >> $LOGFILE
|
echo -e "-----------" >> $LOGFILE
|
||||||
|
#Log the start of the script run and re-run
|
||||||
#echo -e "Sleeping for 30 seconds to let any boot/reboot delays conclude"
|
date
|
||||||
echo -e "Sleeping for 30 seconds to let any boot/reboot delays conclude"
|
date >> $LOGFILE
|
||||||
|
echo -e "Running in verbose mode. Change the VERBOSE variable in the dw-script.sh to not see this and other text output"
|
||||||
|
echo -e "Running in verbose mode. Change the VERBOSE variable in the dw-script.sh to not see this and other text output" >> $LOGFILE
|
||||||
|
echo -e "Sleeping for 30 seconds to let any boot/reboot delays conclude"
|
||||||
|
echo -e "Sleeping for 30 seconds to let any boot/reboot delays conclude" >> $LOGFILE
|
||||||
|
fi
|
||||||
sleep 30
|
sleep 30
|
||||||
|
|
||||||
|
|
||||||
|
@ -207,11 +256,15 @@ sleep 30
|
||||||
#
|
#
|
||||||
|
|
||||||
a=`ps ax | grep direwolf | grep -vi -e bash -e screen -e grep | awk '{print $1}'`
|
a=`ps ax | grep direwolf | grep -vi -e bash -e screen -e grep | awk '{print $1}'`
|
||||||
if [ -n "$a" ]
|
if [ -n "$a" ]; then
|
||||||
then
|
if [ $VERBOSE -eq 1 ]; then
|
||||||
#date >> /tmp/dw-start.log
|
# Don't send this to STDOUT if running from cron or you'll geta cron email saying that
|
||||||
#echo "Direwolf already running." >> $LOGFILE
|
# direwolf is already running every minute! Ok to send to the log file if you turn on
|
||||||
exit
|
# VERBOSE
|
||||||
|
#date >> /tmp/dw-start.log
|
||||||
|
echo "Direwolf already running. Not starting a new instance." >> $LOGFILE
|
||||||
|
fi
|
||||||
|
exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Main execution of the script
|
# Main execution of the script
|
||||||
|
@ -219,6 +272,10 @@ fi
|
||||||
if [ $RUNMODE == "AUTO" ];then
|
if [ $RUNMODE == "AUTO" ];then
|
||||||
GUI
|
GUI
|
||||||
if [ $SUCCESS -eq 0 ]; then
|
if [ $SUCCESS -eq 0 ]; then
|
||||||
|
#if [ $VERBOSE -eq 1 ]; then
|
||||||
|
# echo "GUI mode startup failed. Reverting to CLI mode"
|
||||||
|
# echo "GUI mode startup failed. Reverting to CLI mode" >> $LOGFILE
|
||||||
|
#fi
|
||||||
CLI
|
CLI
|
||||||
fi
|
fi
|
||||||
elif [ $RUNMODE == "GUI" ];then
|
elif [ $RUNMODE == "GUI" ];then
|
||||||
|
@ -226,7 +283,7 @@ if [ $RUNMODE == "AUTO" ];then
|
||||||
elif [ $RUNMODE == "CLI" ];then
|
elif [ $RUNMODE == "CLI" ];then
|
||||||
CLI
|
CLI
|
||||||
else
|
else
|
||||||
echo -e "ERROR: illegal run mode given. Giving up"
|
echo -e "ERROR: illegal dw-start run mode configured. Giving up"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue