Subject: util-linux: New "debianaized" hwclock.sh, for review and testing.
Package: util-linux
Version: 2.12r-10
Severity: wishlist
Tags: patch

If somebody cares, please, welcome to testing new system clock boot
script.


-- System Information:
Debian Release: testing/unstable
  APT prefers testing
  APT policy: (500, 'testing')
Architecture: amd64 (x86_64)
Shell:  /bin/sh linked to /bin/dash
Kernel: Linux 2.6.16-2-amd64-k8
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8)

Versions of packages util-linux depends on:
ii  libc6                        2.3.6.ds1-4 GNU C Library: Shared libraries
ii  libncurses5                  5.5-3       Shared libraries for terminal hand
ii  libslang2                    2.0.6-3     The S-Lang programming library - r
ii  libuuid1                     1.39-1      universally unique id library
ii  lsb-base                     3.1-15      Linux Standard Base 3.1 init scrip
ii  zlib1g                       1:1.2.3-13  compression library - runtime

util-linux recommends no packages.

-- no debconf information


#!/bin/sh
### BEGIN INIT INFO
# Time-stamp: "Thu Sep 21 08:11:51 CEST 2006 [EMAIL PROTECTED]"
# Provides:          time
# Defaults:          ${HWCLOCK:-/sbin/hwclock} ${UTC:-yes} ${ADJTIME:-}
# Required-Start:    $local_fs $remote_fs
# Required-Stop:     $local_fs $remote_fs
# Default-Start:     S
# Default-Stop:      S
# Short-Description: Setting the system clock from RTC
# Description:       Reading time form RTC(CMOS) using hwclock(8) and
#                    setting it to in-kernel system clock, and vice versa.
#                    If $ADJ is set, 'reload' will --adjust hardware clock,
#                    see /usr/share/doc/util-linux/README.Debian.hwclock.gz
### END INIT INFO

# Original-Author: Miquel van Smoorenburg <[EMAIL PROTECTED]>
# Author: Oleg Verych <[EMAIL PROTECTED]>
# Copyright © 1998-2006 The Debian Project

#set -e -x

HWCLOCK=${HWCLOCK:-/sbin/hwclock}
[ -x "$HWCLOCK" ] || exit 0

[ -r /etc/default/$NAME ] && . /etc/default/$NAME
[ -f /etc/default/rcS ] && . /etc/default/rcS
.. /lib/lsb/init-functions

# default time zone settings of hardware clock is assumed to be UTC
#
HWCLOCK_ZONE="--utc"
[ "$UTC" = no ] && HWCLOCK_ZONE="--localtime"
# do not touch time adjustment by default
#
[ -z "$ADJTIME" ] && HWCLOCK="$HWCLOCK --noadjfile"
HWCLOCK="$HWCLOCK $HWCLOCK_ZONE"

unset UTC HWCLOCK_ZONE

DESC="Request for the System Clock action(s) using hwclock(8)"
NAME=systemclock


local err

do_start()
{
    if [ ! -z "$ADJTIME" ]; then
        if [ ! -f /etc/adjtime ] && [ ! -e /etc/adjtime ]; then
            log_action_begin_msg '`--> Creating zero adjtime file'
            err=`eval 2>&1 echo "0.0 0 0.0" > /etc/adjtime)`
            log_action_end_msg $?
            [ ! -z "$err" ] && log_failure_msg $err
        fi
    else
        log_action_begin_msg '`--> Checking TZ environment variable'

        if [ ! -f /etc/timezone ] && [ ! -e /etc/timezone ]; then
            log_warning_msg "/etc/timezone file doesn't exist"
            TZ='UTC+00'
        fi
        export TZ=${TZ:-`cat /etc/timezone`}

        log_action_end_msg $?

        log_action_begin_msg '`--> Setting up the System Clock'

        err=`eval 2>&1 $HWCLOCK --hctosys`
        log_action_end_msg $?
        [ ! -z "$err" ] && log_failure_msg $err

        log_success_msg '\tTime zone:\t\t\t'$TZ.
        log_begin_msg '\tSystem Time:\t\t\t'`date`
        log_end_msg $?

        log_begin_msg '\tUniversal Time Coordinated:\t'`date --utc`
        log_end_msg $?
    fi
}

do_stop()
{
    log_action_begin_msg '`--> Saving System Time to the Hardware Clock'
    err=`eval 2>&1 $HWCLOCK --systohc`
    log_action_end_msg $?
    [ ! -z "$err" ] && log_failure_msg $err
}

do_reload() {
    if [ ! -z "$ADJTIME" ]; then
        log_action_begin_msg '`--> Hardware Clock adjustment'
        err=`eval 2>&1 $HWCLOCK --adjust`
        log_action_end_msg $?
        [ ! -z "$err" ] && log_failure_msg $err
    else
        log_warning_msg "Hardware Clock adjustment disabled, skipping." >&2
    fi
}


log_action_begin_msg "$DESC"
echo

case "$1" in
    start|stop|reload|force-reload)
        eval do_$1
        : # subactions report failures
        log_action_end_msg $?
        exit 0
        ;;
    *)
        log_warning_msg "Usage: $0 {start|stop|reload}" >&2
        log_action_end_msg $?
        exit 3
        ;;
esac

"""
Changelog:

* Default time in hardware now assumed to be UTC (opposite to hwclock(8)).
* Badyear handling removed. It's (very) outdated problem and hwclock(8)
  (as stated in man page) warns about this.
* Do not use $VERBOSE, user must see what happend to system time settings.
* Obsolete parameters: $HWCLOCKPARS $HWCLOCKACCESS.
  If one realy wants to disable hwclock or pass some more comand line options,
  let (s)he set $HWCLOCK as needed.
* $ADJTIME may be set in /etc/default/rcS, if this feature of hwclock(8) is
  to be used.
* Setting of defined year (1/1/2002 in this case) in case of error also
  removed. Let user use (whatever) BIOS to correct time/battary etc.
  Nobody will update this date to future, but being there is not so cool.
* Didn't find any TZ setup in my /etc/, thus doing it here too.
"""

Reply via email to