|
| 1 | +#!/bin/bash |
| 2 | +# SPDX-License-Identifier: GPL-2.0-or-later |
| 3 | + |
| 4 | +check() { |
| 5 | + require_binaries \ |
| 6 | + chronyd \ |
| 7 | + || return 1 |
| 8 | + |
| 9 | + return 255 |
| 10 | +} |
| 11 | + |
| 12 | +depends() { |
| 13 | + echo systemd network |
| 14 | + return 0 |
| 15 | +} |
| 16 | + |
| 17 | +install() { |
| 18 | + # openSUSE/Fedora: chrony |
| 19 | + # Ubuntu: _chrony |
| 20 | + grep -s -E '^(_chrony|chrony):' "${dracutsysrootdir-}"/etc/passwd \ |
| 21 | + | sed 's/\/var\/lib\/chrony/\/run\/chrony/' >> "$initdir/etc/passwd" |
| 22 | + grep -s -E '^(_chrony|chrony):' "${dracutsysrootdir-}"/etc/group >> "$initdir/etc/group" |
| 23 | + |
| 24 | + inst_hook cmdline 01 "$moddir/parse-ntp.sh" |
| 25 | + inst_hook initqueue/online 01 "$moddir/chrony-ntp-source.sh" |
| 26 | + |
| 27 | + inst_multiple -o \ |
| 28 | + "$systemdntpunits"/50-chronyd.list \ |
| 29 | + "$systemdsystemunitdir"/time-sync.target \ |
| 30 | + chronyd chronyc mkdir chown |
| 31 | + |
| 32 | + inst_simple "$moddir/chrony.conf" /etc/chrony.conf |
| 33 | + |
| 34 | + for i in \ |
| 35 | + chronyd.service \ |
| 36 | + chrony-wait.service; do |
| 37 | + inst_simple "$moddir/$i" "$systemdsystemunitdir/$i" |
| 38 | + $SYSTEMCTL -q --root "$initdir" add-wants initrd.target "$i" |
| 39 | + done |
| 40 | + |
| 41 | + if [[ $hostonly ]]; then |
| 42 | + local _i _directives _keyfile _source_dirs=() |
| 43 | + |
| 44 | + # Install the file pointed by the "keyfile" directive, used for NTP |
| 45 | + # authentication. This directive is intended to be unique, chrony would |
| 46 | + # end up using the last one processed. |
| 47 | + readarray -t _directives < <(grep -r -h '^keyfile ' "${dracutsysrootdir-}"/etc/chrony*) |
| 48 | + if ((${#_directives[@]})); then |
| 49 | + printf "\n# Specify file containing keys for NTP authentication.\n%s\n" "${_directives[-1]}" >> "$initdir/etc/chrony.conf" |
| 50 | + _keyfile="${_directives[-1]/#keyfile /}" |
| 51 | + fi |
| 52 | + |
| 53 | + # chrony allows to configure directories with .sources files using the |
| 54 | + # "sourcedir" directive, used to specify NTP sources (server, pool, and |
| 55 | + # peer directives). |
| 56 | + readarray -t _directives < <(grep -r -h '^sourcedir /etc' "${dracutsysrootdir-}"/etc/chrony*) |
| 57 | + if ((${#_directives[@]})); then |
| 58 | + printf "\n# Use NTP sources configured on the host.\n" >> "$initdir/etc/chrony.conf" |
| 59 | + for _i in "${_directives[@]}"; do |
| 60 | + echo "$_i" >> "$initdir/etc/chrony.conf" |
| 61 | + _source_dirs+=("$(echo "$_i" | sed -e 's/sourcedir //' -e 's/$/\/*.sources/')") |
| 62 | + done |
| 63 | + fi |
| 64 | + |
| 65 | + # We do not want to include /etc/chrony.conf or ".conf" files specified |
| 66 | + # with "include" or "confdir" directives from the host, because they |
| 67 | + # can override "driftfile", "ntsdumpdir" or "logdir" directives, |
| 68 | + # intended to point to /run in the initrd. |
| 69 | + |
| 70 | + inst_multiple -H -o "$_keyfile" "${_source_dirs[@]}" \ |
| 71 | + /etc/sysconfig/chronyd \ |
| 72 | + "$systemdsystemconfdir"/time-sync.target \ |
| 73 | + "$systemdsystemconfdir/time-sync.target.wants/*.target" |
| 74 | + fi |
| 75 | +} |
0 commit comments