| # Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| |
| description "Run the tlsdate daemon to set the system time" |
| author "chromium-os-dev@chromium.org" |
| |
| start on started system-services |
| stop on stopping system-services |
| respawn |
| |
| script |
| PROXY_FILE=/var/run/proxy |
| valid_proxy() { |
| scheme=$(echo "$1" | sed 's!://.*!!') |
| address=$(echo "$1" | sed 's!.*://!!') |
| host=$(echo "$address" | cut -f1 -d:) |
| port=$(echo "$address" | cut -f2 -d:) |
| |
| if ! echo "$scheme" | grep -qE '^(http|socks4|socks5)$'; then |
| return 1 |
| fi |
| |
| if ! echo "$host" | grep -qE '^[A-Za-z0-9.-]+$'; then |
| return 1 |
| fi |
| |
| if ! echo "$port" | grep -qE '^[0-9]+$'; then |
| return 1 |
| fi |
| |
| echo "$scheme://$host:$port" |
| return 0 |
| } |
| proxy_arg="none" |
| if [ -r "$PROXY_FILE" ]; then |
| proxy=$(cat "$PROXY_FILE") |
| if proxy=$(valid_proxy "$proxy"); then |
| proxy_arg="$proxy" |
| fi |
| fi |
| mkdir -m 755 -p /var/cache/tlsdated |
| exec tlsdated -v -- /usr/sbin/tlsdate -l -H clients3.google.com -x "$proxy_arg" |
| end script |