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