Browse Source

add and use a set_class function. This adds one or more class(es) to the CLASSES environment variable

master
Georg Hopp 12 years ago
parent
commit
4c700f3ae1
  1. 3
      gatherer/cpu_information.sh
  2. 4
      gatherer/dist_information.sh
  3. 4
      gatherer/host_information.sh
  4. 6
      gatherer/interface_information.sh
  5. 14
      utils/classes.sh

3
gatherer/cpu_information.sh

@ -20,8 +20,7 @@ gather_cpu_info() {
/Virtualization/ { print "export CPU_VIRT=\"" $2 "\";" }') /Virtualization/ { print "export CPU_VIRT=\"" $2 "\";" }')
} }
CLASSES="${CLASSES}${NCPUS}cpus ${CPU_VIRT} ${BYTE_ORDER} ${OP_MODES} "
CLASSES="$(${ECHO} "${CLASSES}" | "${SED}" 's/ \+/ /g')"
set_class ${NCPUS}cpus ${CPU_VIRT} ${BYTE_ORDER} ${OP_MODES}
} }
# vim: set ts=4 sw=4: # vim: set ts=4 sw=4:

4
gatherer/dist_information.sh

@ -87,12 +87,12 @@ gather_dist_info() {
eval ${GREP} -iq ${DIST} \${FILES_${CHK}} || DIST="Unknown" eval ${GREP} -iq ${DIST} \${FILES_${CHK}} || DIST="Unknown"
fi fi
CLASSES="${CLASSES}${DIST} ";;
set_class ${CLASSES} ${DIST};;
*) *)
DIST="${OS}" DIST="${OS}"
esac esac
export DIST CLASSES
export DIST
} }
# vim: set ts=4 sw=4: # vim: set ts=4 sw=4:

4
gatherer/host_information.sh

@ -10,10 +10,10 @@ gather_host_info() {
PLATFORM="$(${UNAME} -m)" PLATFORM="$(${UNAME} -m)"
HOSTNAME="$(${UNAME} -n)" HOSTNAME="$(${UNAME} -n)"
GNU="$([ "${OS%GNU*}" != ${OS} ] && echo "GNU")" GNU="$([ "${OS%GNU*}" != ${OS} ] && echo "GNU")"
CLASSES="${OS}\n${GNU}\n${KERNEL}\n${VERSION}\n${PLATFORM}\n${HOSTNAME}"
CLASSES="$(${ECHO} -e "${CLASSES}" | ${SORT} -u | ${TR} "\n" " ")"
export OS KERNEL VERSION PLATFORM HOSTNAME CLASSES export OS KERNEL VERSION PLATFORM HOSTNAME CLASSES
set_class ${OS} ${GNU} ${KERNEL} ${VERSION} ${PLATFORM} ${HOSTNAME}
} }
# vim: set ts=4 sw=4: # vim: set ts=4 sw=4:

6
gatherer/interface_information.sh

@ -22,7 +22,6 @@ gather_interface_info() {
fi fi
export NINTERFACES export NINTERFACES
export CLASSES
while [ ${NO} -le ${NINTERFACES:=0} ] while [ ${NO} -le ${NINTERFACES:=0} ]
do do
@ -56,7 +55,7 @@ gather_if_info_ip() {
classes="" classes=""
} }
END { END {
print "CLASSES=\"${CLASSES}" classes " \";";
print "set_class " classes ";";
print "NINTERFACES=" FNR ";" print "NINTERFACES=" FNR ";"
}') }')
@ -78,12 +77,13 @@ gather_if_info_ip() {
classes="" classes=""
} }
END { END {
print "CLASSES=\"${CLASSES}" classes " \";"
print "set_class " classes ";"
}') }')
} }
## ##
# get interface data via the ifconfig tool # get interface data via the ifconfig tool
# FIXME This is outdated. It does not set classes at all.
# #
gather_if_info_ifconfig() { gather_if_info_ifconfig() {
eval $(${IFCONFIG} -a | ${AWK} ' eval $(${IFCONFIG} -a | ${AWK} '

14
utils/classes.sh

@ -9,4 +9,18 @@ has_class() {
test "${CHECK}" != "${CHECK% ${1} *}" test "${CHECK}" != "${CHECK% ${1} *}"
} }
##
# add one or more classes given as arguments to this function
# Using ${@} here effectively eliminates multiple spaces between
# the classnames.
# A class might be defined multiple times...I don't eliminate these
# duplicates as this might involve calling uniq which is unneccesary
# overhead as I see no harm in duplicates now.
#
set_class() {
[ -z "${CLASSES}" ] &&
{ CLASSES="${@}"; export CLASSES; } ||
CLASSES="${CLASSES} ${@}"
}
# vim: set ts=4 sw=4: # vim: set ts=4 sw=4:
Loading…
Cancel
Save