├── README.md ├── LICENSE └── distro /README.md: -------------------------------------------------------------------------------- 1 | distroscript 2 | ============ 3 | 4 | Simple shell script to return os/distro info 5 | 6 | Fixes/Updates: pull request or joe@rewt.org.uk - cheers 7 | 8 | 9 | Wanted 10 | ====== 11 | 12 | Obviously to implement good support for all platforms I require at least uname outputs and/or any OS specific checks I can do, currently I need info for: 13 | 14 | * AIX 15 | * HP-UX 16 | * VxWorks 17 | * RTOS/QNX 18 | 19 | Versioning 20 | ======== 21 | 22 | Generally after every commit, or at least after a couple of moderate commits, I increment the version. 23 | 24 | When there are significant milestones I will likely create "releases" where the script as of release is bug free. 25 | 26 | * master - use if you are brave, potential for disruptive changes. 27 | * stable - only changes that I think are worthwhile and won't break compatibility. 28 | 29 | 30 | Usage 31 | ===== 32 | 33 | You can either include the script in your own application or execute it directly. 34 | Before sourcing the script, set $DISTROEXEC. 35 | 36 | No dependencies, should work on anything ash compatible (ksh, bash etc) 37 | 38 | Variables: 39 | * $OS - Operating System (eg Linux, Solaris, FreeBSD) 40 | * $KERNEL - Kernel version (eg 3.8.1 or 9.1-RELEASE) 41 | * $ARCH - platform/bitness (eg amd64 or i386) 42 | * $DISTRO - Distribution if any (eg Debian, OpenIndiana, pfSense) 43 | * $DISTROVER - Distribution version if any (eg 12.04, 6.3) 44 | * $DISTROSCRIPT - Version of the script 45 | 46 | If information isn't available or applicable for any of the variables, they are left blank. 47 | 48 | Functions: 49 | * getos - exports OS as the Operating System 50 | * getkernel - exports KERNEL as the kernel version 51 | * getarch - exports ARCH as the arch/platform 52 | * getdistro - exports DISTRO as the distribution 53 | * getversion - exports VERSION as the distribution version 54 | 55 | Notes: 56 | * On FreeBSD and OpenBSD, where it is a generic install, the distro field is left blank and the distrover is populated with the kernel name. 57 | * x86_64 is normalised to amd64 on Linux. 58 | 59 | Output: 60 | * Default output is pipe deliminated: OS|KERNEL|ARCH|DISTRO|DISTROVER 61 | * Possible output options are: pipe, ini, export 62 | * Set DISTROFORMAT environment variable to change output. 63 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Observium License Version 1.0 2 | 3 | Copyright (c) 2013 Joe Holden 4 | 5 | The intent of this license is to establish the freedom to use, share and contribute to 6 | the software regulated by this license. 7 | 8 | This license applies to any software containing a notice placed by the copyright holder 9 | saying that it may be distributed under the terms of this license. Such software is herein 10 | referred to as the Software. This license covers modification and distribution of the 11 | Software. 12 | 13 | Granted Rights 14 | 15 | 1. You are granted the non-exclusive rights set forth in this license provided you agree to 16 | and comply with any and all conditions in this license. Whole or partial distribution of the 17 | Software, or software items that link with the Software, in any form signifies acceptance of 18 | this license. 19 | 20 | 2. You may copy and distribute the Software in unmodified form provided that the entire package, 21 | including - but not restricted to - copyright, trademark notices and disclaimers, as released 22 | by the initial developer of the Software, is distributed. 23 | 24 | 3. You may make modifications to the Software and distribute your modifications, in a form that 25 | is separate from the Software, such as patches. The following restrictions apply to modifications: 26 | 27 | a. Modifications must not alter or remove any copyright notices in the Software. 28 | b. When modifications to the Software are released under this license, a non-exclusive royalty-free 29 | right is granted to the initial developer of the Software to distribute your modification in 30 | future versions of the Software provided such versions remain available under these terms in 31 | addition to any other license(s) of the initial developer. 32 | 33 | Limitations of Liability 34 | 35 | In no event shall the initial developers or copyright holders be liable for any damages whatsoever, 36 | including - but not restricted to - lost revenue or profits or other direct, indirect, special, 37 | incidental or consequential damages, even if they have been advised of the possibility of such damages, 38 | except to the extent invariable law, if any, provides otherwise. 39 | 40 | No Warranty 41 | 42 | The Software and this license document are provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 43 | WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 44 | 45 | URL: https://github.com/joeholden/distroscript/ 46 | README: https://raw.github.com/joeholden/distroscript/master/README.md 47 | 48 | -------------------------------------------------------------------------------- /distro: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Observium License Version 1.0 3 | # 4 | # Copyright (c) 2013 Joe Holden 5 | # 6 | # The intent of this license is to establish the freedom to use, share and contribute to 7 | # the software regulated by this license. 8 | # 9 | # This license applies to any software containing a notice placed by the copyright holder 10 | # saying that it may be distributed under the terms of this license. Such software is herein 11 | # referred to as the Software. This license covers modification and distribution of the 12 | # Software. 13 | # 14 | # Granted Rights 15 | # 16 | # 1. You are granted the non-exclusive rights set forth in this license provided you agree to 17 | # and comply with any and all conditions in this license. Whole or partial distribution of the 18 | # Software, or software items that link with the Software, in any form signifies acceptance of 19 | # this license. 20 | # 21 | # 2. You may copy and distribute the Software in unmodified form provided that the entire package, 22 | # including - but not restricted to - copyright, trademark notices and disclaimers, as released 23 | # by the initial developer of the Software, is distributed. 24 | # 25 | # 3. You may make modifications to the Software and distribute your modifications, in a form that 26 | # is separate from the Software, such as patches. The following restrictions apply to modifications: 27 | # 28 | # a. Modifications must not alter or remove any copyright notices in the Software. 29 | # b. When modifications to the Software are released under this license, a non-exclusive royalty-free 30 | # right is granted to the initial developer of the Software to distribute your modification in 31 | # future versions of the Software provided such versions remain available under these terms in 32 | # addition to any other license(s) of the initial developer. 33 | # 34 | # Limitations of Liability 35 | # 36 | # In no event shall the initial developers or copyright holders be liable for any damages whatsoever, 37 | # including - but not restricted to - lost revenue or profits or other direct, indirect, special, 38 | # incidental or consequential damages, even if they have been advised of the possibility of such damages, 39 | # except to the extent invariable law, if any, provides otherwise. 40 | # 41 | # No Warranty 42 | # 43 | # The Software and this license document are provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 44 | # WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 45 | # 46 | # URL: https://github.com/joeholden/distroscript/ 47 | # README: https://raw.github.com/joeholden/distroscript/master/README.md 48 | 49 | # Shells are made of dicks. 50 | DISTROSCRIPT="1.0.14" 51 | 52 | if [ -z ${DISTROFORMAT} ]; then 53 | DISTROFORMAT="pipe" 54 | fi 55 | 56 | if [ -n "${AGENT_LIBDIR}" -o -n "${MK_LIBDIR}" ]; then 57 | # Set output for check_mk/observium agent 58 | DISTROFORMAT="export" 59 | fi 60 | 61 | getos() { 62 | OS=`uname -s` 63 | if [ "${OS}" = "SunOS" ]; then 64 | OS="Solaris" 65 | elif [ "${OS}" = "DragonFly" ]; then 66 | OS="DragonFlyBSD" 67 | fi 68 | export OS 69 | return 0 70 | } 71 | 72 | getkernel() { 73 | KERNEL=`uname -r` 74 | export KERNEL 75 | return 0 76 | } 77 | 78 | getdistro() { 79 | if [ "${OS}" = "Linux" ]; then 80 | if [ -f /etc/os-release ]; then 81 | . /etc/os-release 82 | DISTRO=${NAME} 83 | elif [ -f /usr/bin/lsb_release ]; then 84 | DISTRO=`/usr/bin/lsb_release -si 2>/dev/null` 85 | elif [ -f /etc/redhat-release ]; then 86 | DISTRO=`cat /etc/redhat-release | awk '{print $1}'` 87 | if [ "${DISTRO}" = "Red" ]; then 88 | DISTRO="RedHat" 89 | fi 90 | elif [ -f /etc/mandriva-release ]; then 91 | DISTRO="Mandriva" 92 | elif [ -f /etc/arch-release ]; then 93 | DISTRO="ArchLinux" 94 | elif [ -f /etc/gentoo-release ]; then 95 | DISTRO="Gentoo" 96 | elif [ -f /etc/SuSE-release ]; then 97 | DISTRO="SuSE" 98 | elif [ -f /etc/mandrake-release ]; then 99 | DISTRO="Mandrake" 100 | elif [ -f /etc/debian_version ]; then 101 | # shit based on debian 102 | if [ -f /etc/mailcleaner/etc/mailcleaner/version.def ]; then 103 | DISTRO="MailCleaner" 104 | else 105 | DISTRO="Debian" 106 | fi 107 | elif [ -f /etc/UnitedLinux-release ]; then 108 | DISTRO="UnitedLinux" 109 | elif [ -f /etc/openwrt_version ]; then 110 | DISTRO="OpenWRT" 111 | elif [ -f /etc/slackware-version ]; then 112 | DISTRO="Slackware" 113 | else 114 | DISTRO="Unknown" 115 | fi 116 | elif [ "${OS}" = "FreeBSD" ]; then 117 | if [ -f /etc/platform -a -f /etc/version ]; then 118 | DISTRO="pfSense" 119 | elif [ -f /usr/local/bin/pbreg ]; then 120 | DISTRO="PC-BSD" 121 | elif [ -f /tmp/freenas_config.md5 ]; then 122 | DISTRO="FreeNAS" 123 | else 124 | DISTRO= 125 | fi 126 | elif [ "${OS}" = "Solaris" ]; then 127 | DISTRO=`head -n 1 /etc/release | awk '{print $1}'` 128 | if [ "${DISTRO}" = "Solaris" -o "${DISTRO}" = "Oracle" ]; then 129 | DISTRO= 130 | fi 131 | elif [ "${OS}" = "Darwin" ]; then 132 | case `uname -m` in 133 | AppleTV2*) 134 | DISTRO="AppleTV2" 135 | ;; 136 | AppleTV3*) 137 | DISTRO="AppleTV3" 138 | ;; 139 | iPhone*) 140 | DISTRO="iPhone" 141 | ;; 142 | iPod*) 143 | DISTRO="iPOD" 144 | ;; 145 | *) 146 | DISTRO="OSX" 147 | ;; 148 | esac 149 | else 150 | DISTRO= 151 | fi 152 | export DISTRO 153 | return 0 154 | } 155 | 156 | getarch() { 157 | if [ "${OS}" = "Solaris" ]; then 158 | ARCH=`isainfo -k` 159 | elif [ "${OS}" = "Darwin" ]; then 160 | ARCH=`uname -p` 161 | else 162 | ARCH=`uname -m` 163 | fi 164 | if [ "${OS}" = "Linux" ]; then 165 | if [ "${ARCH}" = "x86_64" ]; then 166 | ARCH="amd64" 167 | elif [ "${ARCH}" = "i486" -o "${ARCH}" = "i586" -o "${ARCH}" = "i686" ]; then 168 | ARCH="i386" 169 | fi 170 | fi 171 | export ARCH 172 | return 0 173 | } 174 | 175 | getversion() { 176 | if [ "${OS}" = "FreeBSD" -o "${OS}" = "DragonFlyBSD" ]; then 177 | if [ "${DISTRO}" = "pfSense" ]; then 178 | VERSION=`cat /etc/version` 179 | elif [ "${DISTRO}" = "PC-BSD" ]; then 180 | VERSION=`pbreg get /PC-BSD/Version` 181 | else 182 | VERSION=`uname -i` 183 | fi 184 | elif [ "${OS}" = "OpenBSD" -o "${OS}" = "NetBSD" ]; then 185 | VERSION=`uname -v` 186 | elif [ "${OS}" = "Linux" ]; then 187 | # Totally fucking embarassing, they can't even get the basics right. 188 | if [ "${DISTRO}" = "Debian GNU/Linux" ]; then 189 | DISTRO="Debian" 190 | fi 191 | if [ "${DISTRO}" = "OpenWRT" ]; then 192 | VERSION=`cat /etc/openwrt_version` 193 | elif [ "${DISTRO}" = "Slackware" ]; then 194 | VERSION=`cat /etc/slackware-version | cut -d" " -f2` 195 | # Debian are a bunch of useless cunts - also see: dash 196 | elif [ -f /etc/os-release ]; then 197 | if [ "${DISTRO}" = "Debian" ]; then 198 | # Debian really are the biggest bunch of spastics ever 199 | if [ -f /usr/bin/lsb_release ]; then 200 | VERSION=`lsb_release -sr 2>/dev/null` 201 | fi 202 | else 203 | . /etc/os-release 204 | VERSION=${VERSION_ID} 205 | fi 206 | elif [ -f /etc/redhat-release ]; then 207 | VERSION=`cat /etc/redhat-release | sed 's/.*release\ //' | sed 's/\ .*//'` 208 | elif [ -f /usr/bin/lsb_release ]; then 209 | VERSION=`lsb_release -sr 2>/dev/null` 210 | else 211 | VERSION= 212 | fi 213 | elif [ "${OS}" = "Darwin" ]; then 214 | VERSION=`sw_vers -productVersion` 215 | elif [ "${OS}" = "Solaris" ]; then 216 | VERSION=`uname -v` 217 | fi 218 | export VERSION 219 | return 0 220 | } 221 | 222 | 223 | if [ -z ${DISTROEXEC} ]; then 224 | getos 225 | getkernel 226 | getarch 227 | getdistro 228 | getversion 229 | if [ "${AGENT_LIBDIR}" -o "${MK_LIBDIR}" ]; then 230 | echo "<<>>" 231 | fi 232 | if [ "${DISTROFORMAT}" = "pipe" ]; then 233 | echo "${OS}|${KERNEL}|${ARCH}|${DISTRO}|${VERSION}" 234 | elif [ "${DISTROFORMAT}" = "ini" ]; then 235 | echo "[distroscript]" 236 | echo " OS = ${OS}" 237 | echo " KERNEL = ${KERNEL}" 238 | echo " ARCH = ${ARCH}" 239 | echo " DISTRO = ${DISTRO}" 240 | echo " DISTROVER = ${VERSION}" 241 | echo " SCRIPTVER = ${DISTROSCRIPT}" 242 | elif [ "${DISTROFORMAT}" = "export" ]; then 243 | echo "OS=${OS}" 244 | echo "KERNEL=${KERNEL}" 245 | echo "ARCH=${ARCH}" 246 | echo "DISTRO=${DISTRO}" 247 | echo "DISTROVER=${VERSION}" 248 | echo "SCRIPTVER=${DISTROSCRIPT}" 249 | else 250 | echo "Unsupported output format." 251 | exit 1 252 | fi 253 | exit 0 254 | fi 255 | --------------------------------------------------------------------------------