Commit 4c700f3ae15b3ddb82fa88836a87137b8dd6ace2

Authored by Georg Hopp
1 parent f54c398c

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

… environment variable
... ... @@ -20,8 +20,7 @@ gather_cpu_info() {
20 20 /Virtualization/ { print "export CPU_VIRT=\"" $2 "\";" }')
21 21 }
22 22
23   - CLASSES="${CLASSES}${NCPUS}cpus ${CPU_VIRT} ${BYTE_ORDER} ${OP_MODES} "
24   - CLASSES="$(${ECHO} "${CLASSES}" | "${SED}" 's/ \+/ /g')"
  23 + set_class ${NCPUS}cpus ${CPU_VIRT} ${BYTE_ORDER} ${OP_MODES}
25 24 }
26 25
27 26 # vim: set ts=4 sw=4:
... ...
... ... @@ -87,12 +87,12 @@ gather_dist_info() {
87 87 eval ${GREP} -iq ${DIST} \${FILES_${CHK}} || DIST="Unknown"
88 88 fi
89 89
90   - CLASSES="${CLASSES}${DIST} ";;
  90 + set_class ${CLASSES} ${DIST};;
91 91 *)
92 92 DIST="${OS}"
93 93 esac
94 94
95   - export DIST CLASSES
  95 + export DIST
96 96 }
97 97
98 98 # vim: set ts=4 sw=4:
... ...
... ... @@ -10,10 +10,10 @@ gather_host_info() {
10 10 PLATFORM="$(${UNAME} -m)"
11 11 HOSTNAME="$(${UNAME} -n)"
12 12 GNU="$([ "${OS%GNU*}" != ${OS} ] && echo "GNU")"
13   - CLASSES="${OS}\n${GNU}\n${KERNEL}\n${VERSION}\n${PLATFORM}\n${HOSTNAME}"
14   - CLASSES="$(${ECHO} -e "${CLASSES}" | ${SORT} -u | ${TR} "\n" " ")"
15 13
16 14 export OS KERNEL VERSION PLATFORM HOSTNAME CLASSES
  15 +
  16 + set_class ${OS} ${GNU} ${KERNEL} ${VERSION} ${PLATFORM} ${HOSTNAME}
17 17 }
18 18
19 19 # vim: set ts=4 sw=4:
... ...
... ... @@ -22,7 +22,6 @@ gather_interface_info() {
22 22 fi
23 23
24 24 export NINTERFACES
25   - export CLASSES
26 25
27 26 while [ ${NO} -le ${NINTERFACES:=0} ]
28 27 do
... ... @@ -56,7 +55,7 @@ gather_if_info_ip() {
56 55 classes=""
57 56 }
58 57 END {
59   - print "CLASSES=\"${CLASSES}" classes " \";";
  58 + print "set_class " classes ";";
60 59 print "NINTERFACES=" FNR ";"
61 60 }')
62 61
... ... @@ -78,12 +77,13 @@ gather_if_info_ip() {
78 77 classes=""
79 78 }
80 79 END {
81   - print "CLASSES=\"${CLASSES}" classes " \";"
  80 + print "set_class " classes ";"
82 81 }')
83 82 }
84 83
85 84 ##
86 85 # get interface data via the ifconfig tool
  86 +# FIXME This is outdated. It does not set classes at all.
87 87 #
88 88 gather_if_info_ifconfig() {
89 89 eval $(${IFCONFIG} -a | ${AWK} '
... ...
... ... @@ -9,4 +9,18 @@ has_class() {
9 9 test "${CHECK}" != "${CHECK% ${1} *}"
10 10 }
11 11
  12 +##
  13 +# add one or more classes given as arguments to this function
  14 +# Using ${@} here effectively eliminates multiple spaces between
  15 +# the classnames.
  16 +# A class might be defined multiple times...I don't eliminate these
  17 +# duplicates as this might involve calling uniq which is unneccesary
  18 +# overhead as I see no harm in duplicates now.
  19 +#
  20 +set_class() {
  21 + [ -z "${CLASSES}" ] &&
  22 + { CLASSES="${@}"; export CLASSES; } ||
  23 + CLASSES="${CLASSES} ${@}"
  24 +}
  25 +
12 26 # vim: set ts=4 sw=4:
... ...
Please register or login to post a comment