properties.shlib revision 1d32ba663e202c24a5a1f2e5aef83fffb447cb7f
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# This file and its contents are supplied under the terms of the
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# Common Development and Distribution License ("CDDL"), version 1.0.
3e14f97f673e8a630f076077de35afdd43dc1587Roger A. Faulkner# You may only use this file in accordance with the terms of version
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# 1.0 of the CDDL.
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin# A full copy of the text of the CDDL should have accompanied this
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# source. A copy of the CDDL is also available via the Internet at
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# http://www.illumos.org/license/CDDL.
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# Copyright (c) 2012, 2016 by Delphix. All rights reserved.
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chintypeset -a compress_props=('on' 'off' 'lzjb' 'gzip' 'gzip-1' 'gzip-2' 'gzip-3'
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin 'gzip-4' 'gzip-5' 'gzip-6' 'gzip-7' 'gzip-8' 'gzip-9' 'zle')
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chintypeset -a checksum_props=('on' 'off' 'fletcher2' 'fletcher4' 'sha256')
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# Given the property array passed in, return 'num_props' elements to the
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# user, excluding any elements below 'start.' This allows us to exclude
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# 'off' and 'on' which can be either unwanted, or a duplicate of another
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# property respectively.
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinfunction get_rand_prop
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin{
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin typeset prop_array=($(eval echo \${$1[@]}))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin typeset -i num_props=$2
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin typeset -i start=$3
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin typeset retstr=""
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin [[ -z $prop_array || -z $num_props || -z $start ]] && \
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin log_fail "get_rand_prop: bad arguments"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin typeset prop_max=$((${#prop_array[@]} - 1))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin typeset -i i
for i in $(shuf -i $start-$prop_max -n $num_props); do
retstr="${prop_array[$i]} $retstr"
done
echo $retstr
}
function get_rand_compress
{
get_rand_prop compress_props $1 2
}
function get_rand_compress_any
{
get_rand_prop compress_props $1 0
}
function get_rand_checksum
{
get_rand_prop checksum_props $1 2
}
function get_rand_checksum_any
{
get_rand_prop checksum_props $1 0
}