Advertisement
Guest User

Untitled

a guest
Dec 20th, 2013
1,982
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 9.20 KB | None | 0 0
  1. #!/bin/sh
  2. # ******************************************************************************
  3. # ******************************************************************************
  4. # sysname
  5. #
  6. # Script to print a string describing the type of operating system being run.
  7. # The string can currently be one of the following:
  8. #   sunos_57
  9. #   sunos_58
  10. #   sunos_510_stl4
  11. #   sunos_510_x86
  12. #   sunos_510_x86_stl4
  13. #   hpux_10
  14. #   hpux_11
  15. #   aix_41
  16. #   aix_43
  17. #   aix_51
  18. #   aix_53
  19. #   linux_rhel40_gcc44x
  20. #   win32
  21. #
  22. #   A user may set the variable OA_UNSUPPORTED_PLAT to force the name of an
  23. #   unsupported platform to work.  Specifically for Linux, if the type of
  24. #   Linux system is not recognized, the OA_UNSUPPORTED_PLAT variable is
  25. #   examined and used if set.
  26. #
  27. # ******************************************************************************
  28. # Except as specified in the OpenAccess terms of use of Cadence or Silicon
  29. # Integration Initiative, this material may not be copied, modified,
  30. # re-published, uploaded, executed, or distributed in any way, in any medium,
  31. # in whole or in part, without prior written permission from Cadence.
  32. #
  33. #                 Copyright 2002-2005 Cadence Design Systems, Inc.
  34. #                           All Rights Reserved.
  35. #
  36. #  $Author: icftcm $
  37. #  $Revision: #3 $
  38. #  $Date: 2012/07/09 $
  39. #  $State: Exp $
  40. # *****************************************************************************
  41. # *****************************************************************************
  42.  
  43.  
  44.  
  45. usage() {
  46.   echo "Usage: sysname [ -h | -m | -b | -v ]"
  47. }
  48.  
  49.  
  50.  
  51. # *****************************************************************************
  52. # check_sunos
  53. #
  54. # This routine sets the version, sysname, and sysnames variables for the
  55. # Solaris operating system.
  56. #
  57. #    sunos_57 : SunOS 5.7*
  58. #    sunos_58 : SunOS 5.8* SunOS 5.9* SunOS 5.10*
  59. # *****************************************************************************
  60. check_sunos() {
  61.   sysnames="sunos$compiler"
  62.   _rev=`/bin/uname -r`
  63.  
  64.   longVersion="SunOS $_rev"
  65.  
  66.   case $_rev in
  67.     5.7* )
  68.       sysname="sunos_57$compiler"; sysnames="$sysname $sysnames"
  69.       version=57
  70.       ;;
  71.  
  72.     5.8* | 5.9* )
  73.       sysname="sunos_58$compiler"; sysnames="$sysname sunos_57$compiler $sysnames"
  74.       version=58
  75.       ;;
  76.  
  77.     5.10* )
  78.       cpuarch=`uname -m`
  79.       if [ "$cpuarch" = "i86pc" ]; then
  80.         sysname="sunos_510_x86$compiler"; sysnames="$sysname $sysnames"
  81.         version=510
  82.       elif [ "$cpuarch" = "sun4u" -o "$cpuarch" = "sun4v" -o "$cpuarch" = "sun4us" ]; then
  83.     if [ "$compiler" != "" ]; then
  84.       sysname="sunos_510$compiler"; sysnames="$sysname $sysnames"
  85.       version=510
  86.     else
  87.       sysname="sunos_58$compiler"; sysnames="$sysname sunos_57$compiler $sysnames"
  88.       version=58
  89.     fi
  90.       else
  91.         check_global
  92.       fi
  93.       ;;
  94.  
  95.     * )
  96.       check_global
  97.   esac
  98. }
  99.  
  100.  
  101.  
  102. # *****************************************************************************
  103. # check_hpux
  104. #
  105. # This routine sets the version, sysname, and sysnames variables for the
  106. # HP-UX operating system.
  107. #
  108. #    hpux_10 : HP-UX 10.*
  109. #    hpux_11 : HP-UX 11.* and 32-bit
  110. # *****************************************************************************
  111. check_hpux() {
  112.   sysnames="hpux$compiler"
  113.   _rev=`/bin/uname -r`
  114.  
  115.   longVersion="HP-UX $_rev"
  116.  
  117.   case $_rev in
  118.     *.10.* )
  119.       sysname="hpux_10$compiler"; sysnames="$sysname $sysnames"
  120.       version=10
  121.       ;;
  122.     *.11.* )
  123.       sysname="hpux_11$compiler"; sysnames="$sysname hpux_10$compiler $sysnames"
  124.       version=11
  125.       ;;
  126.     * )
  127.       check_global
  128.    esac
  129. }
  130.  
  131.  
  132.  
  133. # *****************************************************************************
  134. # check_aix
  135. #
  136. # This routine sets the version, sysname, and sysnames variables for the
  137. # AIX operating system.
  138. #
  139. #    aix41 : AIX 4.1.*
  140. #    aix43 : AIX 4.3.*
  141. #    aix51 : AIX 5.1.*
  142. #    aix53 : AIX 5.3.*
  143. #    aix61 : AIX 6.1.*
  144. # *****************************************************************************
  145. check_aix() {
  146.   sysnames="aix$compiler"
  147.   mainVer=`/bin/uname -v`
  148.   subVer=`/bin/uname -r`
  149.   version="${mainVer}${subVer}"
  150.  
  151.   longVersion="AIX ${mainVer}.${subVer}"
  152.  
  153.   case $version in
  154.     41 )
  155.       sysname="aix_41$compiler"; sysnames="$sysname $sysnames";;
  156.     43 )
  157.       sysname="aix_43$compiler"; sysnames="$sysname aix_41$compiler $sysnames";;
  158.     51 )
  159.       sysname="aix_51$compiler"; sysnames="$sysname $sysnames";;
  160.     53 )
  161.       sysname="aix_53$compiler"; sysnames="$sysname $sysnames";;
  162.     61 )
  163.       sysname="aix_53$compiler"; sysnames="$sysname $sysnames";;
  164.     * )
  165.       check_global
  166.   esac
  167. }
  168.  
  169.  
  170.  
  171. # *****************************************************************************
  172. # check_linux
  173. #
  174. # This routine sets the version, system, and sysname variables for the Linux
  175. # operating system.  If the version of Linux is unrecognized and
  176. # OA_UNSUPPORTED_PLAT is set, then that is returned.  
  177. #
  178. # linux-x86
  179. # *****************************************************************************
  180. check_linux() {
  181.     sysnames=$sysname
  182.  
  183.     version=`uname -r`
  184.     machine=`uname -m`
  185.  
  186.     if [ -f "/etc/redhat-release" ]
  187.      then
  188.         longVersion=`cat /etc/redhat-release`
  189.      elif [ -f "/etc/SuSE-release" ]
  190.       then
  191.         longVersion=`cat /etc/SuSE-release`
  192.      else
  193.         longVersion="UNKNOWN Linux"
  194.     fi
  195.  
  196. #    case $machine in
  197. #   ia64 )  sysname="linux_rhas21_ia64$compiler"; sysnames="$sysname $sysnames";;
  198. #   *86 | *86_64 ) 
  199. #       case $version in
  200. #           2.4*) compiler="_gcc411"
  201. #             sysname="linux_rhel30$compiler"; sysnames="$sysname linux$compiler";;
  202. #           2.6*|3.0*) compiler="_gcc44x"
  203. #                      sysname="linux_rhel40$compiler"; sysnames="$sysname linux$compiler";;
  204. #           *)    check_global;;
  205. #       esac;;
  206. #   *)  check_global;;
  207. #    esac
  208.  
  209. compiler="_gcc44x"
  210. sysname="linux_rhel40$compiler"; sysnames="$sysname linux$compiler"
  211.  
  212. }
  213.  
  214.  
  215.  
  216. # *****************************************************************************
  217. # check_win
  218. #
  219. # This routine sets the version, system, and sysname variables for the Windows
  220. # operating system.
  221. # *****************************************************************************
  222. check_win() {
  223.   _is64=`echo $basesysname | sed -e 's/cygwin_nt-5..-//'`
  224.  
  225.   if [ $_is64 = "wow64" ]; then
  226.     sysname="x64"
  227.     sysnames=$sysname
  228.     version="x64"
  229.     longVersion="Windows 64bit"
  230.   else
  231.     sysname="win32"
  232.     sysnames=$sysname
  233.     version="win32"
  234.     longVersion="Windows 32bit"
  235.   fi
  236. }
  237.  
  238. # *****************************************************************************
  239. # check_global
  240. #
  241. # This routine handles the sysname for an unsupported system.  If a user
  242. # wants to run on an unsupported system, they must set the environment
  243. # variable OA_UNSUPPORTED_PLAT to the sysname they wish to utilize.
  244. # Otherwise, the script will exit.
  245. # *****************************************************************************
  246. check_global() {
  247.   if [ -n "$OA_UNSUPPORTED_PLAT" ]
  248.    then
  249.        sysname=${OA_UNSUPPORTED_PLAT}
  250.        sysnames=$sysname
  251.        version="Unknown"
  252.        longVersion="Unknown"
  253.    else
  254.       echo "unknown"
  255.       exit 1
  256.    fi
  257. }
  258.  
  259.  
  260.  
  261. # ******************************************************************************
  262. # Start of the script
  263. # ******************************************************************************
  264.  
  265. # Check for options.
  266. if [ $# -gt 1 ];
  267. then
  268.   usage
  269.   exit 1
  270. fi
  271.  
  272. matching_sysnames=0
  273. base_sysname=0
  274. get_version=0
  275. get_longVersion=0
  276. if [ $# -eq 1 ];
  277. then
  278.   case $1 in
  279.     -h )
  280.       usage; exit 0;;
  281.     -m )
  282.       matching_sysnames=1;;
  283.     -b )
  284.       base_sysname=1;;
  285.     -v )
  286.       get_version=1;;
  287.     -V )
  288.       get_longVersion=1;;
  289.     * )
  290.       usage; exit 1
  291.   esac      
  292. else
  293.     if [ -n "$OA_SYSNAME" ]; then
  294.     echo $OA_SYSNAME
  295.     exit 0
  296.     fi
  297. fi
  298.  
  299.  
  300.  
  301. # Get the operating system name.
  302. sysname=`/bin/uname -s | LC_ALL=C /usr/bin/tr -s '[:upper:]' '[:lower:]'`
  303. basesysname="$sysname"
  304.  
  305. # OA_COMPILER will be appended to all sysnames, preceded by an underscore.
  306. if [ "${OA_COMPILER-}" != "" ]; then
  307.   compiler="_${OA_COMPILER}"
  308. else
  309.   compiler=""
  310. fi
  311.  
  312. sysname="$sysname$compiler"
  313.  
  314. # Call the appropriate function to get the sysname. The sysname will embed
  315. # information about the version of the operating system, processor type and
  316. # architecture. It will be returned in the variable $sysname. A list of
  317. # compatible sysnames will also be returned in $sysnames.
  318. case $basesysname in
  319.   sunos ) check_sunos;;
  320.   hp-ux ) check_hpux;;
  321.   aix ) check_aix;;
  322.   linux ) check_linux;;
  323.   windows*|cygwin_nt* ) check_win;;
  324.   * ) check_global;;
  325. esac
  326.  
  327.  
  328.  
  329. # If an error occured, this script already exited with a non-zero error code.
  330.  
  331. # If the -m option was specified, output a list of matching
  332. # sysnames, in order of priority. If the -b option was specified,
  333. # it will print out the base sysname for this system. Otherwise,
  334. # print the actual sysname of the machine.
  335.  
  336. if [ $get_version -eq 1 ];
  337. then
  338.   echo $version
  339. elif [ $get_longVersion -eq 1 ];
  340. then
  341.   echo $longVersion
  342. elif [ $matching_sysnames -eq 1 ];
  343. then
  344.   echo $sysnames
  345. elif [ $base_sysname -eq 1 ];
  346. then
  347.   echo $sysnames | /bin/awk '{print $NF}'
  348. else
  349.   echo $sysname
  350. fi
  351.  
  352. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement