Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(98)

Side by Side Diff: dhcpcd-hooks/50-ntp.conf

Issue 2428004: Overhaul dhcpcd for chrome os use (Closed) Base URL: ssh://git@chromiumos-git//dhcpcd.git
Patch Set: purge hooks from configure to silence complaint Created 10 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « dhcpcd-hooks/50-dhcpcd-compat ('k') | dhcpcd-hooks/50-yp.conf » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 # Sample dhcpcd hook script for ntp
2 # Like our resolv.conf hook script, we store a database of ntp.conf files
3 # and merge into /etc/ntp.conf
4
5 # You can set the env var NTP_CONF to another file like this
6 # dhcpcd -e NTP_CONF=/usr/pkg/etc/ntpd.conf
7 # or by adding this to /etc/dhcpcd.enter-hook
8 # NTP_CONF=/usr/pkg/etc/ntpd.conf
9 # to use openntpd from pkgsrc instead of the system provided ntp.
10
11 # Detect OpenRC or BSD rc
12 # Distributions may want to just have their command here instead of this
13 if type rc-service >/dev/null 2>&1 && rc-service --exists ntpd; then
14 ntpd_restart_cmd="rc-service ntpd -- -Ds restart"
15 elif [ -x /etc/rc.d/ntpd ]; then
16 ntpd_restart_cmd="/etc/rc.d/ntpd status >/dev/null 2>&1 && /etc/rc.d/ntp d restart"
17 elif [ -x /usr/local/etc/rc.d/ntpd ]; then
18 ntpd_restart_cmd="/usr/local/etc/rc.d/ntpd status >/dev/null 2>&1 && /us r/local/etc/rc.d/ntpd restart"
19 fi
20
21 ntp_conf_dir="$state_dir/ntp.conf"
22 ntp_conf=${NTP_CONF:-/etc/ntp.conf}
23
24 build_ntp_conf()
25 {
26 local cf="$state_dir/ntp.conf.$interface"
27 local interfaces= header= srvs= servers= x=
28
29 # Build a list of interfaces
30 interfaces=$(list_interfaces "$ntp_conf_dir")
31
32 if [ -n "$interfaces" ]; then
33 # Build the header
34 for x in ${interfaces}; do
35 header="$header${header:+, }$x"
36 done
37
38 # Build a server list
39 srvs=$(cd "$ntp_conf_dir";
40 key_get_value "server " $interfaces)
41 if [ -n "$srvs" ]; then
42 for x in $(uniqify $srvs); do
43 servers="${servers}server $x\n"
44 done
45 fi
46 fi
47
48 # Merge our config into ntp.conf
49 [ -e "$cf" ] && rm -f "$cf"
50 [ -d "$ntp_conf_dir" ] || mkdir -p "$ntp_conf_dir"
51 if [ -e "$ntp_conf" ]; then
52 remove_markers "$signature_base" "$signature_base_end" \
53 "$ntp_conf" > "$cf"
54 fi
55 if [ -n "$servers" ]; then
56 echo "$signature_base${header:+ $from }$header" >> "$cf"
57 printf "$search$servers" >> "$cf"
58 echo "$signature_base_end${header:+ $from }$header" >> "$cf"
59 fi
60
61 # If we changed anything, restart ntpd
62 if change_file "$ntp_conf" "$cf"; then
63 [ -n "$ntpd_restart_cmd" ] && eval $ntpd_restart_cmd
64 fi
65 }
66
67 add_ntp_conf()
68 {
69 local cf="$ntp_conf_dir/$interface" x=
70
71 [ -e "$cf" ] && rm "$cf"
72 [ -d "$ntp_conf_dir" ] || mkdir -p "$ntp_conf_dir"
73 if [ -n "$new_ntp_servers" ]; then
74 for x in $new_ntp_servers; do
75 echo "server $x" >> "$cf"
76 done
77 fi
78 build_ntp_conf
79 }
80
81 remove_ntp_conf()
82 {
83 if [ -e "$ntp_conf_dir/$interface" ]; then
84 rm "$ntp_conf_dir/$interface"
85 fi
86 build_ntp_conf
87 }
88
89 case "$reason" in
90 BOUND|INFORM|REBIND|REBOOT|RENEW|TIMEOUT|STATIC) add_ntp_conf add;;
91 PREINIT|EXPIRE|FAIL|IPV4LL|NAK|NOCARRIER|RELEASE|STOP) remove_ntp_conf del;;
92 esac
OLDNEW
« no previous file with comments | « dhcpcd-hooks/50-dhcpcd-compat ('k') | dhcpcd-hooks/50-yp.conf » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698