xref: /freebsd/usr.sbin/bsdinstall/scripts/time (revision 09c4000afebba1062abe3634893968fea74b78a6)
12118f387SNathan Whitehorn#!/bin/sh
22118f387SNathan Whitehorn#-
32118f387SNathan Whitehorn# Copyright (c) 2011 Nathan Whitehorn
42118f387SNathan Whitehorn# All rights reserved.
52118f387SNathan Whitehorn#
62118f387SNathan Whitehorn# Redistribution and use in source and binary forms, with or without
72118f387SNathan Whitehorn# modification, are permitted provided that the following conditions
82118f387SNathan Whitehorn# are met:
92118f387SNathan Whitehorn# 1. Redistributions of source code must retain the above copyright
102118f387SNathan Whitehorn#    notice, this list of conditions and the following disclaimer.
112118f387SNathan Whitehorn# 2. Redistributions in binary form must reproduce the above copyright
122118f387SNathan Whitehorn#    notice, this list of conditions and the following disclaimer in the
132118f387SNathan Whitehorn#    documentation and/or other materials provided with the distribution.
142118f387SNathan Whitehorn#
152118f387SNathan Whitehorn# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
162118f387SNathan Whitehorn# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
172118f387SNathan Whitehorn# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
182118f387SNathan Whitehorn# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
192118f387SNathan Whitehorn# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
202118f387SNathan Whitehorn# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
212118f387SNathan Whitehorn# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
222118f387SNathan Whitehorn# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
232118f387SNathan Whitehorn# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
242118f387SNathan Whitehorn# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
252118f387SNathan Whitehorn# SUCH DAMAGE.
262118f387SNathan Whitehorn#
272118f387SNathan Whitehorn# $FreeBSD$
282118f387SNathan Whitehorn
29*09c4000aSAllan Jude# Select timezone
302118f387SNathan Whitehornchroot $BSDINSTALL_CHROOT tzsetup
31*09c4000aSAllan Jude
32*09c4000aSAllan Jude# Switch to target timezone
33*09c4000aSAllan Judesaved_TZ="$TZ"
34*09c4000aSAllan JudeTZ="${BSDINSTALL_CHROOT}/etc/localtime"
35*09c4000aSAllan Judeexport TZ
36*09c4000aSAllan Jude
37*09c4000aSAllan Jude# Set date
38*09c4000aSAllan Judeexec 3>&1
39*09c4000aSAllan JudeDATE=$(dialog --backtitle 'FreeBSD Installer' \
40*09c4000aSAllan Jude	--title 'Time & Date' \
41*09c4000aSAllan Jude	--ok-label 'Set Date' \
42*09c4000aSAllan Jude	--cancel-label 'Skip' \
43*09c4000aSAllan Jude	--date-format '%Y%m%d%H%M.%S' \
44*09c4000aSAllan Jude	--calendar '' 2 40 \
45*09c4000aSAllan Jude2>&1 1>&3) && date $DATE
46*09c4000aSAllan Judeexec 3>&-
47*09c4000aSAllan Jude
48*09c4000aSAllan Jude# Set time
49*09c4000aSAllan Judeexec 3>&1
50*09c4000aSAllan JudeTIME=$(dialog --backtitle 'FreeBSD Installer' \
51*09c4000aSAllan Jude	--title 'Time & Date' \
52*09c4000aSAllan Jude	--ok-label 'Set Time' \
53*09c4000aSAllan Jude	--cancel-label 'Skip' \
54*09c4000aSAllan Jude	--time-format '%H%M.%S' \
55*09c4000aSAllan Jude	--timebox '' 2 40 \
56*09c4000aSAllan Jude2>&1 1>&3) && date $TIME
57*09c4000aSAllan Judeexec 3>&-
58*09c4000aSAllan Jude
59*09c4000aSAllan Jude# Switch back
60*09c4000aSAllan Judeif [ -n "$saved_TZ" ]; then
61*09c4000aSAllan Jude	TZ="$saved_TZ"
62*09c4000aSAllan Judeelse
63*09c4000aSAllan Jude	unset TZ
64*09c4000aSAllan Judefi
65*09c4000aSAllan Judeunset saved_TZ
66