1
0
mirror of https://github.com/AG7GN/nexus-utilities.git synced 2025-05-18 07:30:07 -07:00

Fixed trap actions

This commit is contained in:
Steve Magnuson 2020-02-08 10:14:38 -08:00
parent 7993b2f1d1
commit c70dfaa1ae

74
tnc.sh
View File

@ -97,7 +97,7 @@
#% #%
#================================================================ #================================================================
#- IMPLEMENTATION #- IMPLEMENTATION
#- version ${SCRIPT_NAME} 3.3.2 #- version ${SCRIPT_NAME} 3.3.6
#- author Steve Magnuson, AG7GN #- author Steve Magnuson, AG7GN
#- license CC-BY-SA Creative Commons License #- license CC-BY-SA Creative Commons License
#- script_id 0 #- script_id 0
@ -123,22 +123,18 @@ DEBUG=false
# FUNCTIONS # FUNCTIONS
#============================ #============================
function TrapCleanup() { function TrapCleanup () {
${SCRIPT_NAME} stop ${SCRIPT_NAME} stop
rm -f /tmp/tnc*
rm -f $CONFFILE
exit 0 exit 0
} }
function SafeExit() { function SafeExit () {
${SCRIPT_NAME} stop rm -f /tmp/tnc*
rm -f /tmp/tnc*
rm -f $CONFFILE rm -f $CONFFILE
trap - INT TERM EXIT
exit exit
} }
function ScriptInfo() { function ScriptInfo () {
HEAD_FILTER="^#-" HEAD_FILTER="^#-"
[[ "$1" = "usage" ]] && HEAD_FILTER="^#+" [[ "$1" = "usage" ]] && HEAD_FILTER="^#+"
[[ "$1" = "full" ]] && HEAD_FILTER="^#[%+]" [[ "$1" = "full" ]] && HEAD_FILTER="^#[%+]"
@ -148,15 +144,15 @@ function ScriptInfo() {
-e "s/\${SCRIPT_NAME}/${SCRIPT_NAME}/g" -e "s/\${SCRIPT_NAME}/${SCRIPT_NAME}/g"
} }
function Usage() { function Usage () {
printf "Usage:\n" printf "Usage:\n"
ScriptInfo usage ScriptInfo usage
exit 1 exit 0
} }
function Die () { function Die () {
echo "${*}" echo "${*}"
SafeExit exit 1
} }
#--------------------------------------- #---------------------------------------
@ -468,7 +464,8 @@ shift $((${OPTIND} - 1)) ## shift options
#============================ #============================
# Trap bad exits with cleanup function # Trap bad exits with cleanup function
trap SafeExit EXIT INT TERM trap TrapCleanup INT
trap SafeExit TERM EXIT
# Exit on error. Append '||true' when you run the script if you expect an error. # Exit on error. Append '||true' when you run the script if you expect an error.
set -o errexit set -o errexit
@ -592,7 +589,7 @@ case "$ACTION" in
[[ "$SCR" != "" ]] && { pkill piardop2; $SCREEN -S $SCR -X quit; } [[ "$SCR" != "" ]] && { pkill piardop2; $SCREEN -S $SCR -X quit; }
done done
## Kill existing session if it exists ## Kill existing session if it exists
pgrep kissattach >/dev/null && kill $(pgrep kissattach) pgrep kissattach >/dev/null && sudo kill $(pgrep kissattach)
## Are the apps installed? ## Are the apps installed?
for i in kissattach kissparms for i in kissattach kissparms
do do
@ -743,34 +740,33 @@ case "$ACTION" in
esac esac
;; ;;
stop) stop)
ORDERS=( rigctld piardop2 direwolf pat ) ORDERS=( rigctld piardop2 direwolf pat )
#ORDERS=( rigctld direwolf ) #ORDERS=( rigctld direwolf )
echo echo
for i in ${!ORDERS[@]} for i in ${!ORDERS[@]}
do do
SCR="$($SCREEN -list | grep ${ORDERS[$i]} | tr -d ' \t' | cut -d'(' -f1 | tr -d '\n')" SCR="$($SCREEN -list | grep ${ORDERS[$i]} | tr -d ' \t' | cut -d'(' -f1 | tr -d '\n')"
if [[ "$SCR" != "" ]] if [[ "$SCR" != "" ]]
then then
echo -n "Stopping $SCR..." echo -n "Stopping $SCR..."
$SCREEN -S $SCR -X quit $SCREEN -S $SCR -X quit
echo "done."
else
echo "Stopping ${ORDERS[$i]}: ${ORDERS[$i]} not running"
fi
done
pgrep piardop2 >/dev/null && kill -9 $(pgrep piardop2)
KISSATTACHPID="$(pgrep kissattach)"
if [[ $KISSATTACHPID != "" ]]
then
echo -n "Stopping kissattach..."
sudo killall kissattach
rm -f /tmp/kisstnc
echo "done." echo "done."
fi else
echo "Stopping ${ORDERS[$i]}: ${ORDERS[$i]} not running"
fi
done
pgrep piardop2 >/dev/null && kill -9 $(pgrep piardop2)
KISSATTACHPID="$(pgrep kissattach)"
if [[ $KISSATTACHPID != "" ]]
then
echo -n "Stopping kissattach..."
sudo killall kissattach
rm -f /tmp/kisstnc
echo "done."
fi
;; ;;
*) *)
Usage Usage
;; ;;
esac esac
SafeExit