mirror of https://github.com/wb2osz/direwolf.git
Enhanced dw-start.sh script and better documentation.
This commit is contained in:
parent
7f77b29e89
commit
aa28c9cadc
Binary file not shown.
Binary file not shown.
195
dw-start.sh
195
dw-start.sh
|
@ -1,100 +1,171 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
#
|
|
||||||
# Run this from crontab periodically to start up
|
# Run this from crontab periodically to start up
|
||||||
# Dire Wolf automatically.
|
# Dire Wolf automatically.
|
||||||
#
|
|
||||||
# I prefer this method instead of putting something
|
|
||||||
# in ~/.config/autostart. That would start an application
|
|
||||||
# only when the desktop first starts up.
|
|
||||||
#
|
|
||||||
# This method will restart the application if it
|
|
||||||
# crashes or stops for any other reason.
|
|
||||||
#
|
|
||||||
# This script has some specifics the Raspberry Pi.
|
|
||||||
# Some adjustments might be needed for other Linux variations.
|
|
||||||
#
|
|
||||||
|
|
||||||
#
|
# Versioning
|
||||||
# When running from cron, we have a very minimal environment
|
#-----------
|
||||||
# including PATH=/usr/bin:/bin.
|
# v1.2 - KI6ZHD - support different versions of VNC
|
||||||
#
|
# 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
|
||||||
|
|
||||||
export PATH=/usr/local/bin:$PATH
|
|
||||||
|
|
||||||
# First wait a little while in case we just rebooted
|
|
||||||
# and the desktop hasn't started up yet.
|
#How are you running Direwolf : within a GUI (Xwindows / VNC) or CLI mode
|
||||||
#
|
#
|
||||||
|
# AUTO mode is design to try starting direwolf with GUI support and then
|
||||||
sleep 30
|
# if no GUI environment is available, it reverts to CLI support with screen
|
||||||
LOGFILE=/tmp/dw-start.log
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Nothing to do if it is already running.
|
# GUI mode is suited for users with the machine running LXDE/Gnome/KDE or VNC
|
||||||
|
# which auto-logs on (sitting at a login prompt won't work)
|
||||||
#
|
#
|
||||||
|
# CLI mode is suited for say a Raspberry Pi running the Jessie LITE version
|
||||||
|
# where it will run from the CLI w/o requiring Xwindows - uses screen
|
||||||
|
|
||||||
a=`pgrep direwolf`
|
RUNMODE=AUTO
|
||||||
if [ "$a" != "" ]
|
|
||||||
then
|
|
||||||
#date >> /tmp/dw-start.log
|
#Direwolf start up command :: two examples where example one is enabled
|
||||||
#echo "Already running." >> $LOGFILE
|
#
|
||||||
exit
|
# 1. For normal operation as TNC, digipeater, IGate, etc.
|
||||||
|
# Print audio statistics each 100 seconds for troubleshooting.
|
||||||
|
# Change this command to however you wish to start Direwolf
|
||||||
|
DWCMD="direwolf -a 100"
|
||||||
|
#---------------------------------------------------------------
|
||||||
|
#
|
||||||
|
# 2. Alternative for running with SDR receiver.
|
||||||
|
# Piping one application into another makes it a little more complicated.
|
||||||
|
# We need to use bash for the | to be recognized.
|
||||||
|
#DWCMD="bash -c 'rtl_fm -f 144.39M - | direwolf -c sdr.conf -r 24000 -D 1 -'"
|
||||||
|
|
||||||
|
|
||||||
|
#Where will logs go - needs to be writable by non-root users
|
||||||
|
LOGFILE=/var/tmp/dw-start.log
|
||||||
|
|
||||||
|
|
||||||
|
#-------------------------------------
|
||||||
|
# Main functions of the script
|
||||||
|
#-------------------------------------
|
||||||
|
|
||||||
|
#Status variables
|
||||||
|
SUCCESS=0
|
||||||
|
|
||||||
|
function CLI {
|
||||||
|
SCREEN=`which screen`
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
echo -e "Error: screen is not installed but is required for CLI mode. Aborting"
|
||||||
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
#
|
echo "Direwolf in CLI mode start up"
|
||||||
|
echo "Direwolf in CLI mode start up" >> $LOGFILE
|
||||||
|
|
||||||
|
# Screen commands
|
||||||
|
# -d m :: starts the command in detached mode
|
||||||
|
# -S :: name the session
|
||||||
|
$SCREEN -d -m -S direwolf $DWCMD
|
||||||
|
SUCCESS=1
|
||||||
|
|
||||||
|
screen -list direwolf
|
||||||
|
screen -list direwolf >> $LOGFILE
|
||||||
|
|
||||||
|
echo "-----------------------"
|
||||||
|
echo "-----------------------" >> $LOGFILE
|
||||||
|
}
|
||||||
|
|
||||||
|
function GUI {
|
||||||
|
# In this case
|
||||||
# In my case, the Raspberry Pi is not connected to a monitor.
|
# In my case, the Raspberry Pi is not connected to a monitor.
|
||||||
# I access it remotely using VNC as described here:
|
# I access it remotely using VNC as described here:
|
||||||
# http://learn.adafruit.com/adafruit-raspberry-pi-lesson-7-remote-control-with-vnc
|
# http://learn.adafruit.com/adafruit-raspberry-pi-lesson-7-remote-control-with-vnc
|
||||||
#
|
#
|
||||||
# If VNC server is running, use its display number.
|
# If VNC server is running, use its display number.
|
||||||
# Otherwise default to :0.
|
# Otherwise default to :0 (the Xwindows on the HDMI display)
|
||||||
#
|
#
|
||||||
|
|
||||||
date >> $LOGFILE
|
|
||||||
|
|
||||||
export DISPLAY=":0"
|
export DISPLAY=":0"
|
||||||
|
|
||||||
|
#Reviewing for RealVNC sessions (stock in Raspbian Pixel)
|
||||||
|
if [ -n "`ps -ef | grep vncserver-x11-serviced | grep -v grep`" ]; then
|
||||||
|
sleep 0.1
|
||||||
|
echo -e "\nRealVNC found - defaults to connecting to the :0 root window"
|
||||||
|
elif [ -n "`ps -ef | grep Xtightvnc | grep -v grep`" ]; then
|
||||||
|
#Reviewing for TightVNC sessions
|
||||||
|
echo -e "\nTightVNC found - defaults to connecting to the :1 root window"
|
||||||
v=`ps -ef | grep Xtightvnc | grep -v grep`
|
v=`ps -ef | grep Xtightvnc | grep -v grep`
|
||||||
if [ "$v" != "" ]
|
|
||||||
then
|
|
||||||
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"
|
||||||
|
echo "Direwolf in GUI mode start up" >> $LOGFILE
|
||||||
|
echo "DISPLAY=$DISPLAY"
|
||||||
echo "DISPLAY=$DISPLAY" >> $LOGFILE
|
echo "DISPLAY=$DISPLAY" >> $LOGFILE
|
||||||
|
|
||||||
echo "Start up application." >> $LOGFILE
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# For normal operation as TNC, digipeater, IGate, etc.
|
# Auto adjust the startup for your particular environment: gnome-terminal, xterm, etc.
|
||||||
# Print audio statistics each 100 seconds for troubleshooting.
|
|
||||||
#
|
#
|
||||||
|
|
||||||
DWCMD="direwolf -a 100"
|
if [ -x /usr/bin/lxterminal ]; then
|
||||||
|
|
||||||
# Alternative for running with SDR receiver.
|
|
||||||
# Piping one application into another makes it a little more complicated.
|
|
||||||
# We need to use bash for the | to be recognized.
|
|
||||||
|
|
||||||
#DWCMD="bash -c 'rtl_fm -f 144.39M - | direwolf -c sdr.conf -r 24000 -D 1 -'"
|
|
||||||
|
|
||||||
#
|
|
||||||
# Adjust for your particular situation: gnome-terminal, xterm, etc.
|
|
||||||
#
|
|
||||||
|
|
||||||
|
|
||||||
if [ -x /usr/bin/lxterminal ]
|
|
||||||
then
|
|
||||||
/usr/bin/lxterminal -t "Dire Wolf" -e "$DWCMD" &
|
/usr/bin/lxterminal -t "Dire Wolf" -e "$DWCMD" &
|
||||||
elif [ -x /usr/bin/xterm ]
|
SUCCESS=1
|
||||||
then
|
elif [ -x /usr/bin/xterm ]; then
|
||||||
/usr/bin/xterm -bg white -fg black -e "$DWCMD" &
|
/usr/bin/xterm -bg white -fg black -e "$DWCMD" &
|
||||||
elif [ -x /usr/bin/x-terminal-emulator ]
|
SUCCESS=1
|
||||||
then
|
elif [ -x /usr/bin/x-terminal-emulator ]; then
|
||||||
/usr/bin/x-terminal-emulator -e "$DWCMD" &
|
/usr/bin/x-terminal-emulator -e "$DWCMD" &
|
||||||
|
SUCCESS=1
|
||||||
else
|
else
|
||||||
echo "Did not find an X terminal emulator."
|
echo "Did not find an X terminal emulator. Reverting to CLI mode"
|
||||||
|
SUCCESS=0
|
||||||
|
fi
|
||||||
|
echo "-----------------------"
|
||||||
|
echo "-----------------------" >> $LOGFILE
|
||||||
|
}
|
||||||
|
|
||||||
|
# -----------------------------------------------------------
|
||||||
|
# Main Script start
|
||||||
|
# -----------------------------------------------------------
|
||||||
|
|
||||||
|
# When running from cron, we have a very minimal environment
|
||||||
|
# including PATH=/usr/bin:/bin.
|
||||||
|
#
|
||||||
|
export PATH=/usr/local/bin:$PATH
|
||||||
|
|
||||||
|
#Log the start of the script run and re-run
|
||||||
|
date >> $LOGFILE
|
||||||
|
|
||||||
|
# First wait a little while in case we just rebooted
|
||||||
|
# and the desktop hasn't started up yet.
|
||||||
|
#
|
||||||
|
sleep 30
|
||||||
|
|
||||||
|
|
||||||
|
#
|
||||||
|
# Nothing to do if Direwolf is already running.
|
||||||
|
#
|
||||||
|
|
||||||
|
a=`ps ax | grep direwolf | grep -vi -e bash -e screen -e grep | awk '{print $1}'`
|
||||||
|
if [ -n "$a" ]
|
||||||
|
then
|
||||||
|
#date >> /tmp/dw-start.log
|
||||||
|
#echo "Direwolf already running." >> $LOGFILE
|
||||||
|
exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "-----------------------" >> $LOGFILE
|
# Main execution of the script
|
||||||
|
|
||||||
|
if [ $RUNMODE == "AUTO" ];then
|
||||||
|
GUI
|
||||||
|
if [ $SUCCESS -eq 0 ]; then
|
||||||
|
CLI
|
||||||
|
fi
|
||||||
|
elif [ $RUNMODE == "GUI" ];then
|
||||||
|
GUI
|
||||||
|
elif [ $RUNMODE == "CLI" ];then
|
||||||
|
CLI
|
||||||
|
else
|
||||||
|
echo -e "ERROR: illegal run mode given. Giving up"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue