xref: /titanic_51/usr/src/data/zoneinfo/zonelint (revision 7d2c63f8305d23a81cbff67cf17cb07fe30edb57)
1*7d2c63f8SAndy Fiddaman#!/bin/ksh
2*7d2c63f8SAndy Fiddaman#
3*7d2c63f8SAndy Fiddaman# This file and its contents are supplied under the terms of the
4*7d2c63f8SAndy Fiddaman# Common Development and Distribution License ("CDDL"), version 1.0.
5*7d2c63f8SAndy Fiddaman# You may only use this file in accordance with the terms of version
6*7d2c63f8SAndy Fiddaman# 1.0 of the CDDL.
7*7d2c63f8SAndy Fiddaman#
8*7d2c63f8SAndy Fiddaman# A full copy of the text of the CDDL should have accompanied this
9*7d2c63f8SAndy Fiddaman# source. A copy of the CDDL is also available via the Internet at
10*7d2c63f8SAndy Fiddaman# http://www.illumos.org/license/CDDL.
11*7d2c63f8SAndy Fiddaman
12*7d2c63f8SAndy Fiddaman# Copyright 2020 OmniOS Community Edition (OmniOSce) Association.
13*7d2c63f8SAndy Fiddaman
14*7d2c63f8SAndy Fiddamanf=zone_sun.tab
15*7d2c63f8SAndy Fiddamanproto=$ROOT/usr/share/lib/zoneinfo
16*7d2c63f8SAndy Fiddaman
17*7d2c63f8SAndy Fiddamanif [[ ! -f "$f" ]]; then
18*7d2c63f8SAndy Fiddaman	echo "Run from inside usr/src/data/zoneinfo"
19*7d2c63f8SAndy Fiddaman	exit 1
20*7d2c63f8SAndy Fiddamanfi
21*7d2c63f8SAndy Fiddaman
22*7d2c63f8SAndy Fiddamanif [[ ! -d "$proto" ]]; then
23*7d2c63f8SAndy Fiddaman	echo "No zoneinfo in $proto - run 'dmake install'"
24*7d2c63f8SAndy Fiddaman	exit 1
25*7d2c63f8SAndy Fiddamanfi
26*7d2c63f8SAndy Fiddaman
27*7d2c63f8SAndy Fiddaman# First check that all of the referenced zone files exist in the proto
28*7d2c63f8SAndy Fiddaman# area.
29*7d2c63f8SAndy Fiddaman
30*7d2c63f8SAndy Fiddamannawk -F'\t' '
31*7d2c63f8SAndy Fiddaman	/^#/ { next }
32*7d2c63f8SAndy Fiddaman	{
33*7d2c63f8SAndy Fiddaman		print $3
34*7d2c63f8SAndy Fiddaman		if ($4 != "-")
35*7d2c63f8SAndy Fiddaman			print $4
36*7d2c63f8SAndy Fiddaman	}
37*7d2c63f8SAndy Fiddaman' $f | while read zone; do
38*7d2c63f8SAndy Fiddaman	if [ ! -f $proto/$zone ]; then
39*7d2c63f8SAndy Fiddaman		echo "Missing: $zone"
40*7d2c63f8SAndy Fiddaman	fi
41*7d2c63f8SAndy Fiddamandone
42*7d2c63f8SAndy Fiddaman
43*7d2c63f8SAndy Fiddaman# Check that lines have between 3 and 5 fields
44*7d2c63f8SAndy Fiddaman
45*7d2c63f8SAndy Fiddamannawk -F'\t' '
46*7d2c63f8SAndy Fiddaman	/^#/ { next }
47*7d2c63f8SAndy Fiddaman	NF < 3 || NF > 5 { print NF, $0 }
48*7d2c63f8SAndy Fiddaman' $f | while read line; do
49*7d2c63f8SAndy Fiddaman	echo "Fields: $line"
50*7d2c63f8SAndy Fiddamandone
51*7d2c63f8SAndy Fiddaman
52*7d2c63f8SAndy Fiddaman# Check that field 5 does not point to a zone file. This could indicate a
53*7d2c63f8SAndy Fiddaman# field in the wrong position.
54*7d2c63f8SAndy Fiddaman
55*7d2c63f8SAndy Fiddamannawk -F'\t' '
56*7d2c63f8SAndy Fiddaman	/^#/ { next }
57*7d2c63f8SAndy Fiddaman	NF > 4 { print $5 }
58*7d2c63f8SAndy Fiddaman' $f | while read zone; do
59*7d2c63f8SAndy Fiddaman	if [ -f "$proto/$zone" ]; then
60*7d2c63f8SAndy Fiddaman		echo "Check: $zone"
61*7d2c63f8SAndy Fiddaman	fi
62*7d2c63f8SAndy Fiddamandone
63*7d2c63f8SAndy Fiddaman
64*7d2c63f8SAndy Fiddaman# Check that the file is properly sorted
65*7d2c63f8SAndy Fiddaman
66*7d2c63f8SAndy Fiddamanof=`mktemp`
67*7d2c63f8SAndy Fiddamannf=`mktemp`
68*7d2c63f8SAndy Fiddamannawk '/^#/ { next } { print $1 }' $f > $of
69*7d2c63f8SAndy Fiddamansort < $of > $nf
70*7d2c63f8SAndy Fiddamancmp -s $of $nf || echo "Bad sorting"
71*7d2c63f8SAndy Fiddamanrm -f $of $nf
72*7d2c63f8SAndy Fiddaman
73