lsb_release 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. #!/bin/sh
  2. #
  3. # This is a simple alternative to /usr/bin/lsb_release which
  4. # doesn't require python.
  5. #
  6. # If /etc/lsb-release exists then we use that to output data
  7. # in a compatible format to the original lsb_release utility.
  8. #
  9. # I consider this script trivial enough to be in the public-domain,
  10. # but any patches or suggestsions will be welcome.
  11. #
  12. # Steve
  13. # --
  14. #
  15. show_help() {
  16. cat << EOF
  17. Usage: lsb_release [options]
  18. Options:
  19. -h, --help show this help message and exit
  20. -i, --id show distributor ID
  21. -d, --description show description of this distribution
  22. -r, --release show release number of this distribution
  23. -c, --codename show code name of this distribution
  24. -a, --all show all of the above information
  25. -s, --short show requested information in short format
  26. EOF
  27. exit 0
  28. }
  29. #
  30. # Potential command-line options.
  31. #
  32. all=0
  33. codename=0
  34. description=0
  35. id=0
  36. release=0
  37. short=0
  38. version=0
  39. #
  40. # Process each argument, and set the appropriate flag
  41. # if we recognize it.
  42. #
  43. while :; do
  44. case $1 in
  45. -a|--all)
  46. all=1
  47. ;;
  48. -c|--codename)
  49. codename=1
  50. ;;
  51. -d|--description)
  52. description=1
  53. ;;
  54. -h|--help)
  55. show_help
  56. break
  57. ;;
  58. -i|--id)
  59. id=1
  60. ;;
  61. -r|--release)
  62. release=1
  63. ;;
  64. -s|--short)
  65. short=1
  66. ;;
  67. -v|--version)
  68. version=1
  69. ;;
  70. *)
  71. break
  72. esac
  73. shift
  74. done
  75. #
  76. # Read our variables.
  77. #
  78. if [ -e /etc/lsb-release ]; then
  79. . /etc/lsb-release
  80. else
  81. echo "/etc/lsb-release is not present. Aborting" >&2
  82. exit 1
  83. fi
  84. #
  85. # Now output the data - The order of these was chosen to match
  86. # what the original lsb_release used, and while I suspect it doesn't
  87. # matter I kept it the same.
  88. #
  89. if [ "$all" = "1" ] || [ "$id" = "1" ]; then
  90. if [ "$short" = "0" ]; then
  91. printf "Distributor ID:\t"
  92. fi
  93. echo $DISTRIB_ID
  94. fi
  95. if [ "$all" = "1" ] || [ "$description" = "1" ]; then
  96. if [ "$short" = "0" ]; then
  97. printf "Description:\t"
  98. fi
  99. echo $DISTRIB_DESCRIPTION
  100. fi
  101. if [ "$all" = "1" ] || [ "$release" = "1" ]; then
  102. if [ "$short" = "0" ]; then
  103. printf "Release:\t"
  104. fi
  105. echo $DISTRIB_RELEASE
  106. fi
  107. if [ "$all" = "1" ] || [ "$codename" = "1" ]; then
  108. if [ "$short" = "0" ]; then
  109. printf "Codename:\t"
  110. fi
  111. #
  112. # Codename comes from: VERSION="7 (wheezy)"
  113. #
  114. ver=$(echo $VERSION | awk '{print $2}' | tr -d \(\))
  115. echo "$DISTRIB_CODENAME"
  116. fi
  117. exit 0