xref: /titanic_52/usr/src/data/zoneinfo/update_manifest (revision 639e6f6dee95ad9da6ae775fbcf3f5dfef1cf428)
1743cf225SAndy Fiddaman#!/usr/bin/ksh
2743cf225SAndy Fiddaman#
3743cf225SAndy Fiddaman# This file and its contents are supplied under the terms of the
4743cf225SAndy Fiddaman# Common Development and Distribution License ("CDDL"), version 1.0.
5743cf225SAndy Fiddaman# You may only use this file in accordance with the terms of version
6743cf225SAndy Fiddaman# 1.0 of the CDDL.
7743cf225SAndy Fiddaman#
8743cf225SAndy Fiddaman# A full copy of the text of the CDDL should have accompanied this
9743cf225SAndy Fiddaman# source. A copy of the CDDL is also available via the Internet at
10743cf225SAndy Fiddaman# http://www.illumos.org/license/CDDL.
11743cf225SAndy Fiddaman
12743cf225SAndy Fiddaman# Copyright 2021 OmniOS Community Edition (OmniOSce) Association.
13743cf225SAndy Fiddaman
14743cf225SAndy Fiddamanset -o errexit -o pipefail
15743cf225SAndy Fiddamantrap 'echo Error occured at line $LINENO' ERR
16743cf225SAndy Fiddaman
17743cf225SAndy Fiddamanif [[ ! -v CODEMGR_WS ]] || (($# < 1)); then
18743cf225SAndy Fiddaman	cat <<- EOM
19743cf225SAndy FiddamanThis script should be run within a bldenv by issuing 'make update' in
20743cf225SAndy Fiddaman\$CODEMGR_WS/usr/src/data/zoneinfo
21743cf225SAndy Fiddaman	EOM
22743cf225SAndy Fiddaman	exit 1
23743cf225SAndy Fiddamanfi
24743cf225SAndy Fiddaman
25743cf225SAndy FiddamanMANIFEST=$CODEMGR_WS/usr/src/pkg/manifests/system-data-zoneinfo.mf
26743cf225SAndy FiddamanPREFIX=usr/share/lib/zoneinfo
27743cf225SAndy Fiddaman
28743cf225SAndy Fiddamanif [[ ! -f "$MANIFEST" ]]; then
29743cf225SAndy Fiddaman	echo "Could not find $MANIFEST"
30743cf225SAndy Fiddaman	exit 1
31743cf225SAndy Fiddamanfi
32743cf225SAndy Fiddaman
33*639e6f6dSAndy Fiddamanfunction find_cmd {
34*639e6f6dSAndy Fiddaman	typeset cmd="$1"
35*639e6f6dSAndy Fiddaman	typeset var=$(echo $cmd | tr '[:lower:]' '[:upper:]')
36*639e6f6dSAndy Fiddaman	typeset -n path="$var"
37*639e6f6dSAndy Fiddaman	path=$(whence -fp "$cmd")
38*639e6f6dSAndy Fiddaman	if (($? != 0)) || [ ! -x "$path" ]; then
39*639e6f6dSAndy Fiddaman		echo "Cannot find executable '$cmd' in PATH"
40*639e6f6dSAndy Fiddaman		exit 1
41*639e6f6dSAndy Fiddaman	fi
42*639e6f6dSAndy Fiddaman}
43*639e6f6dSAndy Fiddaman
44*639e6f6dSAndy Fiddaman# This script uses a few commands which are not part of illumos and are
45*639e6f6dSAndy Fiddaman# expected to be available in the path.
46*639e6f6dSAndy Fiddamanfind_cmd pkgfmt
47*639e6f6dSAndy Fiddaman
48743cf225SAndy Fiddamantypeset -A links
49743cf225SAndy Fiddamantypeset -A targets
50743cf225SAndy Fiddamanfor f in "$@"; do
51743cf225SAndy Fiddaman	if [[ ! -r "$f" ]]; then
52743cf225SAndy Fiddaman		echo "Could not read $f"
53743cf225SAndy Fiddaman		exit 1
54743cf225SAndy Fiddaman	fi
55743cf225SAndy Fiddaman	echo "+++ Processing input file $f"
56743cf225SAndy Fiddaman	grep '^Link' "$f" | tr -s '[:space:]' | \
57743cf225SAndy Fiddaman	    while IFS=$' \t' read _ tgt src _; do
58743cf225SAndy Fiddaman
59743cf225SAndy Fiddaman		osrc=$src
60743cf225SAndy Fiddaman		targets[$tgt]=1
61743cf225SAndy Fiddaman
62743cf225SAndy Fiddaman		printf "    %20s => %s\n" $src $tgt
63743cf225SAndy Fiddaman
64743cf225SAndy Fiddaman		while [[ $src == */* && ${src%%/*} == ${tgt%%/*} ]]; do
65743cf225SAndy Fiddaman			src=${src#*/}
66743cf225SAndy Fiddaman			tgt=${tgt#*/}
67743cf225SAndy Fiddaman		done
68743cf225SAndy Fiddaman
69743cf225SAndy Fiddaman		# On no matches, grep -o exits non-zero, hence the || true to
70743cf225SAndy Fiddaman		# satisfy the shell's errexit option.
71743cf225SAndy Fiddaman		sslashes=$(echo $src | grep -o / | wc -l || true)
72743cf225SAndy Fiddaman		r=
73743cf225SAndy Fiddaman		while ((sslashes-- > 0)); do
74743cf225SAndy Fiddaman			r+="../"
75743cf225SAndy Fiddaman		done
76743cf225SAndy Fiddaman		links[$osrc]="$r$tgt"
77743cf225SAndy Fiddaman	done
78743cf225SAndy Fiddamandone
79743cf225SAndy Fiddaman
80743cf225SAndy Fiddamantmpf1=`mktemp`
81743cf225SAndy Fiddamantmpf2=`mktemp`
82743cf225SAndy Fiddamantrap 'rm -f $tmpf1 $tmpf2' EXIT
83743cf225SAndy Fiddaman[[ -n "$tmpf1" && -f "$tmpf1" ]]
84743cf225SAndy Fiddaman[[ -n "$tmpf2" && -f "$tmpf2" ]]
85743cf225SAndy Fiddaman
86743cf225SAndy Fiddamancp $MANIFEST $tmpf1
87*639e6f6dSAndy Fiddaman$PKGFMT -u $tmpf1
88743cf225SAndy Fiddaman
89743cf225SAndy Fiddamanecho "+++ Removing existing hardlinks from manifest"
90743cf225SAndy Fiddamanegrep -v "^hardlink " $tmpf1 > $tmpf2
91743cf225SAndy Fiddamanmv $tmpf2 $tmpf1
92743cf225SAndy Fiddaman
93743cf225SAndy Fiddamanecho "+++ Removing existing targets from manifest"
94743cf225SAndy Fiddamanfor i in "${!links[@]}" "${!targets[@]}"; do
95743cf225SAndy Fiddaman	egrep -v "^file path=$PREFIX/$i\$" $tmpf1 > $tmpf2
96743cf225SAndy Fiddaman	mv $tmpf2 $tmpf1
97743cf225SAndy Fiddamandone
98743cf225SAndy Fiddaman
99743cf225SAndy Fiddamanecho "+++ Adding new entries to manifest"
100743cf225SAndy Fiddaman{
101743cf225SAndy Fiddaman	for i in "${!targets[@]}"; do
102743cf225SAndy Fiddaman		echo "file path=$PREFIX/$i"
103743cf225SAndy Fiddaman	done
104743cf225SAndy Fiddaman	for i in "${!links[@]}"; do
105743cf225SAndy Fiddaman		echo "hardlink path=$PREFIX/$i target=${links[$i]}"
106743cf225SAndy Fiddaman	done
107743cf225SAndy Fiddaman} >> $tmpf1
108743cf225SAndy Fiddaman
109743cf225SAndy Fiddamanecho "+++ Formatting manifest"
110*639e6f6dSAndy Fiddaman$PKGFMT -f v1 $tmpf1
111743cf225SAndy Fiddaman
112743cf225SAndy Fiddamanmv $tmpf1 $MANIFEST
113743cf225SAndy Fiddaman
114