xref: /titanic_52/usr/src/data/zoneinfo/update_manifest (revision 743cf22567cc013b3c62c1efae0455fa7c838c60)
1*743cf225SAndy Fiddaman#!/usr/bin/ksh
2*743cf225SAndy Fiddaman#
3*743cf225SAndy Fiddaman# This file and its contents are supplied under the terms of the
4*743cf225SAndy Fiddaman# Common Development and Distribution License ("CDDL"), version 1.0.
5*743cf225SAndy Fiddaman# You may only use this file in accordance with the terms of version
6*743cf225SAndy Fiddaman# 1.0 of the CDDL.
7*743cf225SAndy Fiddaman#
8*743cf225SAndy Fiddaman# A full copy of the text of the CDDL should have accompanied this
9*743cf225SAndy Fiddaman# source. A copy of the CDDL is also available via the Internet at
10*743cf225SAndy Fiddaman# http://www.illumos.org/license/CDDL.
11*743cf225SAndy Fiddaman
12*743cf225SAndy Fiddaman# Copyright 2021 OmniOS Community Edition (OmniOSce) Association.
13*743cf225SAndy Fiddaman
14*743cf225SAndy Fiddamanset -o errexit -o pipefail
15*743cf225SAndy Fiddamantrap 'echo Error occured at line $LINENO' ERR
16*743cf225SAndy Fiddaman
17*743cf225SAndy Fiddamanif [[ ! -v CODEMGR_WS ]] || (($# < 1)); then
18*743cf225SAndy Fiddaman	cat <<- EOM
19*743cf225SAndy FiddamanThis script should be run within a bldenv by issuing 'make update' in
20*743cf225SAndy Fiddaman\$CODEMGR_WS/usr/src/data/zoneinfo
21*743cf225SAndy Fiddaman	EOM
22*743cf225SAndy Fiddaman	exit 1
23*743cf225SAndy Fiddamanfi
24*743cf225SAndy Fiddaman
25*743cf225SAndy FiddamanMANIFEST=$CODEMGR_WS/usr/src/pkg/manifests/system-data-zoneinfo.mf
26*743cf225SAndy FiddamanPREFIX=usr/share/lib/zoneinfo
27*743cf225SAndy Fiddaman
28*743cf225SAndy Fiddamanif [[ ! -f "$MANIFEST" ]]; then
29*743cf225SAndy Fiddaman	echo "Could not find $MANIFEST"
30*743cf225SAndy Fiddaman	exit 1
31*743cf225SAndy Fiddamanfi
32*743cf225SAndy Fiddaman
33*743cf225SAndy Fiddamantypeset -A links
34*743cf225SAndy Fiddamantypeset -A targets
35*743cf225SAndy Fiddamanfor f in "$@"; do
36*743cf225SAndy Fiddaman	if [[ ! -r "$f" ]]; then
37*743cf225SAndy Fiddaman		echo "Could not read $f"
38*743cf225SAndy Fiddaman		exit 1
39*743cf225SAndy Fiddaman	fi
40*743cf225SAndy Fiddaman	echo "+++ Processing input file $f"
41*743cf225SAndy Fiddaman	grep '^Link' "$f" | tr -s '[:space:]' | \
42*743cf225SAndy Fiddaman	    while IFS=$' \t' read _ tgt src _; do
43*743cf225SAndy Fiddaman
44*743cf225SAndy Fiddaman		osrc=$src
45*743cf225SAndy Fiddaman		targets[$tgt]=1
46*743cf225SAndy Fiddaman
47*743cf225SAndy Fiddaman		printf "    %20s => %s\n" $src $tgt
48*743cf225SAndy Fiddaman
49*743cf225SAndy Fiddaman		while [[ $src == */* && ${src%%/*} == ${tgt%%/*} ]]; do
50*743cf225SAndy Fiddaman			src=${src#*/}
51*743cf225SAndy Fiddaman			tgt=${tgt#*/}
52*743cf225SAndy Fiddaman		done
53*743cf225SAndy Fiddaman
54*743cf225SAndy Fiddaman		# On no matches, grep -o exits non-zero, hence the || true to
55*743cf225SAndy Fiddaman		# satisfy the shell's errexit option.
56*743cf225SAndy Fiddaman		sslashes=$(echo $src | grep -o / | wc -l || true)
57*743cf225SAndy Fiddaman		r=
58*743cf225SAndy Fiddaman		while ((sslashes-- > 0)); do
59*743cf225SAndy Fiddaman			r+="../"
60*743cf225SAndy Fiddaman		done
61*743cf225SAndy Fiddaman		links[$osrc]="$r$tgt"
62*743cf225SAndy Fiddaman	done
63*743cf225SAndy Fiddamandone
64*743cf225SAndy Fiddaman
65*743cf225SAndy Fiddamantmpf1=`mktemp`
66*743cf225SAndy Fiddamantmpf2=`mktemp`
67*743cf225SAndy Fiddamantrap 'rm -f $tmpf1 $tmpf2' EXIT
68*743cf225SAndy Fiddaman[[ -n "$tmpf1" && -f "$tmpf1" ]]
69*743cf225SAndy Fiddaman[[ -n "$tmpf2" && -f "$tmpf2" ]]
70*743cf225SAndy Fiddaman
71*743cf225SAndy Fiddamancp $MANIFEST $tmpf1
72*743cf225SAndy Fiddamanpkgfmt -u $tmpf1
73*743cf225SAndy Fiddaman
74*743cf225SAndy Fiddamanecho "+++ Removing existing hardlinks from manifest"
75*743cf225SAndy Fiddamanegrep -v "^hardlink " $tmpf1 > $tmpf2
76*743cf225SAndy Fiddamanmv $tmpf2 $tmpf1
77*743cf225SAndy Fiddaman
78*743cf225SAndy Fiddamanecho "+++ Removing existing targets from manifest"
79*743cf225SAndy Fiddamanfor i in "${!links[@]}" "${!targets[@]}"; do
80*743cf225SAndy Fiddaman	egrep -v "^file path=$PREFIX/$i\$" $tmpf1 > $tmpf2
81*743cf225SAndy Fiddaman	mv $tmpf2 $tmpf1
82*743cf225SAndy Fiddamandone
83*743cf225SAndy Fiddaman
84*743cf225SAndy Fiddamanecho "+++ Adding new entries to manifest"
85*743cf225SAndy Fiddaman{
86*743cf225SAndy Fiddaman	for i in "${!targets[@]}"; do
87*743cf225SAndy Fiddaman		echo "file path=$PREFIX/$i"
88*743cf225SAndy Fiddaman	done
89*743cf225SAndy Fiddaman	for i in "${!links[@]}"; do
90*743cf225SAndy Fiddaman		echo "hardlink path=$PREFIX/$i target=${links[$i]}"
91*743cf225SAndy Fiddaman	done
92*743cf225SAndy Fiddaman} >> $tmpf1
93*743cf225SAndy Fiddaman
94*743cf225SAndy Fiddamanecho "+++ Formatting manifest"
95*743cf225SAndy Fiddamanpkgfmt -f v1 $tmpf1
96*743cf225SAndy Fiddaman
97*743cf225SAndy Fiddamanmv $tmpf1 $MANIFEST
98*743cf225SAndy Fiddaman
99