release 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #!/bin/sh -e
  2. #
  3. # release: grab the os/distro release version
  4. #
  5. # Copyright (C) 2008 Canonical Ltd.
  6. # Copyright (C) 2011-2014 Dustin Kirkland
  7. #
  8. # Authors: Dustin Kirkland <kirkland@byobu.org>
  9. #
  10. # This program is free software: you can redistribute it and/or modify
  11. # it under the terms of the GNU General Public License as published by
  12. # the Free Software Foundation, version 3 of the License.
  13. #
  14. # This program is distributed in the hope that it will be useful,
  15. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. # GNU General Public License for more details.
  18. #
  19. # You should have received a copy of the GNU General Public License
  20. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. __release_detail() {
  22. lsb_release -a 2>/dev/null
  23. }
  24. __release() {
  25. local RELEASE="${RELEASE}"
  26. if [ -n "$RELEASE" ]; then
  27. # user defined
  28. true
  29. elif [ -r "/etc/os-release" ]; then
  30. # lsb_release is *really* slow; try to use /etc/os-release
  31. RELEASE=$(. /etc/os-release && echo "$VERSION_ID")
  32. elif [ -r "/etc/issue" ]; then
  33. # next try /etc/issue first
  34. local issue
  35. read issue < /etc/issue
  36. case "$issue" in
  37. Ubuntu*)
  38. set -- $issue;
  39. RELEASE="$2";
  40. ;;
  41. Debian*)
  42. local ver
  43. read ver < /etc/debian_version
  44. RELEASE="$ver"
  45. ;;
  46. esac
  47. elif eval $BYOBU_TEST sw_vers >/dev/null 2>&1; then
  48. RELEASE="$(sw_vers -productVersion)"
  49. fi
  50. if [ -z "$RELEASE" ] && eval $BYOBU_TEST lsb_release >/dev/null 2>&1; then
  51. # If lsb_release is available, use it
  52. RELEASE=$(lsb_release -s -r)
  53. fi
  54. if [ -n "$RELEASE_ABBREVIATED" ] && [ $RELEASE_ABBREVIATED -gt 0 ]; then
  55. color bold2; printf "%.${RELEASE_ABBREVIATED}s" "$RELEASE"; color --
  56. else
  57. color bold2; printf "%s" "$RELEASE"; color --
  58. fi
  59. }
  60. # vi: syntax=sh ts=4 noexpandtab