summaryrefslogtreecommitdiff
path: root/sysinfogen.sh
diff options
context:
space:
mode:
authorHaru <haru@dotalux.com>2013-10-18 13:21:34 +0200
committerHaru <haru@dotalux.com>2014-04-17 06:09:49 +0200
commit7b12dd06420fae973fbcc2f81f5d385e59788c78 (patch)
tree5bad1c4f2e44f5d4b49c82fafdd46177d15b9b97 /sysinfogen.sh
parent8a84d46a19b0112b7e2417728b8816e8b34b7383 (diff)
downloadhercules-7b12dd06420fae973fbcc2f81f5d385e59788c78.tar.gz
hercules-7b12dd06420fae973fbcc2f81f5d385e59788c78.tar.bz2
hercules-7b12dd06420fae973fbcc2f81f5d385e59788c78.tar.xz
hercules-7b12dd06420fae973fbcc2f81f5d385e59788c78.zip
Added sysinfo (System Information) functionalities
- More informative messages are displayed during startup, to make it easier to identify what system and environment Hercules is running. - Git/SVN revision detection is improved, separating the source version (cached at compile time) from the runtime version, in case the user updated their working copy without recompiling the server. Git version detection is also more reliable, in case a non-default branch is used. - The get_revision script command has been removed (as it was useless to begin with, after the switch to git). An alternative will be provided later, for feature-probing purposes. - The patch was tested under Linux (Gentoo / gcc 4.7 on i686 and x86_64, Debian 6 / gcc 4.4 on i686, Raspbian / gcc 4.6 on armv6l, CentOS 5 / gcc 4.1 on i686, CentOS 6 / gcc 4.4 on x86_64, Linux Mint 15 / gcc 4.7 on x86_64, OS X Mountain Lion / clang 5.0 and gcc 4.8 on x86_64, Cygwin-NT-5.1/gcc 4.8 on i686, FreeBSD 8 / gcc 4.2 on i386, FreeBSD 9 / gcc 4.2 on amd64, FreeBSD 10 / clang 3.3 on amd64, NetBSD 5 / gcc 4.1 on i386, NetBSD 6 / gcc 4.5 on amd64, OpenBSD 5 / gcc 4.2 on amd64, Solaris 11 / gcc 4.5 on i86pc, Windows 7 / Visual Studio 2012 on x86, Windows 8 / Visual Studio 2010 on WOW64, Windows 8.1 / Visual Studio 2013 on WOW64. Signed-off-by: Haru <haru@dotalux.com>
Diffstat (limited to 'sysinfogen.sh')
-rwxr-xr-xsysinfogen.sh259
1 files changed, 259 insertions, 0 deletions
diff --git a/sysinfogen.sh b/sysinfogen.sh
new file mode 100755
index 000000000..89857249f
--- /dev/null
+++ b/sysinfogen.sh
@@ -0,0 +1,259 @@
+#!/bin/sh
+
+# Copyright (c) Hercules Dev Team, licensed under GNU GPL.
+# See the LICENSE file
+# Base Author: Haru @ http://hercules.ws
+
+do_fail() {
+ echo 'Error writing output file'
+ exit 1
+}
+
+cleanstring() {
+ if [ "$( echo "x x" | sed -e 's/[[:space:]]//g' )" = "x x" ]; then
+ # Workaround for non-POSIX-compliant systems that lack [[:space:]] (Solaris)
+ echo "$@" | sed -e 's/"/ /g' -e 's/[ ][ ]*/ /g' -e 's/^[ ]*//g' -e 's/[ ]*$//g'
+ else
+ echo "$@" | sed -e 's/"/ /g' -e 's/[[:space:]][[:space:]]*/ /g' -e 's/^[[:space:]]*//g' -e 's/[[:space:]]*$//g'
+ fi
+}
+
+if [ -z "$1" ]; then
+ echo 'No output file specified'
+ exit 1
+fi
+
+OUTFILE="$1"
+shift
+
+if ! touch "$OUTFILE"; then
+ echo 'Cannot create output file'
+ exit 1
+fi
+
+cat > "$OUTFILE" << EOF
+// Copyright (c) Hercules Dev Team, licensed under GNU GPL.
+// See the LICENSE file
+
+// This file was automatically generated. Any edit to it will be lost.
+
+EOF
+[ $? -eq 0 ] || do_fail
+
+HERC_PLATFORM="$( uname -s )"
+HERC_CORES="0"
+HERC_CPU="Unknown"
+
+case $HERC_PLATFORM in
+ Linux)
+ DIST=''
+ DESCRIPTION=''
+ REV=''
+
+ if type lsb_release >/dev/null 2>&1; then
+ LSBINFO="$( lsb_release -a 2>/dev/null )"
+ DIST="$( cleanstring "$( echo "$LSBINFO" | grep '^Distributor ID:' | cut -d: -f2- )" )"
+ DESCRIPTION="$( echo "$LSBINFO" | grep '^Description:' | cut -d: -f2- | sed 's/Enterprise Linux Enterprise Linux/Oracle Linux/' )"
+ fi
+
+ if [ -z "$DIST" ] || [ "$DIST" = "Gentoo" ]; then
+ if [ -f /etc/gentoo-release ]; then
+ # "Gentoo Base System release 2.2"
+ DIST='Gentoo'
+ DESCRIPTION="$( head -n 1 /etc/gentoo-release )"
+ REV=''
+ elif [ -f /etc/arch-release ]; then
+ # empty release file
+ DIST='ArchLinux'
+ DESCRIPTION=''
+ REV=''
+ elif [ -f /etc/vmware-release ]; then
+ # "VMware ESX Server 3" or "VMware ESX 4.0 (Kandinsky)"
+ DIST="VMWare"
+ DESCRIPTION="$( head -n 1 /etc/vmware-release )"
+ REV=''
+ elif [ -f /etc/debian_version ]; then
+ # "wheezy/sid"
+ DIST="Debian"
+ DESCRIPTION="Debian GNU/Linux $( head -n 1 /etc/debian_version )"
+ REV=''
+ elif [ -f /etc/fedora-release ]; then
+ # "Fedora release 9 (Sulphur)"
+ DIST="Fedora"
+ DESCRIPTION="$( head -n 1 /etc/fedora-release )"
+ REV=''
+ elif [ -f /etc/knoppix_version ]; then
+ # "3.2 2003-04-15"
+ DIST="Knoppix"
+ REV="Knoppix GNU/Linux $( head -n 1 /etc/knoppix_version )"
+ DESCRIPTION=''
+ elif [ -f /etc/mandriva-release ]; then
+ # "Mandriva Linux release 2010.1 (Official) for x86_64"
+ DIST="Mandriva"
+ DESCRIPTION="$( head -n 1 /etc/mandriva-release )"
+ REV=''
+ elif [ -f /etc/mandrake-release ]; then
+ # "Mandrakelinux release 10.1 (Community) for i586"
+ DIST="Mandrake"
+ DESCRIPTION="$( head -n 1 /etc/mandrake-release )"
+ REV=''
+ elif [ -f /etc/oracle-release ]; then
+ # "Oracle Linux Server release 6.3"
+ DIST="Oracle"
+ DESCRIPTION="$( head -n 1 /etc/oracle-release )"
+ REV=''
+ elif [ -f /etc/centos-release ]; then
+ # "CentOS Linux release 6.0 (Final)"
+ DIST="CentOS"
+ DESCRIPTION="$( head -n 1 /etc/centos-release )"
+ REV=''
+ elif [ -f /etc/redhat-release ]; then
+ # "Red Hat Enterprise Linux Server release 5 (Tikanga)"
+ DIST="RedHat"
+ DESCRIPTION="$( head -n 1 /etc/redhat-release )"
+ REV=''
+ elif [ -f /etc/slackware-version ]; then
+ DIST="Slackware"
+ DESCRIPTION="$( head -n 1 /etc/slackware-version )"
+ REV=''
+ elif [ -f /etc/slackware-release ]; then
+ DIST="Slackware"
+ DESCRIPTION="$( head -n 1 /etc/slackware-release )"
+ REV=''
+ elif [ -f /etc/SuSE-release ]; then
+ # "SUSE Linux Enterprise Server 11 (x86_64)"
+ # Note: it may contain several extra lines
+ DIST="SuSE"
+ DESCRIPTION="$( head -n 1 /etc/SuSE-release )"
+ REV=''
+ elif [ -f /etc/trustix-release ]; then
+ # "Trustix Secure Linux release 2.0 (Cloud)"
+ DIST="Trustix"
+ DESCRIPTION="$( head -n 1 /etc/trustix-release )"
+ REV=''
+ else
+ DIST='Unknown'
+ DESCRIPTION=''
+ REV=''
+ fi
+ fi
+ if [ -n "$DESCRIPTION" ]; then
+ DIST="$DESCRIPTION"
+ fi
+ HERC_OSVERSION="$DIST"
+
+ HERC_CPU="$( cat /proc/cpuinfo | grep "model name" | head -n 1 | cut -d: -f2- )"
+ HERC_CORES="$( grep '^processor' /proc/cpuinfo | wc -l )"
+ ;;
+ Darwin)
+ HERC_PLATFORM="Mac OS X"
+ if type sw_vers >/dev/null 2>&1; then
+ HERC_OSVERSION="$( sw_vers -productName ) $( sw_vers -productVersion ) $( sw_vers -buildVersion )"
+ else
+ HERC_OSVERSION="Unknown"
+ fi
+ if type system_profiler >/dev/null 2>&1; then
+ HWDATA="$( system_profiler SPHardwareDataType )"
+ HWDATA_CPU="$( echo "$HWDATA" | grep "Processor Name:" | cut -d: -f2- )"
+ HWDATA_CPUSPEED="$( cleanstring "$( echo "$HWDATA" | grep "Processor Speed:" | cut -d: -f2- )" )"
+ HERC_CORES="$( echo "$HWDATA" | grep "Total Number of Cores:" | cut -d: -f2- )"
+ HERC_CPU="${HWDATA_CPU} (${HWDATA_CPUSPEED})"
+ fi
+ ;;
+ SunOS)
+ HERC_PLATFORM="Solaris"
+ HERC_OSVERSION="${HERC_PLATFORM} $( uname -r ) ($( uname -p) $(uname -v))"
+ ;;
+ AIX)
+ HERC_OSVERSION="AIX $( oslevel ) ($(`oslevel -r`))"
+ ;;
+ CYGWIN*)
+ HERC_PLATFORM="Cygwin Windows"
+ HERC_OSVERSION="$( cleanstring "$( uname -s )" )"
+ HERC_CPU="$( cat /proc/cpuinfo | grep "model name" | head -n 1 | cut -d: -f2- )"
+ HERC_CORES="$( grep '^processor' /proc/cpuinfo | wc -l )"
+ ;;
+ OpenBSD)
+ HERC_OSVERSION="${HERC_PLATFORM} $( uname -r ) ($( uname -p) $(uname -v))"
+ HERC_CPU="$( sysctl hw.model | cut -d= -f2- )"
+ HERC_CORES="$( sysctl hw.ncpu | cut -d= -f2- )"
+ ;;
+ FreeBSD)
+ HERC_OSVERSION="${HERC_PLATFORM} $( uname -r ) ($( uname -p))"
+ HERC_CPU="$( sysctl hw.model | cut -d: -f2- )"
+ HERC_CORES="$( sysctl hw.ncpu | cut -d: -f2- )"
+ ;;
+ NetBSD)
+ HERC_OSVERSION="${HERC_PLATFORM} $( uname -r ) ($( uname -p))"
+ HERC_CPU="$( sysctl hw.model | cut -d= -f2- )"
+ HERC_CORES="$( sysctl hw.ncpu | cut -d= -f2- )"
+ ;;
+ *)
+ HERC_OSVERSION="Unknown"
+ ;;
+esac
+
+cat >> "$OUTFILE" << EOF
+// Platform (uname -s)
+#define SYSINFO_PLATFORM "$( cleanstring "${HERC_PLATFORM}" )"
+
+// Operating System version (Platform-dependent)
+#define SYSINFO_OSVERSION "$( cleanstring "${HERC_OSVERSION}" )"
+
+// CPU Model (Platform-dependent)
+#define SYSINFO_CPU "$( cleanstring "${HERC_CPU}" )"
+
+// CPU Cores (Platform-dependent)
+#define SYSINFO_CPUCORES ( $( cleanstring "${HERC_CORES}" ) )
+
+EOF
+[ $? -eq 0 ] || do_fail
+
+HERC_ARCH="$( uname -m )"
+
+cat >> "$OUTFILE" << EOF
+// OS Architecture (uname -m)
+#define SYSINFO_ARCH "$( cleanstring "${HERC_ARCH}" )"
+
+EOF
+[ $? -eq 0 ] || do_fail
+
+HERC_CFLAGS="$@"
+HERC_CFLAGS="$( echo "${HERC_CFLAGS}" | sed 's/"//g' )"
+
+cat >> "$OUTFILE" << EOF
+// Compiler Flags
+#define SYSINFO_CFLAGS "$( cleanstring "${HERC_CFLAGS}" )"
+
+EOF
+[ $? -eq 0 ] || do_fail
+
+HERC_VCSREV=""
+if [ -d .git ]; then
+ HERC_VCSTYPE="VCSTYPE_GIT"
+ if type git >/dev/null 2>&1; then
+ HERC_VCSREV="$( git rev-parse HEAD )"
+ else
+ HERC_VCSREV="Unknown"
+ fi
+elif [ -d .svn ]; then
+ HERC_VCSTYPE="VCSTYPE_SVN"
+ if type svnversion >/dev/null 2>&1; then
+ HERC_VCSREV="$( svnversion )"
+ else
+ HERC_VCSREV="Unknown"
+ fi
+else
+ HERC_VCSTYPE="VCSTYPE_NONE"
+fi
+
+cat >> "$OUTFILE" << EOF
+// VCS Type
+#define SYSINFO_VCSTYPE ${HERC_VCSTYPE}
+
+// VCS Revision
+#define SYSINFO_VCSREV "$( cleanstring "${HERC_VCSREV}" )"
+
+EOF
+[ $? -eq 0 ] || do_fail
+