summaryrefslogtreecommitdiffstats
path: root/projectroot/usr/bin/chrony_command
blob: 03a18d0aea548709882e06e8f83e807c1570785f (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
#!/bin/sh
# This is a generic chrony command script which
# extracts the chrony access key from /etc/chrony/chrony.key
# and executes one given command
# some chronyc commands need prior autentication: extract keys from config
PREFIX="chrony command helper: "
command=$1
if [ -z "$command" ] ; then
	echo "Usage: $0 <command>"
	exit 0
fi
[ "$command" = "--help" ] && command="help"

bailout(){
        echo "${PREFIX}ERROR   --- $*" >&2
        exit 1
}

KEY=$(awk '$1 ~ /^commandkey$/ { print $2; exit}' /etc/chrony/chrony.conf)
PASSWORD=`awk '$1 ~ /^'$KEY'$/ {print $2; exit}' /etc/chrony/chrony.keys`

/bin/pidof chronyd > /dev/null || bailout " chronyd is not running "
/usr/bin/chronyc <<-EOF
password $PASSWORD
$command
EOF