Commit bbbd9408d7d34af2649f571fb2d9569b80a0f696

Authored by Georg Hopp
1 parent afaba612

more sparation and retrieve some informations about the available cpus and their…

… capabilities. If we are on a GNU system this is done via nprocs and on a Linux via lscpu, if we are a GNU/Linux both are used, which is not the best way from a performance point of view, but it show that execution based on my classes works.
... ... @@ -16,7 +16,8 @@ has_class() {
16 16 exit 1
17 17 fi
18 18
19   - test "${CLASSES}" != "${CLASSES%${1}*}"
  19 + local CHECK=" ${CLASSES}"
  20 + test "${CHECK}" != "${CHECK% ${1} *}"
20 21 }
21 22
22 23 # vim: set ts=4 sw=4:
... ...
  1 +#!/bin/dash
  2 +
  3 +. ./utils.sh
  4 +include_once classes.sh
  5 +
  6 +gather_cpu_info() {
  7 + [ -z "${NCPUS}" ] || return
  8 +
  9 + has_class "GNU" && {
  10 + export NCPUS=$(${NPROC})
  11 + }
  12 +
  13 + has_class "Linux" && {
  14 + eval $(${LSCPU} | ${AWK} -F: '
  15 + { sub(/^ */,"",$2) }
  16 + /Byte Order/ {
  17 + sub(/ /,"_",$2);
  18 + print "export BYTE_ORDER=\"" $2 "\";"
  19 + }
  20 + /CPU op-mode/ {
  21 + sub(/,/,"",$2);
  22 + print "export OP_MODES=\"" $2 "\";"
  23 + }
  24 + /CPU(s):/ { print "export NCPUS=" $2 ";" }
  25 + /Virtualization/ { print "export CPU_VIRT=\"" $2 "\";" }')
  26 + }
  27 +
  28 + CLASSES="${CLASSES}${NCPUS}cpus ${CPU_VIRT} ${BYTE_ORDER} ${OP_MODES} "
  29 + CLASSES="$(${ECHO} "${CLASSES}" | "${SED}" 's/ \+/ /g')"
  30 +}
  31 +
  32 +# vim: set ts=4 sw=4:
... ...
  1 +#!/bin/dash
  2 +
  3 +. ./utils.sh
  4 +
  5 +##
  6 +# if we are on a linux try to figure out wich distribution we are
  7 +# running.
  8 +# First look what kind of realease file we have:
  9 +#
  10 +# 00 01 - Novell SuSE ---> /etc/SuSE-release
  11 +# 00 02 - Red Hat ---> /etc/redhat-release, /etc/redhat_version
  12 +# 00 04 - Fedora ---> /etc/fedora-release
  13 +# 00 08 - Slackware ---> /etc/slackware-release, /etc/slackware-version
  14 +# 00 10 - Debian ---> /etc/debian_release, /etc/debian_version
  15 +# 00 20 - Mandrake ---> /etc/mandrake-release
  16 +# 00 40 - Yellow dog ---> /etc/yellowdog-release
  17 +# 00 80 - Sun JDS ---> /etc/sun-release
  18 +# 01 00 - Solaris/Sparc ---> /etc/release
  19 +# 02 00 - Gentoo ---> /etc/gentoo-release
  20 +#
  21 +# Here I follow a pessimistic way because I prefere to have no
  22 +# identification at all over a wrong one...so I check for all these files.
  23 +# If I can't find any or find multiple of them I assume this system
  24 +# as unidentified. Anyway when I found one I still check the content...
  25 +# Here I need some help as I don't know the valid content of these files.
  26 +# For now I assume that at least the name of the distribution is in
  27 +# the file.
  28 +#
  29 +gather_dist_info() {
  30 + [ -z "${DIST}" ] || return
  31 +
  32 + case "${OS}" in
  33 + *Linux*)
  34 + local SUSE=1
  35 + local REDHAT=2
  36 + local FEDORA=4
  37 + local SLACKWARE=8
  38 + local DEBIAN=16
  39 + local MANDRAKE=32
  40 + local YELLOWDOG=64
  41 + local SUNJDS=128
  42 + local GENTOO=256
  43 + local SOLARIS=512
  44 +
  45 + local LAST=${SOLARIS}
  46 +
  47 + local CHK=$((SUSE|REDHAT|FEDORA|SLACKWARE|DEBIAN|MANDRAKE|\
  48 + YELLOWDOG|SUNJDS|GENTOO|SOLARIS))
  49 +
  50 + eval local FILES_${SUSE}=\'/etc/SuSE-release\'
  51 + eval local FILES_${REDHAT}=\'/etc/redhat-release /etc/redhat_version\'
  52 + eval local FILES_${FEDORA}=\'/etc/fedora-release\'
  53 + eval local FILES_${SLACKWARE}=\'/etc/slackware-release /etc/slackware-version\'
  54 + eval local FILES_${DEBIAN}=\'/etc/debian_release /etc/debian_version\'
  55 + eval local FILES_${MANDRAKE}=\'/etc/mandrake-release\'
  56 + eval local FILES_${YELLOWDOG}=\'/etc/yellowdog-release\'
  57 + eval local FILES_${SUNJDS}=\'/etc/sun-release\'
  58 + eval local FILES_${GENTOO}=\'/etc/gentoo-release\'
  59 + eval local FILES_${SOLARIS}=\'/etc/release\'
  60 +
  61 + local CUR=1
  62 + while [ ${CUR} -le ${LAST} ]
  63 + do
  64 + local DIR
  65 +
  66 + eval local FILES=\"\${FILES_${CUR}}\"
  67 +
  68 + for DIR in ${FILES}
  69 + do
  70 + [ -f ${DIR} ] || CHK=$((CHK&~CUR))
  71 + done
  72 +
  73 + CUR=$((CUR*2))
  74 + done
  75 +
  76 + DIST="Unknown"
  77 +
  78 + [ ${CHK} -eq ${SUSE} ] && DIST="Suse"
  79 + [ ${CHK} -eq ${REDHAT} ] && DIST="Redhat"
  80 + [ ${CHK} -eq ${FEDORA} ] && DIST="Fedora"
  81 + [ ${CHK} -eq ${SLACKWARE} ] && DIST="Slakware"
  82 + [ ${CHK} -eq ${DEBIAN} ] && DIST="Debian"
  83 + [ ${CHK} -eq ${MANDRAKE} ] && DIST="Mandrake"
  84 + [ ${CHK} -eq ${YELLOWDOG} ] && DIST="Yellowdog"
  85 + [ ${CHK} -eq ${SUNJDS} ] && DIST="Sun"
  86 + [ ${CHK} -eq ${GENTOO} ] && DIST="Gentoo"
  87 + [ ${CHK} -eq ${SOLARIS} ] && DIST="Solaris"
  88 +
  89 + if [ 'Unknown' != "${DIST}" ]
  90 + then
  91 + eval ${GREP} -iq ${DIST} \${FILES_${CHK}} || DIST="Unknown"
  92 + fi
  93 +
  94 + CLASSES="${CLASSES}${DIST} ";;
  95 + *)
  96 + DIST="${OS}"
  97 + esac
  98 +
  99 + export DIST CLASSES
  100 +}
  101 +
  102 +# vim: set ts=4 sw=4:
