#!/bin/sh -efu # # Copyright (C) 2012 Dmitry V. Levin # # 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 the package; if not, see . conf_file=/etc/timezone env_file=/etc/sysconfig/clock dst_file=/etc/localtime src_dir=/usr/share/zoneinfo update_chrooted=/usr/sbin/update_chrooted readonly conf_file env_file dst_file src_dir update_chrooted # get configured timezone name tz_name= if [ -s "$conf_file" ]; then tz_name="$(cat -- "$conf_file")" fi [ -n "$tz_name" ] || if [ -s "$env_file" ]; then tz_name="$(ZONE= && . "$env_file" && printf %s "$ZONE")" fi [ -n "$tz_name" ] || exit 0 readonly tz_name src_file="$src_dir/$tz_name" readonly src_file [ -f "$src_file" ] || exit 0 if cmp -s "$src_file" "$dst_file"; then # up to date already exit 0 fi cleanup() { if [ -f "$tmp_file" ]; then rm -f -- "$tmp_file" fi exit "$@" } tmp_file="$(mktemp -- "$dst_file.XXXXXX")" readonly tmp_file trap 'cleanup $?' EXIT trap 'exit 143' HUP INT QUIT PIPE TERM ln -nf -- "$src_file" "$tmp_file" 2>/dev/null || cp -p -- "$src_file" "$tmp_file" mv -f -- "$tmp_file" "$dst_file" trap - EXIT HUP INT QUIT PIPE TERM if [ -x "$update_chrooted" ]; then "$update_chrooted" conf ||: fi