summarylogtreecommitdiffstats
path: root/10-chrony
blob: 581a575c611f5f1a145b634f6d25b661eaaac566 (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
36
37
38
39
40
#!/bin/sh

INTERFACE=$1
STATUS=$2

# Chrony set-up
CHRONY=/usr/bin/chronyc
CONFIG=/etc/chrony.conf
KEYFILE=`grep ^keyfile $CONFIG | sed 's/[^ ]* //' -`
COMMANDKEY=`grep ^commandkey $CONFIG | sed 's/[^ ]* //' -`
PASSWORD=`grep ^$COMMANDKEY $KEYFILE | sed 's/[^ ]* //' -`

chrony_cmd() {
	echo Chrony going $1.
	exec $CHRONY <<EOF
password $PASSWORD
$1
EOF
}

case "$STATUS" in
  up)
    chrony_cmd online
  ;;
  vpn-up)
    chrony_cmd online
  ;;
  down)
    # Check for active interface, take offline if none is active
    if [ ! `nm-tool|grep State|cut -f2 -d' '` = 'connected' ]; then
      chrony_cmd offline
    fi
  ;;
  vpn-down)
    # Check for active interface, take offline if none is active
    if [ ! `nm-tool|grep State|cut -f2 -d' '` = 'connected' ]; then
      chrony_cmd offline
    fi
  ;;
esac