#!/bin/bash # Daniel Casimiro # # Emulates: hash[key]=value # * This function is from: # http://tldp.org/LDP/abs/html/contributed-scripts.html#HASHLIB # # Params: # 1 - hash # 2 - key # 3 - value function hash_set { eval "${Hash_config_varname_prefix}${1}_${2}=\"${3}\"" } # Emulates something similar to: # foreach($hash as $key => $value) { fun($key,$value); } # * This function is from: # http://tldp.org/LDP/abs/html/contributed-scripts.html#HASHLIB # # It is possible to write different variations of this function. # Here we use a function call to make it as "generic" as possible. # # Params: # 1 - hash # 2 - function name function hash_foreach { local keyname oldIFS="$IFS" IFS=' ' for i in $(eval "echo \${!${Hash_config_varname_prefix}${1}_*}"); do keyname=$(eval "echo \${i##${Hash_config_varname_prefix}${1}_}") eval "$2 $keyname \"\$$i\"" done IFS="$oldIFS" } # UnionFS requires different versions for different kernels. # This list is as of 27 October 2006. # Kernel Version Compatibility: # Kernel Version Unionfs Version # 2.4.x (x>19) 1.0.14 # 2.6.x (x<9) Not Supported # 2.6.9 - 2.6.15 1.1.5 # 2.6.16 1.2 # 2.6.17 1.3 # 2.6.18-rc CVS Snapshots # $1 unionfs version # $2 kernel version regular expression test_unionfs_version() { MYKV=`expr match "${KV}" $2` if [ ${MYKV} -gt 0 ]; then # The keys cannot contain '.', so underscores are substituted here. UNIONFS_VERSION=${1/_/.} fi } # set kernel versions regular expressions and unionfs versions in config file # build a hash that maps kernel version re's to unionfs version # for each hash key, use the value when the key regular expression evals # true when compared to ${BASEKV} get_unionfs_version() { # Do not support 2.4 kernels yet; just need another RE. # The hash is hard coded here, but it could be built from variables defined # in /etc/genkernel.conf hash_set unionfsversions 1_1_5 "2\.6\.(9|1[0-5])-" hash_set unionfsversions 1_2 "2\.6\.16-" hash_set unionfsversions 1_3 "2\.6\.17-" # Unset the UNIONFS_VERSION that was set in /etc/genkernel.conf # This function could check if the variable is set, and then break # Or, it could use a different variable name UNIONFS_VERSION= hash_foreach unionfsversions test_unionfs_version if [ -z ${UNIONFS_VERSION} ]; then echo "Invalid kernel for UNIONFS!" exit 1 fi }