Wednesday, January 5, 2011

Which distro?

When writing shell script, sometime we need to find out which Linux flavor is running on the machine. I like the following bash script from knowledgetree installer to do the job.

function distro_info() {
  distro=$(lsb_release --short --id)

  case "$distro" in
    "Ubuntu"|"Debian")
      # install deb package using apt-get
      ;;
    "CentOS"|"Fedora"|"RedHatEnterpriseServer")
      # install rpm package using yum
      ;;
    * )
      unsupported_distro
      return 1
      ;;
  esac
}

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...