1#! /bin/sh 2 3# "findos.sh" 4# 5# Attempt to find the operating system varient in play. This is mainly 6# for use on Linux where the tests that autoconf does do not detect 7# which distribution I am using. 8# 9# If $1 is "short" then this will omit version information. 10# 11# This code is not properly general. It mostly looks at the file 12# /etc/issue (which an administrator could have altered!) and pattern 13# matches against the cases I happen to have tested. It can thus need 14# checking and extending as new cases become relevant. If the utility 15# lsb_release then information from that will be used, and it may be 16# more reliable. 17 18os="unknown" 19 20case `uname -a` in 21*CYGWIN* | *Cygwin* | *cygwin* | *MINGW* | *MinGW* | *Mingw* | *mingw*) 22 echo "windows" 23 exit 24 ;; 25FreeBSD*) 26 version=`uname -r | sed -e 's/-.*$//'` 27 echo "freebsd$version" 28 exit 29 ;; 30esac 31 32vendor=`if { lsb_release -d ; } 2>/dev/null; then : ; else echo unknown; fi` 33version=`if { lsb_release -r ; } 2>/dev/null; then : ; else echo unknown; fi` 34 35# I think it is probable that if lsb_release is available the result it 36# provides will be more reliable than looking in /etc/issue 37 38if test "x$vendor" != "xunknown" 39then 40# I normalise the names of distributions I know about... 41 case $vendor in 42 *Debian*) 43 vendor="debian" 44 ;; 45 *Fedora*) 46 vendor="fedora" 47 ;; 48 *SUSE*) 49 vendor="suse" 50 ;; 51 *Ubuntu*) 52 vendor="ubuntu" 53 ;; 54 *Linux*Mint*) 55 vendor="mint" 56 ;; 57 *CentOS*) 58 vendor="centos" 59 ;; 60 *Scientific*) 61 vendor="scientificlinux" 62 ;; 63 *Gentoo*) 64 vendor="gentoo" 65 ;; 66 *Raspbian*) 67 vendor="raspbian" 68 ;; 69# Add more distributions here please! 70 *) 71 vendor="unknown" 72 ;; 73 esac 74fi 75 76 77 78if test "x$vendor" != "xunknown" 79then 80 if test "x$version" != "xunknown" && test "x$1" != "xshort" 81 then 82 version=`echo $version | sed '-e s/[^:]*:[ \t]*//'` 83 os="$vendor$version" 84 else 85 os="$vendor" 86 fi 87else 88 if test -f /etc/issue 89 then 90# I will detect a bunch of the bigger distributions. The 91# first thing to do is to spot the main family, after that 92# I will try to decode the release number. 93# 94# Usually the information I want is on the first line of /etc/issue, but at 95# least on SUSE that is blank. On Ubuntu /etc/issue is several lines long 96# and if I process all of them I get in a mess. Hence the following 97# messing about with "head" etc. Actuall some of the pain is that on Ubuntu 98# the file /etc/issue contains a string "\n" that sometimes gets mapped 99# onto a newline. 100 issue=`cat /etc/issue` 101 hissue=`echo "$issue" | head -1` 102 if test "x$hissue" = "x" 103 then 104 hissue="$issue" 105 fi 106 case $issue in 107 *Red*Hat*) 108 if test "x$1" = "xshort" 109 then 110 os="rh" 111 else 112 os=`echo $hissue | sed 's/^[^0-9]*\\([0-9][0-9]*\\.*[0-9]*\\).*$/rh\\1/'` 113 fi 114 ;; 115 *SUSE*) 116 if test "x$1" = "xshort" 117 then 118 os="suse" 119 else 120 os=`echo $hissue | sed 's/^[^0-9]*\\([0-9][0-9]*\\.*[0-9]*\\).*$/suse\\1/'` 121 fi 122 ;; 123 *Fedora*) 124 if test "x$1" = "xshort" 125 then 126 os="fedora" 127 else 128 os=`echo $hissue | sed 's/^[^0-9]*\\([0-9][0-9]*\\.*[0-9]*\\).*$/fedora\\1/'` 129 fi 130 ;; 131 *Scientific*Linux*) 132 if test "x$1" = "xshort" 133 then 134 os="scientificlinux" 135 else 136 os=`echo $hissue | sed 's/^[^0-9]*\\([0-9][0-9]*\\.*[0-9]*\\).*$/scientificlinux\\1/'` 137 fi 138 ;; 139 *Debian*) 140 if test "x$1" = "xshort" 141 then 142 os="debian" 143 else 144 os=`echo $hissue | sed 's/^[^0-9]*\\([0-9][0-9]*\\.*[0-9]*\\).*$/debian\\1/'` 145 fi 146 ;; 147 *Ubuntu*) 148 if test "x$1" = "xshort" 149 then 150 os="ubuntu" 151 else 152 os=`echo $hissue | sed 's/^[^0-9]*\\([0-9][0-9]*\\.*[0-9]*\\).*$/ubuntu\\1/'` 153 fi 154 ;; 155 *Linux*Mint*) 156 if test "x$1" = "xshort" 157 then 158 os="mint" 159 else 160 os=`echo $hissue | sed 's/^[^0-9]*\\([0-9][0-9]*\\.*[0-9]*\\).*$/mint\\1/'` 161 fi 162 ;; 163 *Mandriva*) 164 if test "x$1" = "xshort" 165 then 166 os="mandriva" 167 else 168 os=`echo $hissue | sed 's/^[^0-9]*\\([0-9][0-9]*\\.*[0-9]*\\).*$/mandriva\\1/'` 169 fi 170 ;; 171 *Mandrake*) 172 if test "x$1" = "xshort" 173 then 174 os="mandrake" 175 else 176 os=`echo $hissue | sed 's/^[^0-9]*\\([0-9][0-9]*\\.*[0-9]*\\).*$/mandrake\\1/'` 177 fi 178 ;; 179 esac 180 else 181 if test -f /System/Library/CoreServices/SystemVersion.plist 182 then 183# For MacOS I will detect the version number and report a code-name for it. 184# Actually the succession of changes that Apple make here is starting to 185# get tedious to track! 186 if test "x$1" = "xshort" 187 then 188 os="mac" 189 else 190 case `cat /System/Library/CoreServices/SystemVersion.plist` in 191# *Mac*OS*X*ProductVersion*\<string\>10.2*) 192# os="mac_10.2_jaguar" 193# ;; 194# *Mac*OS*X*ProductVersion*\<string\>10.3*) 195# os="mac_10.3_panther" 196# ;; 197# *Mac*OS*X*ProductVersion*\<string\>10.4*) 198# os="mac_10.4_tiger" 199# ;; 200# *Mac*OS*X*ProductVersion*\<string\>10.5*) 201# os="mac_10.5_leopard" 202# ;; 203# *Mac*OS*X*ProductVersion*\<string\>10.6*) 204# os="mac_10.6_snowleopard" 205# ;; 206 *Mac*OS*X*ProductVersion*\<string\>10.7*) 207 os="mac_10.7_lion" 208 ;; 209 *Mac*OS*X*ProductVersion*\<string\>10.8*) 210 os="mac_10.8_mountainlion" 211 ;; 212 *Mac*OS*X*ProductVersion*\<string\>10.9*) 213 os="mac_10.9_mavericks" 214 ;; 215 *Mac*OS*X*ProductVersion*\<string\>10.10*) 216 os="mac_10.10_yosemite" 217 ;; 218 *Mac*OS*X*ProductVersion*\<string\>10.11*) 219 os="mac_10.11_elcapitan" 220 ;; 221 *Mac*OS*X*ProductVersion*\<string\>10.12*) 222 os="mac_10.12_sierra" 223 ;; 224 *Mac*OS*X*ProductVersion*\<string\>10.13*) 225 os="mac_10.13_highsierra" 226 ;; 227 *Mac*OS*X*ProductVersion*\<string\>10.14*) 228 os="mac_10.14_mojave" 229 ;; 230 *Mac*OS*X*ProductVersion*\<string\>10.15*) 231 os="mac_10.15_catalina" 232 ;; 233# I think that 11.0 and 11.2 are both known as Big Sur? 234 *Mac*OS*X*ProductVersion*\<string\>11.*) 235 os="mac_11_big_sur" 236 ;; 237 *mac*OS*ProductVersion*\<string\>11.*) 238 os="mac_11_bigsur" 239 ;; 240 *Mac*OS*X*ProductVersion*\<string\>*) 241 os="mac_unknown_version" 242 ;; 243 esac 244 fi 245 else 246 os="unknown" 247 fi 248 fi 249fi 250 251# I want to ensure that there are no blanks, tabs or slashes in the name 252os=`echo $os | sed -e 's/[ /]//g'` 253 254echo $os 255 256exit 257