fixed dos line-endings

This commit is contained in:
pyr0ball 2022-03-23 14:22:49 -07:00
parent b3b3292022
commit 9ab589cae7
3 changed files with 467 additions and 455 deletions

View file

@ -1,101 +1,101 @@
#!/bin/bash #!/bin/bash
# initial vars # initial vars
rundir=${0%/*} rundir=${0%/*}
source ${rundir}/functions source ${rundir}/functions
scriptname=${0##*/} scriptname=${0##*/}
runuser=$(whoami) runuser=$(whoami)
#-----------------------------------------------------------------# #-----------------------------------------------------------------#
# Script-specific Parameters # Script-specific Parameters
#-----------------------------------------------------------------# #-----------------------------------------------------------------#
VERSION=1.0 VERSION=1.0
bashrc_append="if [ -n \"$BASH_VERSION\" ]; then bashrc_append="if [ -n \"$BASH_VERSION\" ]; then
# include .bashrc if it exists # include .bashrc if it exists
if [ -d \"$HOME/.bashrc.d\" ]; then if [ -d \"$HOME/.bashrc.d\" ]; then
for file in $HOME/.bashrc.d/*.bashrc ; do for file in $HOME/.bashrc.d/*.bashrc ; do
source \"$file\" source \"$file\"
done done
fi fi
fi" fi"
packages=( packages=(
git git
vim vim
nfs-kernel-server nfs-kernel-server
nfs-common nfs-common
) )
globalinstalldir="/usr/lib/pyr0-bash" globalinstalldir="/usr/lib/pyr0-bash"
#-----------------------------------------------------------------# #-----------------------------------------------------------------#
# Script-specific Funcitons # Script-specific Funcitons
#-----------------------------------------------------------------# #-----------------------------------------------------------------#
usage(){ usage(){
boxtop boxtop
boxline "${lyl}$scriptname - v${VERSION}:${dfl}" boxline "${lyl}$scriptname - v${VERSION}:${dfl}"
boxline "${lbl}Usage:${dfl}" boxline "${lbl}Usage:${dfl}"
boxline "${lyl}$scriptname ${bld}[args]" boxline "${lyl}$scriptname ${bld}[args]"
boxseparator boxseparator
boxline "[args:]" boxline "[args:]"
boxline " -i [--install]" boxline " -i [--install]"
boxline " -r [--remove]" boxline " -r [--remove]"
boxline " -u [--update]" boxline " -u [--update]"
boxline " -h [--help]" boxline " -h [--help]"
boxbottom boxbottom
} }
install(){ install(){
mkdir -p ${globalinstalldir} mkdir -p ${globalinstalldir}
cp ${rundir}/functions ${globalinstalldir}/functions cp ${rundir}/functions ${globalinstalldir}/functions
cp -r $rundir/lib/skel/* $HOME cp -r $rundir/lib/skel/* $HOME
cp $rundir/lib/vimfiles/crystallite.vim /usr/share/vim/vim*/colors/crystallite.vim cp $rundir/lib/vimfiles/crystallite.vim /usr/share/vim/vim*/colors/crystallite.vim
cp $rundir/lib/vimfiles/vimrc.local /etc/vim/vimrc.local cp $rundir/lib/vimfiles/vimrc.local /etc/vim/vimrc.local
echo -e $bashrc_append >> $HOME/.bashrc echo -e $bashrc_append >> $HOME/.bashrc
} }
remove(){ remove(){
echo -e "\n" echo -e "\n"
} }
update(){ update(){
pushd $rundir pushd $rundir
remove remove
git fetch && git pull git fetch && git pull
install install
popd popd
} }
#------------------------------------------------------# #------------------------------------------------------#
# Options and Arguments Parser # Options and Arguments Parser
#------------------------------------------------------# #------------------------------------------------------#
if [[ $runuser == root ]] ; then if [[ $runuser == root ]] ; then
case $1 in case $1 in
-i | --install) -i | --install)
install install
;; ;;
-r | --remove) -r | --remove)
remove remove
;; ;;
-u | --update) -u | --update)
update update
#sleep $ratelimit #sleep $ratelimit
exit 0 exit 0
;; ;;
-h | --help) -h | --help)
usage usage
;; ;;
*) *)
warn "Invalid argument $@" warn "Invalid argument $@"
usage usage
#exit 2 #exit 2
;; ;;
esac esac
else else
fail "Must be run as user 'root'" fail "Must be run as user 'root'"
fi fi
#------------------------------------------------------# #------------------------------------------------------#
# Script begins here # Script begins here
#------------------------------------------------------# #------------------------------------------------------#

