|
root / base / usr / src / data / zoneinfo / update_manifest
update_manifest Plain Text 114 lines 2.6 KB
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/usr/bin/ksh
#
# This file and its contents are supplied under the terms of the
# Common Development and Distribution License ("CDDL"), version 1.0.
# You may only use this file in accordance with the terms of version
# 1.0 of the CDDL.
#
# A full copy of the text of the CDDL should have accompanied this
# source. A copy of the CDDL is also available via the Internet at
# http://www.illumos.org/license/CDDL.

# Copyright 2021 OmniOS Community Edition (OmniOSce) Association.

set -o errexit -o pipefail
trap 'echo Error occured at line $LINENO' ERR

if [[ ! -v CODEMGR_WS ]] || (($# < 1)); then
	cat <<- EOM
This script should be run within a bldenv by issuing 'make update' in
\$CODEMGR_WS/usr/src/data/zoneinfo
	EOM
	exit 1
fi

MANIFEST=$CODEMGR_WS/usr/src/pkg/manifests/system-data-zoneinfo.p5m
PREFIX=usr/share/lib/zoneinfo

if [[ ! -f "$MANIFEST" ]]; then
	echo "Could not find $MANIFEST"
	exit 1
fi

function find_cmd {
	typeset cmd="$1"
	typeset var=$(echo $cmd | tr '[:lower:]' '[:upper:]')
	typeset -n path="$var"
	path=$(whence -fp "$cmd")
	if (($? != 0)) || [ ! -x "$path" ]; then
		echo "Cannot find executable '$cmd' in PATH"
		exit 1
	fi
}

# This script uses a few commands which are not part of illumos and are
# expected to be available in the path.
find_cmd pkgfmt

typeset -A links
typeset -A targets
for f in "$@"; do
	if [[ ! -r "$f" ]]; then
		echo "Could not read $f"
		exit 1
	fi
	echo "+++ Processing input file $f"
	grep '^Link' "$f" | tr -s '[:space:]' | \
	    while IFS=$' \t' read _ tgt src _; do

		osrc=$src
		targets[$tgt]=1

		printf "    %20s => %s\n" $src $tgt

		while [[ $src == */* && ${src%%/*} == ${tgt%%/*} ]]; do
			src=${src#*/}
			tgt=${tgt#*/}
		done

		# On no matches, grep -o exits non-zero, hence the || true to
		# satisfy the shell's errexit option.
		sslashes=$(echo $src | grep -o / | wc -l || true)
		r=
		while ((sslashes-- > 0)); do
			r+="../"
		done
		links[$osrc]="$r$tgt"
	done
done

tmpf1=`mktemp`
tmpf2=`mktemp`
trap 'rm -f $tmpf1 $tmpf2' EXIT
[[ -n "$tmpf1" && -f "$tmpf1" ]]
[[ -n "$tmpf2" && -f "$tmpf2" ]]

cp $MANIFEST $tmpf1
$PKGFMT -u $tmpf1

echo "+++ Removing existing hardlinks from manifest"
egrep -v "^hardlink " $tmpf1 > $tmpf2
mv $tmpf2 $tmpf1

echo "+++ Removing existing targets from manifest"
for i in "${!links[@]}" "${!targets[@]}"; do
	egrep -v "^file path=$PREFIX/$i\$" $tmpf1 > $tmpf2
	mv $tmpf2 $tmpf1
done

echo "+++ Adding new entries to manifest"
{
	for i in "${!targets[@]}"; do
		echo "file path=$PREFIX/$i"
	done
	for i in "${!links[@]}"; do
		echo "hardlink path=$PREFIX/$i target=${links[$i]}"
	done
} >> $tmpf1

echo "+++ Formatting manifest"
$PKGFMT -fv2 $tmpf1

mv $tmpf1 $MANIFEST