manbytesgnu_site

Source files for manbytesgnu.org
git clone git://holbrook.no/manbytesgnu_site.git
Log | Files | Refs

iup.sh (993B)


      1 #!/bin/bash
      2 
      3 # this is our runtime file, if - which exists - tells us internet is up
      4 f="/run/user/$UID/probe_up"
      5 rm -f $f
      6 
      7 up() {
      8 	if [ ! -f $f ]; then
      9 		logger -p info "iup up"
     10 	fi
     11 	touch $f
     12 }
     13 down() {
     14 	if [ -f $f ]; then
     15 		logger -p info "iup down"
     16 	fi
     17 	rm -f $f
     18 }
     19 
     20 argh() {
     21 	logger -p info "iup die"
     22 	rm -f $f
     23 	exit 0
     24 }
     25 
     26 IUP_DELAY=${IUP_DELAY:-$1}
     27 if [ -z $IUP_DELAY ]; then
     28 	IUP_DELAY=5
     29 fi
     30 logger -p debug iup started with delay $IUP_DELAY
     31 
     32 hosts=()
     33 while read h; do
     34 	hosts+=($h)
     35 done < $HOME/.config/iup 2> /dev/null
     36 if [ ${#hosts[@]} -eq "0" ]; then
     37 	hosts=(8.8.8.8 151.101.193.67) # google nameserver and cnn.com
     38 	logger -p warn missing hosts input file, using evil default: ${hosts[@]}
     39 fi
     40 
     41 trap argh SIGINT
     42 trap argh SIGTERM
     43 trap argh SIGQUIT
     44 
     45 while true; do
     46 	isup=""
     47 	for h in ${hosts[@]}; do
     48 		ping -c1 $h -w1 -q &> /dev/null
     49 		if [ $? -eq '0' ]; then
     50 			up
     51 			isup=1
     52 			#logger -p debug "ping success $h"
     53 			break
     54 		fi
     55 	done
     56 	if [ -z $isup ]; then
     57 		down
     58 	fi
     59 	sleep $IUP_DELAY
     60 done