134f9b3eRoland Mainz#!/usr/bin/ksh93
234f9b3eRoland Mainz
334f9b3eRoland Mainz#
434f9b3eRoland Mainz# CDDL HEADER START
534f9b3eRoland Mainz#
634f9b3eRoland Mainz# The contents of this file are subject to the terms of the
734f9b3eRoland Mainz# Common Development and Distribution License (the "License").
834f9b3eRoland Mainz# You may not use this file except in compliance with the License.
934f9b3eRoland Mainz#
1034f9b3eRoland Mainz# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
1134f9b3eRoland Mainz# or http://www.opensolaris.org/os/licensing.
1234f9b3eRoland Mainz# See the License for the specific language governing permissions
1334f9b3eRoland Mainz# and limitations under the License.
1434f9b3eRoland Mainz#
1534f9b3eRoland Mainz# When distributing Covered Code, include this CDDL HEADER in each
1634f9b3eRoland Mainz# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
1734f9b3eRoland Mainz# If applicable, add the following below this CDDL HEADER, with the
1834f9b3eRoland Mainz# fields enclosed by brackets "[]" replaced with your own identifying
1934f9b3eRoland Mainz# information: Portions Copyright [yyyy] [name of copyright owner]
2034f9b3eRoland Mainz#
2134f9b3eRoland Mainz# CDDL HEADER END
2234f9b3eRoland Mainz#
2334f9b3eRoland Mainz
2434f9b3eRoland Mainz#
253e14f97Roger A. Faulkner# Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
2634f9b3eRoland Mainz#
2734f9b3eRoland Mainz
2834f9b3eRoland Mainz#
2934f9b3eRoland Mainz# simplefileattributetree1 - build a simple file tree (including file attributes)
3034f9b3eRoland Mainz#
3134f9b3eRoland Mainz
3234f9b3eRoland Mainz# Solaris needs /usr/xpg6/bin:/usr/xpg4/bin because the tools in /usr/bin are not POSIX-conformant
3334f9b3eRoland Mainzexport PATH=/usr/xpg6/bin:/usr/xpg4/bin:/bin:/usr/bin
3434f9b3eRoland Mainz
3534f9b3eRoland Mainz# Make sure all math stuff runs in the "C" locale to avoid problems
3634f9b3eRoland Mainz# with alternative # radix point representations (e.g. ',' instead of
3734f9b3eRoland Mainz# '.' in de_DE.*-locales). This needs to be set _before_ any
3834f9b3eRoland Mainz# floating-point constants are defined in this script).
3934f9b3eRoland Mainzif [[ "${LC_ALL}" != "" ]] ; then
4034f9b3eRoland Mainz    export \
4134f9b3eRoland Mainz        LC_MONETARY="${LC_ALL}" \
4234f9b3eRoland Mainz        LC_MESSAGES="${LC_ALL}" \
4334f9b3eRoland Mainz        LC_COLLATE="${LC_ALL}" \
4434f9b3eRoland Mainz        LC_CTYPE="${LC_ALL}"
4534f9b3eRoland Mainz        unset LC_ALL
4634f9b3eRoland Mainzfi
4734f9b3eRoland Mainzexport LC_NUMERIC=C
4834f9b3eRoland Mainz
4934f9b3eRoland Mainz
5034f9b3eRoland Mainzfunction add_file_to_tree
5134f9b3eRoland Mainz{
5234f9b3eRoland Mainz	typeset treename=$1
5334f9b3eRoland Mainz	typeset filename=$2
5434f9b3eRoland Mainz	nameref destnodename=$3
5534f9b3eRoland Mainz	integer i
5634f9b3eRoland Mainz	typeset nodepath # full name of compound variable
5734f9b3eRoland Mainz	typeset -a pe # path elements
5834f9b3eRoland Mainz
5934f9b3eRoland Mainz	# first built an array containing the names of each path element
6034f9b3eRoland Mainz	# (e.g. "foo/var/baz"" results in an array containing "( 'foo' 'bar' 'baz' )")
6134f9b3eRoland Mainz	typeset IFS='/'
6234f9b3eRoland Mainz	pe+=( ${filename} )
6334f9b3eRoland Mainz	
6434f9b3eRoland Mainz	[[ ${pe[0]} == '' ]] && pe[0]='/'
6534f9b3eRoland Mainz
6634f9b3eRoland Mainz	# walk path described via the "pe" array and build nodes if
6734f9b3eRoland Mainz	# there aren't any nodes yet
6834f9b3eRoland Mainz	nodepath="${treename}"
6934f9b3eRoland Mainz	for (( i=0 ; i < (${#pe[@]}-1) ; i++ )) ; do
7034f9b3eRoland Mainz		nameref x="${nodepath}"
713e14f97Roger A. Faulkner
723e14f97Roger A. Faulkner		# [[ -v ]] does not work for arrays because [[ -v ar ]]
733e14f97Roger A. Faulkner		# is equal to [[ -v ar[0] ]]. In this case we can
743e14f97Roger A. Faulkner		# use the output of typeset +p x.nodes
753e14f97Roger A. Faulkner		[[ "${ typeset +p x.nodes ; }" == "" ]] && compound -A x.nodes
7634f9b3eRoland Mainz	
7734f9b3eRoland Mainz		nodepath+=".nodes[${pe[i]}]"
7834f9b3eRoland Mainz	done
7934f9b3eRoland Mainz	
8034f9b3eRoland Mainz	# insert element
8134f9b3eRoland Mainz	nameref node="${nodepath}"
823e14f97Roger A. Faulkner	[[ "${ typeset +p node.elements ; }" == "" ]] && compound -A node.elements
8334f9b3eRoland Mainz	node.elements[${pe[i]}]=(
8434f9b3eRoland Mainz		filepath="${filename}"
8534f9b3eRoland Mainz	)
8634f9b3eRoland Mainz	
8734f9b3eRoland Mainz	destnodename="${!node}.elements[${pe[i]}]"
8834f9b3eRoland Mainz	
8934f9b3eRoland Mainz	return 0
9034f9b3eRoland Mainz}
9134f9b3eRoland Mainz
9234f9b3eRoland Mainzfunction parse_findls
9334f9b3eRoland Mainz{
9434f9b3eRoland Mainz	nameref out=$1
9534f9b3eRoland Mainz	typeset str="$2"
9634f9b3eRoland Mainz	
9734f9b3eRoland Mainz	# find -ls on Solaris uses the following output format by default:
9834f9b3eRoland Mainz	#604302    3 -rw-r--r--   1 test001  users        2678 May  9 00:46 ./httpsresdump
9934f9b3eRoland Mainz
10034f9b3eRoland Mainz	integer out.inodenum="${str/~(Elr)[[:space:]]*([[:digit:]]+)[[:space:]]+([[:digit:]]+)[[:space:]]+([[:alpha:]-]+)[[:space:]]+([[:digit:]]+)[[:space:]]+([[:alnum:]]+)[[:space:]]+([[:alnum:]]+)[[:space:]]+([[:digit:]]+)[[:space:]]+([[:alpha:]]*[[:space:]]+[[:digit:]]*[[:space:]]+[[:digit:]:]+)[[:space:]]+(.+)/\1}"
10134f9b3eRoland Mainz	integer out.kbblocks="${str/~(Elr)[[:space:]]*([[:digit:]]+)[[:space:]]+([[:digit:]]+)[[:space:]]+([[:alpha:]-]+)[[:space:]]+([[:digit:]]+)[[:space:]]+([[:alnum:]]+)[[:space:]]+([[:alnum:]]+)[[:space:]]+([[:digit:]]+)[[:space:]]+([[:alpha:]]*[[:space:]]+[[:digit:]]*[[:space:]]+[[:digit:]:]+)[[:space:]]+(.+)/\2}"
10234f9b3eRoland Mainz	typeset out.mode="${str/~(Elr)[[:space:]]*([[:digit:]]+)[[:space:]]+([[:digit:]]+)[[:space:]]+([[:alpha:]-]+)[[:space:]]+([[:digit:]]+)[[:space:]]+([[:alnum:]]+)[[:space:]]+([[:alnum:]]+)[[:space:]]+([[:digit:]]+)[[:space:]]+([[:alpha:]]*[[:space:]]+[[:digit:]]*[[:space:]]+[[:digit:]:]+)[[:space:]]+(.+)/\3}"
10334f9b3eRoland Mainz	integer out.numlinks="${str/~(Elr)[[:space:]]*([[:digit:]]+)[[:space:]]+([[:digit:]]+)[[:space:]]+([[:alpha:]-]+)[[:space:]]+([[:digit:]]+)[[:space:]]+([[:alnum:]]+)[[:space:]]+([[:alnum:]]+)[[:space:]]+([[:digit:]]+)[[:space:]]+([[:alpha:]]*[[:space:]]+[[:digit:]]*[[:space:]]+[[:digit:]:]+)[[:space:]]+(.+)/\4}"
10434f9b3eRoland Mainz	compound out.owner=(
10534f9b3eRoland Mainz		typeset user="${str/~(Elr)[[:space:]]*([[:digit:]]+)[[:space:]]+([[:digit:]]+)[[:space:]]+([[:alpha:]-]+)[[:space:]]+([[:digit:]]+)[[:space:]]+([[:alnum:]]+)[[:space:]]+([[:alnum:]]+)[[:space:]]+([[:digit:]]+)[[:space:]]+([[:alpha:]]*[[:space:]]+[[:digit:]]*[[:space:]]+[[:digit:]:]+)[[:space:]]+(.+)/\5}"
10634f9b3eRoland Mainz		typeset group="${str/~(Elr)[[:space:]]*([[:digit:]]+)[[:space:]]+([[:digit:]]+)[[:space:]]+([[:alpha:]-]+)[[:space:]]+([[:digit:]]+)[[:space:]]+([[:alnum:]]+)[[:space:]]+([[:alnum:]]+)[[:space:]]+([[:digit:]]+)[[:space:]]+([[:alpha:]]*[[:space:]]+[[:digit:]]*[[:space:]]+[[:digit:]:]+)[[:space:]]+(.+)/\6}"
10734f9b3eRoland Mainz	)
10834f9b3eRoland Mainz	integer out.filesize="${str/~(Elr)[[:space:]]*([[:digit:]]+)[[:space:]]+([[:digit:]]+)[[:space:]]+([[:alpha:]-]+)[[:space:]]+([[:digit:]]+)[[:space:]]+([[:alnum:]]+)[[:space:]]+([[:alnum:]]+)[[:space:]]+([[:digit:]]+)[[:space:]]+([[:alpha:]]*[[:space:]]+[[:digit:]]*[[:space:]]+[[:digit:]:]+)[[:space:]]+(.+)/\7}"
10934f9b3eRoland Mainz	typeset out.date="${str/~(Elr)[[:space:]]*([[:digit:]]+)[[:space:]]+([[:digit:]]+)[[:space:]]+([[:alpha:]-]+)[[:space:]]+([[:digit:]]+)[[:space:]]+([[:alnum:]]+)[[:space:]]+([[:alnum:]]+)[[:space:]]+([[:digit:]]+)[[:space:]]+([[:alpha:]]*[[:space:]]+[[:digit:]]*[[:space:]]+[[:digit:]:]+)[[:space:]]+(.+)/\8}"
11034f9b3eRoland Mainz	typeset out.filepath="${str/~(Elr)[[:space:]]*([[:digit:]]+)[[:space:]]+([[:digit:]]+)[[:space:]]+([[:alpha:]-]+)[[:space:]]+([[:digit:]]+)[[:space:]]+([[:alnum:]]+)[[:space:]]+([[:alnum:]]+)[[:space:]]+([[:digit:]]+)[[:space:]]+([[:alpha:]]*[[:space:]]+[[:digit:]]*[[:space:]]+[[:digit:]:]+)[[:space:]]+(.+)/\9}"
11134f9b3eRoland Mainz
11234f9b3eRoland Mainz	return 0
11334f9b3eRoland Mainz}
11434f9b3eRoland Mainz
11534f9b3eRoland Mainzfunction usage
11634f9b3eRoland Mainz{
11734f9b3eRoland Mainz	OPTIND=0
11834f9b3eRoland Mainz	getopts -a "${progname}" "${simplefileattributetree1_usage}" OPT '-?'
11934f9b3eRoland Mainz	exit 2
12034f9b3eRoland Mainz}
12134f9b3eRoland Mainz
12234f9b3eRoland Mainz# main
12334f9b3eRoland Mainzbuiltin basename
12434f9b3eRoland Mainzbuiltin dirname
12534f9b3eRoland Mainz
12634f9b3eRoland Mainzset -o noglob
12734f9b3eRoland Mainzset -o nounset
12834f9b3eRoland Mainz
12934f9b3eRoland Mainz# tree base
13034f9b3eRoland Mainzcompound filetree
13134f9b3eRoland Mainz
13234f9b3eRoland Mainz# benchmark data
13334f9b3eRoland Mainzcompound bench=(
13434f9b3eRoland Mainz	float start
13534f9b3eRoland Mainz	float stop
13634f9b3eRoland Mainz)
13734f9b3eRoland Mainz
13834f9b3eRoland Mainzcompound appconfig=(
13934f9b3eRoland Mainz	typeset do_benchmarking=false
14034f9b3eRoland Mainz	compound do_record=(
14134f9b3eRoland Mainz		typeset content=false
14234f9b3eRoland Mainz		typeset filetype=false
143