View file

@ -29,4 +29,16 @@ case `select_opt "${options[@]}"` in
0) echo "selected Yes";; 0) echo "selected Yes";;
1) echo "selected No";; 1) echo "selected No";;
*) echo "selected ${options[$?]}";; *) echo "selected ${options[$?]}";;
esac esac
# Example for above multiselect functions
my_options=( "Option 1" "Option 2" "Option 3" )
preselection=( "true" "true" "false" )
multiselect result my_options preselection
idx=0
for option in "${my_options[@]}"; do
echo -e "$option\t=> ${result[idx]}"
((idx++))
done

View file

@ -1,354 +1,354 @@
#!/bin/bash #!/bin/bash
# Moxa NPort Driver loader and watchdog script # Moxa NPort Driver loader and watchdog script
# initial vars # initial vars
scriptname=${0##*/} scriptname=${0##*/}
rundir=${0%/*} rundir=${0%/*}
source ${rundir}/functions source ${rundir}/functions
#-----------------------------------------------------------------# #-----------------------------------------------------------------#
# Script-specific Parameters # Script-specific Parameters
#-----------------------------------------------------------------# #-----------------------------------------------------------------#
VERSION=1.0 VERSION=1.0
logfile=/var/log/bdv/moxaloader.log logfile=/var/log/bdv/moxaloader.log
ratelimit=15 ratelimit=15
rst_threshold=1 rst_threshold=1
god=/opt/ruby-enterprise/bin/god god=/opt/ruby-enterprise/bin/god
pingfile=/usr/lib/npreal2/driver/pingup pingfile=/usr/lib/npreal2/driver/pingup
daemonpid=$(ps -ef | grep -v grep | grep moxaloader.*daemon | awk {'print $2'}) daemonpid=$(ps -ef | grep -v grep | grep moxaloader.*daemon | awk {'print $2'})
config_sh=$(grep DNS /.AVC-X/etc/networking/profiles/default/ifcfg-Public) config_sh=$(grep DNS /.AVC-X/etc/networking/profiles/default/ifcfg-Public)
resolv_conf=$(grep nameserver /.AVC-X/etc/networking/profiles/default/resolv.conf) resolv_conf=$(grep nameserver /.AVC-X/etc/networking/profiles/default/resolv.conf)
config_dev=$(grep DNS /.AVC-X/etc/networking/devices/ifcfg-Public) config_dev=$(grep DNS /.AVC-X/etc/networking/devices/ifcfg-Public)
sys_resolv_conf=$(grep nameserver /etc/resolv.conf) sys_resolv_conf=$(grep nameserver /etc/resolv.conf)
etc_net_sh=$(grep DNS /etc/network-scripts/ifcfg-Public) etc_net_sh=$(grep DNS /etc/network-scripts/ifcfg-Public)
dns=$(grep DNS1 /.AVC-X/etc/networking/profiles/default/ifcfg-Public | cut -c 6-) dns=$(grep DNS1 /.AVC-X/etc/networking/profiles/default/ifcfg-Public | cut -c 6-)
#-----------------------------------------------------------------# #-----------------------------------------------------------------#
# Script-specific Funcitons # Script-specific Funcitons
#-----------------------------------------------------------------# #-----------------------------------------------------------------#
usage(){ usage(){
boxtop boxtop
boxline "${lyl}Moxa NPort Watchdog & Recovery v$VERSION${dfl}" boxline "${lyl}Moxa NPort Watchdog & Recovery v$VERSION${dfl}"
boxseparator boxseparator
boxline "Usage:" boxline "Usage:"
boxline "$scriptname [FUNCTIONS][-d|--daemon|--usage|--version]" boxline "$scriptname [FUNCTIONS][-d|--daemon|--usage|--version]"
boxseparator boxseparator
boxline "-s | --start - Initializes the Moxa NPort Driver only and exits" boxline "-s | --start - Initializes the Moxa NPort Driver only and exits"
boxline "-S | --stop - stops the NPort driver and any ongoing daemonized watchdog" boxline "-S | --stop - stops the NPort driver and any ongoing daemonized watchdog"
boxline "-r | --restart - Restarts all BDV hardware services, and re-initialized moxa if DNS is valid" boxline "-r | --restart - Restarts all BDV hardware services, and re-initialized moxa if DNS is valid"
boxline "-R | --force-restart - forces a restart of both the NPort driver and BDV services (assume -9)" boxline "-R | --force-restart - forces a restart of both the NPort driver and BDV services (assume -9)"
boxline "-p | --ping - Detect nPort online and write 'pingup' file if true or remove if false" boxline "-p | --ping - Detect nPort online and write 'pingup' file if true or remove if false"
boxline "-P | --pid - returns the PID's of any ongoing NPort Driver processes" boxline "-P | --pid - returns the PID's of any ongoing NPort Driver processes"
boxline "-d | --daemon - daemonizes the service as a watchdog" boxline "-d | --daemon - daemonizes the service as a watchdog"
boxline "-F | --fix-dns - Checks system's DNS config and removes entries if invalid" boxline "-F | --fix-dns - Checks system's DNS config and removes entries if invalid"
boxline "-u | --usage - Show this help text" boxline "-u | --usage - Show this help text"
boxline "-h | --help - Show this help text" boxline "-h | --help - Show this help text"
boxline "-v | --version - returns the version of this script" boxline "-v | --version - returns the version of this script"
boxbottom boxbottom
} }
removedns(){ removedns(){
# Look for existing DNS entries if there are any # Look for existing DNS entries if there are any
config_sh=$(grep DNS /.AVC-X/etc/networking/profiles/default/ifcfg-Public) config_sh=$(grep DNS /.AVC-X/etc/networking/profiles/default/ifcfg-Public)
resolv_conf=$(grep nameserver /.AVC-X/etc/networking/profiles/default/resolv.conf) resolv_conf=$(grep nameserver /.AVC-X/etc/networking/profiles/default/resolv.conf)
resolv_search=$(grep search /.AVC-X/etc/networking/profiles/default/resolv.conf) resolv_search=$(grep search /.AVC-X/etc/networking/profiles/default/resolv.conf)
config_dev=$(grep DNS /.AVC-X/etc/networking/devices/ifcfg-Public) config_dev=$(grep DNS /.AVC-X/etc/networking/devices/ifcfg-Public)
sys_resolv_conf=$(grep nameserver /etc/resolv.conf) sys_resolv_conf=$(grep nameserver /etc/resolv.conf)
sys_resolv_search=$(grep search /etc/resolv.conf) sys_resolv_search=$(grep search /etc/resolv.conf)
etc_net_sh=$(grep DNS /etc/network-scripts/ifcfg-Public) etc_net_sh=$(grep DNS /etc/network-scripts/ifcfg-Public)
# Checks if the above variables are empty, and if all are, exits the function only # Checks if the above variables are empty, and if all are, exits the function only
if [[ -z "$config_sh" && -z "$resolv_conf" && -z "$resolv_search" && -z "$config_dev" && -z "$sys_resolv_conf" && -z "$sys_resolv_search" && -z "$etc_net_sh" ]] ; then if [[ -z "$config_sh" && -z "$resolv_conf" && -z "$resolv_search" && -z "$config_dev" && -z "$sys_resolv_conf" && -z "$sys_resolv_search" && -z "$etc_net_sh" ]] ; then
logger echo -e "${grn}No DNS entries found${dfl}" logger echo -e "${grn}No DNS entries found${dfl}"
return 0 return 0
else else
# If either of the above variables are not empty, proceeds with checking # If either of the above variables are not empty, proceeds with checking
# and printing their contents # and printing their contents
if [[ ! -z "$config_sh" ]] ; then if [[ ! -z "$config_sh" ]] ; then
logger echo -e "${lbl}Current DNS is set to:${dfl}" logger echo -e "${lbl}Current DNS is set to:${dfl}"
logger echo -e "$config_sh" logger echo -e "$config_sh"
# sed uses regex to detect and delete lines out of the configuration script # sed uses regex to detect and delete lines out of the configuration script
# files that contain DNS entries # files that contain DNS entries
sudo sed -i '/DNS/d' /.AVC-X/etc/networking/profiles/default/ifcfg-Public && logger echo -e "${ylw}Successfully removed DNS entries from ifcfg-Public${dfl}\n" || logger fail "${red}Unable to remove DNS entries from /.AVC-X/etc/networking/profiles/default/ifcfg-Public${dfl}" sudo sed -i '/DNS/d' /.AVC-X/etc/networking/profiles/default/ifcfg-Public && logger echo -e "${ylw}Successfully removed DNS entries from ifcfg-Public${dfl}\n" || logger fail "${red}Unable to remove DNS entries from /.AVC-X/etc/networking/profiles/default/ifcfg-Public${dfl}"
fi fi
if [[ ! -z "$resolv_conf" ]] ; then if [[ ! -z "$resolv_conf" ]] ; then
logger echo -e "${lbl}Current resolv.conf entry is${dfl}" logger echo -e "${lbl}Current resolv.conf entry is${dfl}"
logger echo -e "$resolv_conf" logger echo -e "$resolv_conf"
sudo sed -i '/nameserver/d' /.AVC-X/etc/networking/profiles/default/resolv.conf && logger echo -e "${ylw}Successfully removed DNS entries from resolv.conf${dfl}\n" || logger warn "${red}Unable to remove DNS entries from /.AVC-X/etc/networking/profiles/default/resolv.conf${dfl}" sudo sed -i '/nameserver/d' /.AVC-X/etc/networking/profiles/default/resolv.conf && logger echo -e "${ylw}Successfully removed DNS entries from resolv.conf${dfl}\n" || logger warn "${red}Unable to remove DNS entries from /.AVC-X/etc/networking/profiles/default/resolv.conf${dfl}"
fi fi
if [[ ! -z "$resolv_conf" ]] ; then if [[ ! -z "$resolv_conf" ]] ; then
logger echo -e "${lbl}Current resolv.conf is searching${dfl}" logger echo -e "${lbl}Current resolv.conf is searching${dfl}"
logger echo -e "$resolv_search" logger echo -e "$resolv_search"
sudo sed -i '/search/d' /.AVC-X/etc/networking/profiles/default/resolv.conf && logger echo -e "${ylw}Successfully removed DNS entries from resolv.conf${dfl}\n" || logger warn "${red}Unable to remove DNS entries from /.AVC-X/etc/networking/profiles/default/resolv.conf${dfl}" sudo sed -i '/search/d' /.AVC-X/etc/networking/profiles/default/resolv.conf && logger echo -e "${ylw}Successfully removed DNS entries from resolv.conf${dfl}\n" || logger warn "${red}Unable to remove DNS entries from /.AVC-X/etc/networking/profiles/default/resolv.conf${dfl}"
fi fi
if [[ ! -z "$config_dev" ]] ; then if [[ ! -z "$config_dev" ]] ; then
logger echo -e "${lbl}Current DNS is set to:${dfl}" logger echo -e "${lbl}Current DNS is set to:${dfl}"
logger echo -e "$config_dev" logger echo -e "$config_dev"
# sed uses regex to detect and delete lines out of the configuration script # sed uses regex to detect and delete lines out of the configuration script
# files that contain DNS entries # files that contain DNS entries
sudo sed -i '/DNS/d' /.AVC-X/etc/networking/devices/ifcfg-Public && logger echo -e "${ylw}Successfully removed DNS entries from ifcfg-Public${dfl}\n" || logger fail "${red}Unable to remove DNS entries from /.AVC-X/etc/networking/devices/ifcfg-Public${dfl}" sudo sed -i '/DNS/d' /.AVC-X/etc/networking/devices/ifcfg-Public && logger echo -e "${ylw}Successfully removed DNS entries from ifcfg-Public${dfl}\n" || logger fail "${red}Unable to remove DNS entries from /.AVC-X/etc/networking/devices/ifcfg-Public${dfl}"
fi fi
if [[ ! -z "$sys_resolv_conf" ]] ; then if [[ ! -z "$sys_resolv_conf" ]] ; then
logger echo -e "${lbl}Current resolv.conf entry is${dfl}" logger echo -e "${lbl}Current resolv.conf entry is${dfl}"
logger echo -e "$sys_resolv_conf" logger echo -e "$sys_resolv_conf"
sudo sed -i '/nameserver/d' /.AVC-X/etc/networking/profiles/default/resolv.conf && logger echo -e "${ylw}Successfully removed DNS entries from /etc/resolv.conf${dfl}\n" || logger warn "${red}Unable to remove DNS entries from /etc/resolv.conf${dfl}" sudo sed -i '/nameserver/d' /.AVC-X/etc/networking/profiles/default/resolv.conf && logger echo -e "${ylw}Successfully removed DNS entries from /etc/resolv.conf${dfl}\n" || logger warn "${red}Unable to remove DNS entries from /etc/resolv.conf${dfl}"
fi fi
if [[ ! -z "$sys_resolv_search" ]] ; then if [[ ! -z "$sys_resolv_search" ]] ; then
logger echo -e "${lbl}Current resolv.conf is searching${dfl}" logger echo -e "${lbl}Current resolv.conf is searching${dfl}"
logger echo -e "$sys_resolv_search" logger echo -e "$sys_resolv_search"
sudo sed -i '/search/d' /.AVC-X/etc/networking/profiles/default/resolv.conf && logger echo -e "${ylw}Successfully removed DNS entries from /etc/resolv.conf${dfl}\n" || logger warn "${red}Unable to remove DNS entries from /etc/resolv.conf${dfl}" sudo sed -i '/search/d' /.AVC-X/etc/networking/profiles/default/resolv.conf && logger echo -e "${ylw}Successfully removed DNS entries from /etc/resolv.conf${dfl}\n" || logger warn "${red}Unable to remove DNS entries from /etc/resolv.conf${dfl}"
fi fi
if [[ ! -z "$etc_net_sh" ]] ; then if [[ ! -z "$etc_net_sh" ]] ; then
logger echo -e "${lbl}Current DNS is set to:${dfl}" logger echo -e "${lbl}Current DNS is set to:${dfl}"
logger echo -e "$etc_net_sh" logger echo -e "$etc_net_sh"
# sed uses regex to detect and delete lines out of the configuration script # sed uses regex to detect and delete lines out of the configuration script
# files that contain DNS entries # files that contain DNS entries
sudo sed -i '/DNS/d' /etc/network-scripts/ifcfg-Public && logger echo -e "${ylw}Successfully removed DNS entries from ifcfg-Public${dfl}\n" || logger fail "${red}Unable to remove DNS entries from /.AVC-X/etc/networking/profiles/default/ifcfg-Public${dfl}" sudo sed -i '/DNS/d' /etc/network-scripts/ifcfg-Public && logger echo -e "${ylw}Successfully removed DNS entries from ifcfg-Public${dfl}\n" || logger fail "${red}Unable to remove DNS entries from /.AVC-X/etc/networking/profiles/default/ifcfg-Public${dfl}"
fi fi
return 1 return 1
fi fi
} }
dnscheck(){ dnscheck(){
# The Moxa drivers are built in such a way that they will hang if no outside # The Moxa drivers are built in such a way that they will hang if no outside
# network is available, unless DNS entries are not present. Below checks for # network is available, unless DNS entries are not present. Below checks for
# external network access, then removes dns entries if outside network is unavailable # external network access, then removes dns entries if outside network is unavailable
# Check if dns entries exist # Check if dns entries exist
if [[ ! -z "$config_sh" || ! -z "$resolv_conf" || ! -z "$config_dev" || ! -z "$sys_resolv_conf" || ! -z "$etc_net_sh" ]] ; then if [[ ! -z "$config_sh" || ! -z "$resolv_conf" || ! -z "$config_dev" || ! -z "$sys_resolv_conf" || ! -z "$etc_net_sh" ]] ; then
# If DNS entries are found, check that the server can ping them # If DNS entries are found, check that the server can ping them
logger echo -e "DNS Entries found, checking for internet connection" logger echo -e "DNS Entries found, checking for internet connection"
ping -c 1 $dns >/dev/null 2>&1 ping -c 1 $dns >/dev/null 2>&1
if [[ $? != 0 ]] ; then if [[ $? != 0 ]] ; then
# If DNS entries are found, but not responding, # If DNS entries are found, but not responding,
# remove DNS entries to prevent drivers from hanging on boot # remove DNS entries to prevent drivers from hanging on boot
logger echo -e "${ong}DNS $dns is not responding to ping${dfl}" logger echo -e "${ong}DNS $dns is not responding to ping${dfl}"
logger echo -e "Removing DNS entries from network configuration" logger echo -e "Removing DNS entries from network configuration"
return 1 return 1
else else
# If DNS entries are found, but responding, leave the entries intact # If DNS entries are found, but responding, leave the entries intact
logger echo -e "${grn}DNS is responding, entries valid.${dfl}" logger echo -e "${grn}DNS is responding, entries valid.${dfl}"
logger echo -e "${lyl}Proceeding with initialization.${dfl}" logger echo -e "${lyl}Proceeding with initialization.${dfl}"
return 0 return 0
fi fi
else else
logger echo -e "DNS Entries not found, skipping DNS pingcheck" logger echo -e "DNS Entries not found, skipping DNS pingcheck"
return 0 return 0
fi fi
} }
dnspurge(){ dnspurge(){
# Run first dns check and removal # Run first dns check and removal
removedns removedns
# Run network reset # Run network reset
sudo /sbin/service network restart sudo /sbin/service network restart
# Run second dns check for lingering entries # Run second dns check for lingering entries
logger echo -e "${pur}Re-checking dns entries${dfl}" logger echo -e "${pur}Re-checking dns entries${dfl}"
removedns removedns
} }
moxatty(){ moxatty(){
ls /dev/tty* | grep -c ttyr00 ls /dev/tty* | grep -c ttyr00
} }
# Checks moxa's online status and stores state via external 'pingtest' file # Checks moxa's online status and stores state via external 'pingtest' file
online(){ online(){
if [ ! -f $pingfile ] ; then if [ ! -f $pingfile ] ; then
if ping -c 1 -W 1 $@ &> /dev/null ; then if ping -c 1 -W 1 $@ &> /dev/null ; then
echo 2 echo 2
else else
echo 1 echo 1
fi fi
else else
if ping -c 1 -W 1 $@ &> /dev/null ; then if ping -c 1 -W 1 $@ &> /dev/null ; then
echo 0 echo 0
else else
echo 3 echo 3
fi fi
fi fi
} }
# Checks moxa's online status and stores state in a variable # Checks moxa's online status and stores state in a variable
pingtest(){ pingtest(){
if [[ $moxaonline == true ]] ; then if [[ $moxaonline == true ]] ; then
if ping -c 1 -W 1 $@ &> /dev/null ; then if ping -c 1 -W 1 $@ &> /dev/null ; then
echo 0 echo 0
else else
echo 3 echo 3
fi fi
else else
if ping -c 1 -W 1 $@ &> /dev/null ; then if ping -c 1 -W 1 $@ &> /dev/null ; then
echo 2 echo 2
else else
echo 1 echo 1
fi fi
fi fi
} }
# Launch the Moxa NPort loader application # Launch the Moxa NPort loader application
start(){ start(){
/usr/lib/npreal2/driver/mxloadsvr /usr/lib/npreal2/driver/mxloadsvr
} }
# Force terminate any instances of the Moxa NPort application # Force terminate any instances of the Moxa NPort application
stop(){ stop(){
sudo pkill -9 npreal2d sudo pkill -9 npreal2d
} }
# Force stop of any daemonized instances of this script # Force stop of any daemonized instances of this script
fullstop(){ fullstop(){
stop stop
sudo kill -9 $daemonpid sudo kill -9 $daemonpid
} }
# Restart of multiple services is required to re-establish device control after # Restart of multiple services is required to re-establish device control after
# the NPort loses its connection. The order of restarting these services is # the NPort loses its connection. The order of restarting these services is
# significant, and should be maintained. # significant, and should be maintained.
restart(){ restart(){
stop stop
start start
god restart rs232 god restart rs232
sudo /sbin/service SimpleHttpDeviceServer restart_noscript sudo /sbin/service SimpleHttpDeviceServer restart_noscript
sudo /sbin/service BDVHardwareManager restart sudo /sbin/service BDVHardwareManager restart
god restart steris_act god restart steris_act
} }
conditionalrestart(){ conditionalrestart(){
if [[ $(dnscheck) == 0 ]] ; then if [[ $(dnscheck) == 0 ]] ; then
stop stop
start start
fi fi
god restart rs232 god restart rs232
sudo /sbin/service SimpleHttpDeviceServer restart_noscript sudo /sbin/service SimpleHttpDeviceServer restart_noscript
sudo /sbin/service BDVHardwareManager restart sudo /sbin/service BDVHardwareManager restart
god restart steris_act god restart steris_act
} }
# Clears loop flag variables # Clears loop flag variables
clearflags(){ clearflags(){
moxaonline= moxaonline=
pingfails= pingfails=
state= state=
} }
#------------------------------------------------------# #------------------------------------------------------#
# Options and Arguments Parser # Options and Arguments Parser
#------------------------------------------------------# #------------------------------------------------------#
case $1 in case $1 in
-s | start | --start) -s | start | --start)
start start
exit 0 exit 0
;; ;;
-S | stop | --stop) -S | stop | --stop)
fullstop fullstop
exit $? exit $?
;; ;;
-R | --force-restart) -R | --force-restart)
fullstop fullstop
restart restart
exit 0 exit 0
;; ;;
-r | restart | --restart) -r | restart | --restart)
conditionalrestart conditionalrestart
exit 0 exit 0
;; ;;
-p | ping | --ping) -p | ping | --ping)
online moxa online moxa
exit $? exit $?
;; ;;
-P | pid | --pid) -P | pid | --pid)
echo -e "$daemonpid" echo -e "$daemonpid"
exit $? exit $?
;; ;;
-d | daemon | --daemon) -d | daemon | --daemon)
start start
;; ;;
-u | --usage) -u | --usage)
usage usage
exit -1 exit -1
;; ;;
-h | --help) -h | --help)
usage usage
exit -1 exit -1
;; ;;
-v | --version) -v | --version)
echo $VERSION echo $VERSION
exit 0 exit 0
;; ;;
-F | --fix-dns) -F | --fix-dns)
purgedns purgedns
exit 0 exit 0
;; ;;
*) *)
warn "Invalid argument $@" warn "Invalid argument $@"
usage usage
exit -1 exit -1
;; ;;
esac esac
#-----------------------------------------------------------------# #-----------------------------------------------------------------#
# Process substitution to fork log output # Process substitution to fork log output
# Only uncomment if all script output should be logged! # Only uncomment if all script output should be logged!
#-----------------------------------------------------------------# #-----------------------------------------------------------------#
# exec &> >(tee $logfile) # exec &> >(tee $logfile)
#------------------------------------------------------# #------------------------------------------------------#
# Script begins here # Script begins here
#------------------------------------------------------# #------------------------------------------------------#
logger boxtop logger boxtop
logger boxline "${lbl}Moxa NPort Driver Loader v$VERSION${dfl}" logger boxline "${lbl}Moxa NPort Driver Loader v$VERSION${dfl}"
logger boxbottom logger boxbottom
# Unset flags # Unset flags
clearflags clearflags
while true ; do while true ; do
state=$(online moxa) state=$(online moxa)
case $state in case $state in
0) # State 0 = Moxa is online, and was online in previous loop. No action needed 0) # State 0 = Moxa is online, and was online in previous loop. No action needed
boxtop boxtop
boxline "${grn}Moxa NPort Online...${dfl}" boxline "${grn}Moxa NPort Online...${dfl}"
boxbottom boxbottom
moxaonline=true moxaonline=true
;; ;;
1) # State 1 = Moxa is offline, and was offline in previous loop. No action needed 1) # State 1 = Moxa is offline, and was offline in previous loop. No action needed
boxtop boxtop
boxline "${lrd}Moxa NPort Offline${dfl}" boxline "${lrd}Moxa NPort Offline${dfl}"
boxbottom boxbottom
moxaonline=false moxaonline=false
failpings=$((failpings+1)) failpings=$((failpings+1))
;; ;;
2) # State 2 = Moxa is online, but was offline in previous loop. Service Restart required to restore functionality and update moxaonline state 2) # State 2 = Moxa is online, but was offline in previous loop. Service Restart required to restore functionality and update moxaonline state
#if [[ $rst_threshold -gt $failpings ]] ; then #if [[ $rst_threshold -gt $failpings ]] ; then
logger boxtop logger boxtop
logger boxline "${grn}Moxa NPort Came Online!${dfl}" logger boxline "${grn}Moxa NPort Came Online!${dfl}"
logger boxline "... ${lyl}Restarting Services${dfl} ..." logger boxline "... ${lyl}Restarting Services${dfl} ..."
logger boxbottom logger boxbottom
moxaonline=true moxaonline=true
touch $pingfile touch $pingfile
conditionalrestart conditionalrestart
#fi #fi
;; ;;
3) # State 3 = Moxa is offline, but was online in previous loop. Start counting failed pings, and update moxaonline state 3) # State 3 = Moxa is offline, but was online in previous loop. Start counting failed pings, and update moxaonline state
logger boxtop logger boxtop
logger boxline "${grn}Moxa NPort Has Gone Offline${dfl}" logger boxline "${grn}Moxa NPort Has Gone Offline${dfl}"
logger boxline "${lyl}Awaiting Response before Restart${dfl} ..." logger boxline "${lyl}Awaiting Response before Restart${dfl} ..."
logger boxbottom logger boxbottom
moxaonline=false moxaonline=false
rm $pingfile rm $pingfile
failpings=1 failpings=1
;; ;;
esac esac
boxtop boxtop
boxline "Moxa Online = $moxaonline" boxline "Moxa Online = $moxaonline"
boxline "Checking again in $ratelimit seconds..." boxline "Checking again in $ratelimit seconds..."
boxbottom boxbottom
sleep $ratelimit sleep $ratelimit
done done