... ...
1 1 #!/bin/dash
2 2
3 3 ##
4   -# This creates function that will gather some system informations
5   -# and propagate them as environment variables.
  4 +# The GNU way for more information
6 5 #
7 6
8 7 . ./utils.sh
9   -include_once system_information.sh
10 8
11   -echo "foo ${NPROC}"
12   -CPUS=$(${NPROC})
  9 +gather_gnu_information() {
  10 + export CPUS=$(${NPROC})
13 11
14   -export CLASSES="${CLASSES}${CPUS}cpus "
  12 + export CLASSES="${CLASSES}${CPUS}cpus "
  13 +}
15 14
16 15 # vim: set ts=4 sw=4:
... ...
  1 +#!/bin/dash
  2 +
  3 +. ./utils.sh
  4 +
  5 +##
  6 +# start guessing the system type via uname and export it.
  7 +#
  8 +gather_host_info() {
  9 + [ -z "${OS}" ] || return
  10 +
  11 + OS="$(${UNAME} -o)"
  12 + KERNEL="$(${UNAME} -s)"
  13 + VERSION="$(${UNAME} -r)"
  14 + PLATFORM="$(${UNAME} -m)"
  15 + HOSTNAME="$(${UNAME} -n)"
  16 + GNU="$([ "${OS%GNU*}" != ${OS} ] && echo "GNU")"
  17 + CLASSES="${OS}\n${GNU}\n${KERNEL}\n${VERSION}\n${PLATFORM}\n${HOSTNAME}"
  18 + CLASSES="$(${ECHO} -e "${CLASSES}" | ${SORT} -u | ${TR} "\n" " ")"
  19 +
  20 + export OS KERNEL VERSION PLATFORM HOSTNAME CLASSES
  21 +}
  22 +
  23 +# vim: set ts=4 sw=4:
... ...
... ... @@ -13,16 +13,18 @@
13 13 # how to retrieve this information on other systems.
14 14 # This also exports the environment variables.
15 15 #
16   -get_interface_data() {
  16 +gather_interface_info() {
  17 + [ -z "${NINTERFACES}" ] || return
  18 +
17 19 local NO=1
18 20
19 21 if [ ${IP} ]
20 22 then
21   - get_interface_data_ip
  23 + gather_if_info_ip
22 24 else
23 25 if [ ${IFCONFIG} ]
24 26 then
25   - get_interface_data_ifconfig
  27 + gather_if_info_ifconfig
26 28 else
27 29 ${LOGGER} -p local0.warn 'Found no way to retrieve interface information.'
28 30 fi
... ... @@ -41,7 +43,7 @@ get_interface_data() {
41 43 ##
42 44 # get the interface information from the ip tool
43 45 #
44   -get_interface_data_ip() {
  46 +gather_if_info_ip() {
45 47 eval $(${IP} -o link | ${AWK} '{
46 48 sub(/:/,"",$1);
47 49 no=$1;
... ... @@ -92,7 +94,7 @@ get_interface_data_ip() {
92 94 ##
93 95 # get interface data via the ifconfig tool
94 96 #
95   -get_interface_data_ifconfig() {
  97 +gather_if_info_ifconfig() {
96 98 eval $(${IFCONFIG} -a | ${AWK} '
97 99 /ether/ { mac=$2 }
98 100 /inet / { ipv4=ipv4 $2 " " }
... ... @@ -121,10 +123,4 @@ get_interface_data_ifconfig() {
121 123 }')
122 124 }
123 125
124   -##
125   -# autorun this if sourced.
126   -#
127   -
128   -[ -z "${NINTERFACES}" ] && get_interface_data
129   -
130 126 # vim: set ts=4 sw=4:
... ...
... ... @@ -10,10 +10,12 @@
10 10 #
11 11
12 12 . ./utils.sh
  13 +
13 14 include_once system_information.sh
14   -include_once interface_information.sh
15 15 include_once network_tools.sh
16 16
  17 +gather_information
  18 +
17 19 ##
18 20 # report everysthing
19 21 #
... ... @@ -24,7 +26,10 @@ ${PRINTF} "%15s : %s\n" "VERSION" "${VERSION}"
24 26 ${PRINTF} "%15s : %s\n" "PLATFORM" "${PLATFORM}"
25 27 ${PRINTF} "%15s : %s\n" "DIST" "${DIST}"
26 28 ${PRINTF} "%15s : %s\n" "HOSTNAME" "${HOSTNAME}"
27   -${PRINTF} "%15s : %s\n" "CPUS" "${CPUS}"
  29 +${PRINTF} "%15s : %s\n" "# CPUS" "${NCPUS}"
  30 +${PRINTF} "%15s : %s\n" "BYTE_ORDER" "${BYTE_ORDER}"
  31 +${PRINTF} "%15s : %s\n" "OP_MODES" "${OP_MODES}"
  32 +${PRINTF} "%15s : %s\n" "CPU_VIRT" "${CPU_VIRT}"
28 33 ${PRINTF} "%15s : %s\n" "# INTERFACES" "${NINTERFACES}"
29 34
30 35 NO=1
... ...
1 1 #!/bin/dash
2 2
3   -##
4   -# This creates function that will gather some system informations
5   -# and propagate them as environment variables.
6   -#
7   -
8 3 . ./utils.sh
9 4
10   -##
11   -# start guessing the system type via uname and export it.
12   -#
13   -get_host_info() {
14   - OS="$(${UNAME} -o)"
15   - KERNEL="$(${UNAME} -s)"
16   - VERSION="$(${UNAME} -r)"
17   - PLATFORM="$(${UNAME} -m)"
18   - HOSTNAME="$(${UNAME} -n)"
19   - CLASSES="$(${ECHO} -e "${OS}\n${KERNEL}\n${VERSION}\n${PLATFORM}\n${HOSTNAME}" |\
20   - ${SORT} -u | ${TR} "\n" " ")"
  5 +include_once host_information.sh
  6 +include_once dist_information.sh
  7 +include_once cpu_information.sh
  8 +include_once interface_information.sh
21 9
22   - export OS KERNEL VERSION PLATFORM HOSTNAME CLASSES
  10 +gather_information() {
  11 + gather_host_info
  12 + gather_dist_info
  13 + gather_cpu_info
  14 + gather_interface_info
23 15 }
24 16
25   -##
26   -# if we are on a linux try to figure out wich distribution we are
27   -# running.
28   -# First look what kind of realease file we have:
29   -#
30   -# 00 01 - Novell SuSE ---> /etc/SuSE-release
31   -# 00 02 - Red Hat ---> /etc/redhat-release, /etc/redhat_version
32   -# 00 04 - Fedora ---> /etc/fedora-release
33   -# 00 08 - Slackware ---> /etc/slackware-release, /etc/slackware-version
34   -# 00 10 - Debian ---> /etc/debian_release, /etc/debian_version
35   -# 00 20 - Mandrake ---> /etc/mandrake-release
36   -# 00 40 - Yellow dog ---> /etc/yellowdog-release
37   -# 00 80 - Sun JDS ---> /etc/sun-release
38   -# 01 00 - Solaris/Sparc ---> /etc/release
39   -# 02 00 - Gentoo ---> /etc/gentoo-release
40   -#
41   -# Here I follow a pessimistic way because I prefere to have no
42   -# identification at all over a wrong one...so I check for all these files.
43   -# If I can't find any or find multiple of them I assume this system
44   -# as unidentified. Anyway when I found one I still check the content...
45   -# Here I need some help as I don't know the valid content of these files.
46   -# For now I assume that at least the name of the distribution is in
47   -# the file.
48   -#
49   -get_dist_info() {
50   - [ -z "${KERNEL}" ] && get_host_info
51   -
52   - if [ "Linux" = "${KERNEL}" ]
53   - then
54   - local SUSE=1
55   - local REDHAT=2
56   - local FEDORA=4
57   - local SLACKWARE=8
58   - local DEBIAN=16
59   - local MANDRAKE=32
60   - local YELLOWDOG=64
61   - local SUNJDS=128
62   - local GENTOO=256
63   - local SOLARIS=512
64   -
65   - local LAST=${SOLARIS}
66   -
67   - local CHK=$((SUSE|REDHAT|FEDORA|SLACKWARE|DEBIAN|MANDRAKE|\
68   - YELLOWDOG|SUNJDS|GENTOO|SOLARIS))
69   -
70   - eval local FILES_${SUSE}=\'/etc/SuSE-release\'
71   - eval local FILES_${REDHAT}=\'/etc/redhat-release /etc/redhat_version\'
72   - eval local FILES_${FEDORA}=\'/etc/fedora-release\'
73   - eval local FILES_${SLACKWARE}=\'/etc/slackware-release /etc/slackware-version\'
74   - eval local FILES_${DEBIAN}=\'/etc/debian_release /etc/debian_version\'
75   - eval local FILES_${MANDRAKE}=\'/etc/mandrake-release\'
76   - eval local FILES_${YELLOWDOG}=\'/etc/yellowdog-release\'
77   - eval local FILES_${SUNJDS}=\'/etc/sun-release\'
78   - eval local FILES_${GENTOO}=\'/etc/gentoo-release\'
79   - eval local FILES_${SOLARIS}=\'/etc/release\'
80   -
81   - local CUR=1
82   - while [ ${CUR} -le ${LAST} ]
83   - do
84   - local DIR
85   -
86   - eval local FILES=\"\${FILES_${CUR}}\"
87   -
88   - for DIR in ${FILES}
89   - do
90   - [ -f ${DIR} ] || CHK=$((CHK&~CUR))
91   - done
92   -
93   - CUR=$((CUR*2))
94   - done
95   -
96   - DIST="Unknown"
97   -
98   - [ ${CHK} -eq ${SUSE} ] && DIST="Suse"
99   - [ ${CHK} -eq ${REDHAT} ] && DIST="Redhat"
100   - [ ${CHK} -eq ${FEDORA} ] && DIST="Fedora"
101   - [ ${CHK} -eq ${SLACKWARE} ] && DIST="Slakware"
102   - [ ${CHK} -eq ${DEBIAN} ] && DIST="Debian"
103   - [ ${CHK} -eq ${MANDRAKE} ] && DIST="Mandrake"
104   - [ ${CHK} -eq ${YELLOWDOG} ] && DIST="Yellowdog"
105   - [ ${CHK} -eq ${SUNJDS} ] && DIST="Sun"
106   - [ ${CHK} -eq ${GENTOO} ] && DIST="Gentoo"
107   - [ ${CHK} -eq ${SOLARIS} ] && DIST="Solaris"
108   -
109   - if [ 'Unknown' != "${DIST}" ]
110   - then
111   - eval ${GREP} -iq ${DIST} \${FILES_${CHK}} || DIST="Unknown"
112   - fi
113   -
114   - CLASSES="${CLASSES}${DIST} "
115   - else
116   - DIST="${OS}"
117   - fi
118   -
119   - export DIST CLASSES
120   -}
121   -
122   -##
123   -# autorun this if sourced.
124   -#
125   -
126   -[ -z "${DIST}" ] && get_dist_info
127   -
128   -case "${OS}" in
129   - GNU/*)
130   - include_once gnu_information.sh;;
131   -esac
132   -
133 17 # vim: set ts=4 sw=4:
... ...
... ... @@ -88,16 +88,18 @@ then
88 88 [ -z "${UNAME}" ] && UNAME="$(${WHICH} uname)"
89 89 [ -z "${GREP}" ] && GREP="$(${WHICH} grep)"
90 90 [ -z "${AWK}" ] && AWK="$(${WHICH} awk)"
  91 + [ -z "${SED}" ] && SED="$(${WHICH} sed)"
91 92 [ -z "${ECHO}" ] && ECHO="$(${WHICH} echo)"
92 93 [ -z "${SORT}" ] && SORT="$(${WHICH} sort)"
93 94 [ -z "${TR}" ] && TR="$(${WHICH} tr)"
94 95 [ -z "${PRINTF}" ] && PRINTF="$(${WHICH} printf)"
95 96 [ -z "${LOGGER}" ] && LOGGER="$(${WHICH} logger)"
96 97 [ -z "${NPROC}" ] && NPROC="$(${WHICH} nproc)"
  98 + [ -z "${LSCPU}" ] && LSCPU="$(${WHICH} lscpu)"
97 99 [ -z "${IP}" ] && IP="$(${WHICH} ip)"
98 100 [ -z "${IFCONFIG}" ] && IFCONFIG="$(${WHICH} ifconfig)"
99 101
100   - export WHICH UNAME GREP AWK ECHO SORT TR PRINTF LOGGER IP IFCONFIG
  102 + export WHICH UNAME GREP AWK SED ECHO SORT TR PRINTF LOGGER NPROC LSCPU IP IFCONFIG
101 103 fi
102 104
103 105 # vim: set ts=4 sw=4:
... ...
Please register or login to post a comment