diff --git a/classes.sh b/classes.sh deleted file mode 100755 index d48bb74..0000000 --- a/classes.sh +++ /dev/null @@ -1,23 +0,0 @@ -#!/bin/dash - -## -# This creates function that will gather some system informations -# and propagate them as environment variables. -# - -. ./utils.sh -include_once system_information.sh -include_once interface_information.sh - -has_class() { - if [ 1 -ne $# ] - then - logger -p syslog.err 'has_class: no class given' - exit 1 - fi - - local CHECK=" ${CLASSES}" - test "${CHECK}" != "${CHECK% ${1} *}" -} - -# vim: set ts=4 sw=4: diff --git a/cpu_information.sh b/gatherer/cpu_information.sh old mode 100755 new mode 100644 similarity index 92% rename from cpu_information.sh rename to gatherer/cpu_information.sh index ab59c96..77435c6 --- a/cpu_information.sh +++ b/gatherer/cpu_information.sh @@ -1,8 +1,3 @@ -#!/bin/dash - -. ./utils.sh -include_once classes.sh - gather_cpu_info() { [ -z "${NCPUS}" ] || return diff --git a/dist_information.sh b/gatherer/dist_information.sh old mode 100755 new mode 100644 similarity index 99% rename from dist_information.sh rename to gatherer/dist_information.sh index bb2c534..94c253b --- a/dist_information.sh +++ b/gatherer/dist_information.sh @@ -1,7 +1,3 @@ -#!/bin/dash - -. ./utils.sh - ## # if we are on a linux try to figure out wich distribution we are # running. diff --git a/host_information.sh b/gatherer/host_information.sh old mode 100755 new mode 100644 similarity index 94% rename from host_information.sh rename to gatherer/host_information.sh index 2d02940..27193f4 --- a/host_information.sh +++ b/gatherer/host_information.sh @@ -1,7 +1,3 @@ -#!/bin/dash - -. ./utils.sh - ## # start guessing the system type via uname and export it. # diff --git a/interface_information.sh b/gatherer/interface_information.sh old mode 100755 new mode 100644 similarity index 94% rename from interface_information.sh rename to gatherer/interface_information.sh index 007ea91..e251df1 --- a/interface_information.sh +++ b/gatherer/interface_information.sh @@ -1,12 +1,3 @@ -#!/bin/dash - -## -# This creates function that will gather some system informations -# and propagate them as environment variables. -# - -. ./utils.sh - ## # retrieve interfaces. I prefer using ip if it is # available, else I fallback to ifconfig... don't know diff --git a/gatherer/system_information.sh b/gatherer/system_information.sh new file mode 100644 index 0000000..1dcb84e --- /dev/null +++ b/gatherer/system_information.sh @@ -0,0 +1,17 @@ +. utils/file.sh + +include_once utils/programs.sh +include_once utils/classes.sh +include_once gatherer/host_information.sh +include_once gatherer/dist_information.sh +include_once gatherer/cpu_information.sh +include_once gatherer/interface_information.sh + +gather_information() { + gather_host_info + gather_dist_info + gather_cpu_info + gather_interface_info +} + +# vim: set ts=4 sw=4: diff --git a/cf-engine-classes.txt b/notes/cf-engine-classes.txt similarity index 100% rename from cf-engine-classes.txt rename to notes/cf-engine-classes.txt diff --git a/run.sh b/run.sh index 295013e..ba51783 100755 --- a/run.sh +++ b/run.sh @@ -9,10 +9,10 @@ # flavours and maybe FreeBSD. # -. ./utils.sh +. utils/file.sh -include_once system_information.sh -include_once network_tools.sh +include_once gatherer/system_information.sh +include_once utils/network_tools.sh gather_information diff --git a/system_information.sh b/system_information.sh deleted file mode 100755 index 61760c2..0000000 --- a/system_information.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/dash - -. ./utils.sh - -include_once host_information.sh -include_once dist_information.sh -include_once cpu_information.sh -include_once interface_information.sh - -gather_information() { - gather_host_info - gather_dist_info - gather_cpu_info - gather_interface_info -} - -# vim: set ts=4 sw=4: diff --git a/utils/classes.sh b/utils/classes.sh new file mode 100644 index 0000000..cbda742 --- /dev/null +++ b/utils/classes.sh @@ -0,0 +1,12 @@ +has_class() { + if [ 1 -ne $# ] + then + logger -p syslog.err 'has_class: no class given' + exit 1 + fi + + local CHECK=" ${CLASSES}" + test "${CHECK}" != "${CHECK% ${1} *}" +} + +# vim: set ts=4 sw=4: diff --git a/utils.sh b/utils/file.sh old mode 100755 new mode 100644 similarity index 55% rename from utils.sh rename to utils/file.sh index 84a2e6f..031c3f9 --- a/utils.sh +++ b/utils/file.sh @@ -1,9 +1,8 @@ -#!/bin/dash - ## -# make definitions only when not already defined +# some functions for file handling...this includes a kind of +# include_once for shell scripts. This one also includes the +# utils/program.sh file as it is needed in all scripts. # - command -v filename2symbol >/dev/null if [ $? -ne 0 ] then @@ -77,29 +76,7 @@ then fi } - ## - # get and export the locations of used programs and export them - # I assume that on every UNIX/shell variant at least [ is globally - # available. I will use it throughout all other scripts without - # checking for existence. - # I also assume through all scripts that eval is available. - # - [ -z "${WHICH}" ] && WHICH="/usr/bin/which" - [ -z "${UNAME}" ] && UNAME="$(${WHICH} uname)" - [ -z "${GREP}" ] && GREP="$(${WHICH} grep)" - [ -z "${AWK}" ] && AWK="$(${WHICH} awk)" - [ -z "${SED}" ] && SED="$(${WHICH} sed)" - [ -z "${ECHO}" ] && ECHO="$(${WHICH} echo)" - [ -z "${SORT}" ] && SORT="$(${WHICH} sort)" - [ -z "${TR}" ] && TR="$(${WHICH} tr)" - [ -z "${PRINTF}" ] && PRINTF="$(${WHICH} printf)" - [ -z "${LOGGER}" ] && LOGGER="$(${WHICH} logger)" - [ -z "${NPROC}" ] && NPROC="$(${WHICH} nproc)" - [ -z "${LSCPU}" ] && LSCPU="$(${WHICH} lscpu)" - [ -z "${IP}" ] && IP="$(${WHICH} ip)" - [ -z "${IFCONFIG}" ] && IFCONFIG="$(${WHICH} ifconfig)" - - export WHICH UNAME GREP AWK SED ECHO SORT TR PRINTF LOGGER NPROC LSCPU IP IFCONFIG + include_once utils/programs.sh fi # vim: set ts=4 sw=4: diff --git a/network_tools.sh b/utils/network_tools.sh similarity index 97% rename from network_tools.sh rename to utils/network_tools.sh index 0d71cab..ba47520 100755 --- a/network_tools.sh +++ b/utils/network_tools.sh @@ -1,6 +1,4 @@ -#!/bin/dash - -. ./utils.sh +. utils/file.sh ## # Function calculates number of bit in a netmask diff --git a/utils/programs.sh b/utils/programs.sh new file mode 100644 index 0000000..60fe0e2 --- /dev/null +++ b/utils/programs.sh @@ -0,0 +1,25 @@ +## +# get and export the locations of used programs and export them +# I assume that on every UNIX/shell variant at least [ is globally +# available. I will use it throughout all other scripts without +# checking for existence. +# I also assume through all scripts that eval is available. +# +[ -z "${WHICH}" ] && WHICH="/usr/bin/which" +[ -z "${UNAME}" ] && UNAME="$(${WHICH} uname)" +[ -z "${GREP}" ] && GREP="$(${WHICH} grep)" +[ -z "${AWK}" ] && AWK="$(${WHICH} awk)" +[ -z "${SED}" ] && SED="$(${WHICH} sed)" +[ -z "${ECHO}" ] && ECHO="$(${WHICH} echo)" +[ -z "${SORT}" ] && SORT="$(${WHICH} sort)" +[ -z "${TR}" ] && TR="$(${WHICH} tr)" +[ -z "${PRINTF}" ] && PRINTF="$(${WHICH} printf)" +[ -z "${LOGGER}" ] && LOGGER="$(${WHICH} logger)" +[ -z "${NPROC}" ] && NPROC="$(${WHICH} nproc)" +[ -z "${LSCPU}" ] && LSCPU="$(${WHICH} lscpu)" +[ -z "${IP}" ] && IP="$(${WHICH} ip)" +[ -z "${IFCONFIG}" ] && IFCONFIG="$(${WHICH} ifconfig)" + +export WHICH UNAME GREP AWK SED ECHO SORT TR PRINTF LOGGER NPROC LSCPU IP IFCONFIG + +# vim: set ts=4 sw=4: