sh: Add internet-check base script

Added script to sh base package to allow checking for internet
connectivity. Checks both through system virtual filesystem and, as a
fallback, through pinging google dns.

Added a simple readme to sh module.
This commit is contained in:
Marty Oehme 2021-09-24 11:15:08 +02:00
parent 658e07e1b8
commit 3bf5becbe2
Signed by: Marty
GPG Key ID: B7538B8F50A1C800
3 changed files with 48 additions and 4 deletions

View File

@ -269,7 +269,7 @@ format-underline = ${colors.primary}
[module/mail] [module/mail]
type = custom/script type = custom/script
exec = echo "$( [ $(systemctl --user --property=ActiveState show mbsync.timer) = 'ActiveState=active' ] && echo "" || echo "" ) $(notmuch count tag:inbox and tag:unread)" exec = echo "$( [ $(systemctl --user --property=ActiveState show mbsync.timer) = 'ActiveState=active' ] && echo "" || echo "" ) $(notmuch count tag:inbox and tag:unread)"
exec-if = [ "$(notmuch count tag:inbox and tag:unread)" -gt 0 ] exec-if = check-internet && [ "$(notmuch count tag:inbox and tag:unread)" -gt 0 ]
click-right = systemctl --user start mbsync.timer click-right = systemctl --user start mbsync.timer
click-left = systemctl --user stop mbsync.timer click-left = systemctl --user stop mbsync.timer
interval = 300.0 interval = 300.0
@ -278,7 +278,7 @@ format-underline = ${colors.primary}
[module/weather] [module/weather]
type = custom/script type = custom/script
exec = $XDG_CONFIG_HOME/polybar/scripts/poly-weather 'Copenhagen?m&format=%t+%C+(%p)' exec = $XDG_CONFIG_HOME/polybar/scripts/poly-weather 'Copenhagen?m&format=%t+%C+(%p)'
exec-if = type $XDG_CONFIG_HOME/polybar/scripts/poly-weather exec-if = type $XDG_CONFIG_HOME/polybar/scripts/poly-weather && check-internet
interval = 60.0 interval = 60.0
; format-background = ${colors.primary} ; format-background = ${colors.primary}
; format-foreground = ${colors.background} ; format-foreground = ${colors.background}
@ -301,7 +301,7 @@ tail = true
[module/archupdates] [module/archupdates]
type = custom/script type = custom/script
exec = $XDG_CONFIG_HOME/polybar/scripts/poly-archupdates exec = $XDG_CONFIG_HOME/polybar/scripts/poly-archupdates
exec-if = type $XDG_CONFIG_HOME/polybar/scripts/poly-archupdates exec-if = type $XDG_CONFIG_HOME/polybar/scripts/poly-archupdates && check-internet
interval = 600 interval = 600
format = <label> format = <label>
format-prefix = " " format-prefix = " "
@ -311,7 +311,7 @@ format-underline = ${colors.primary}
[module/networkspeed] [module/networkspeed]
type = custom/script type = custom/script
exec = $XDG_CONFIG_HOME/polybar/scripts/poly-networkspeed exec = $XDG_CONFIG_HOME/polybar/scripts/poly-networkspeed
exec-if = type $XDG_CONFIG_HOME/polybar/scripts/poly-networkspeed exec-if = type $XDG_CONFIG_HOME/polybar/scripts/poly-networkspeed && check-internet
tail = true tail = true
format-underline = ${colors.primary} format-underline = ${colors.primary}

24
sh/.local/bin/check-internet Executable file
View File

@ -0,0 +1,24 @@
#!/usr/bin/env sh
#
# Check for internet connectivity.
# Returns 0 if connectivity exists, 1 if it does not.
hasconnec=0
for intf in /sys/class/net/*; do
case $intf in
"/sys/class/net/lo") break ;;
*)
[ "$(cat "$intf/carrier")" = 1 ] && hasconnec=1
;;
esac
done
if [ $hasconnec -ne 1 ]; then
ping -q -w 1 -c 1 8.8.8.8 >/dev/null 2>&1 && hasconnec=1
fi
if [ $hasconnec -eq 1 ]; then
exit 0
else
exit 1
fi

20
sh/README.md Normal file
View File

@ -0,0 +1,20 @@
# sh
The bare minimum terminal configuration for a working system.
Contains:
* an XDG compliant home directory setup
* several basic environment variables
* simple aliases
* an optional fzf default setup
* X autostart
While other modules are largely optional,
this module is the only one strictly necessary for the system to really work at all.
Additionally contains two scripts on which some other modules build:
* a simple script to detect if applications exist
(and optionally warn the user if they don't)
* and a script to check if internet connectivity exists