#!/bin/sh # -------- # File: llxcfg-ntp-cli # Description: Simple cli to chronyd using chronyc # Author: Luis Garcia Gisbert # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin St, Fifth Floor, Boston MA 02110-1301 USA # -------- set -e KEY_FILE="/etc/chrony/chrony.keys" KEY_NUM="1" die(){ echo "$1" >&2 exit 1 } usage(){ die "Usage: $(basename "$0") COMMAND\n\ $(basename "$0") -f {CMD_FILE|-}\n\ $(basename "$0") -t {TEMPLATE_FILE|-}" } dump_cmds(){ if [ "$CMD_TXT" ] ; then echo "$CMD_TXT" elif [ "$CMD_FILE" ] ; then cat "$CMD_FILE" else llxcfg-template "$TMPL_FILE" || true fi return 0 } # main [ "$1" ] || usage [ -r "$KEY_FILE" ] || die "Unable to read keyfile $KEY_FILE" PASSWORD="$(sed -ne "/^$KEY_NUM[[:blank:]]/s%^.*[[:blank:]]%%p" "$KEY_FILE")" [ "$PASSWORD" ] || die "Unable to read password for key number $KEY_NUM in $KEY_FILE" CMD_FILE="" TMPL_FILE="" CMD_TXT="" case "$1" in -f|-t) CMD_FILE="$2" [ "$CMD_FILE" ] || usage [ "$CMD_FILE" = "-" ] || [ -r "$CMD_FILE" ] || usage if [ "$1" = "-t" ] ; then TMPL_FILE="$CMD_FILE" CMD_FILE="" fi ;; *) CMD_TXT="$*" ;; esac # do the job chronyc << EOF password $PASSWORD $(dump_cmds) quit EOF exit 0