summarylogtreecommitdiffstats
path: root/10-chrony
blob: 9ed4d316c9355334e5af7b5d096a78189dbcda95 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/bin/sh

INTERFACE=$1
STATUS=$2

# Make sure we're always getting the standard response strings
LANG='C'

CHRONY=$(which chronyc)

chrony_cmd() {
  echo "Chrony going $1."
  exec $CHRONY -a $1
}

nm_connected() {
  # Let networkmanager check if we are able to reach the internet
  [ "$(nmcli networking connectivity check)" = 'full' ]
}

if [ "$INTERFACE" = "lo" ]; then
  # Local interface, nothing to do, exit early
  exit 0
fi

case "$STATUS" in
  up|vpn-up)
    # Check for full connectivity, take online if connected
    nm_connected && chrony_cmd online
  ;;
  down|vpn-down)
    # Check for full connectivity, take offline if not connected
    nm_connected || chrony_cmd offline
  ;;
esac