Debian Codegraph @

lsb_release

raw
1 #!/bin/sh
2
3 # SPDX-FileCopyrightText: 2021 Gioele Barabucci
4 # SPDX-License-Identifier: ISC
5
6 set -eu
7
8 export LC_ALL="C.UTF-8"
9
10 help () {
11 cat <<-EOD
12 Usage: lsb_release [options]
13
14 Options:
15 -h, --help show this help message and exit
16 -v, --version show LSB modules this system supports
17 -i, --id show distributor ID
18 -d, --description show description of this distribution
19 -r, --release show release number of this distribution
20 -c, --codename show code name of this distribution
21 -a, --all show all of the above information
22 -s, --short show requested information in short format
23 EOD
24 }
25
26 show_warning=false
27 show_id=false
28 show_desc=false
29 show_release=false
30 show_codename=false
31 short_format=false
32
33 options=$(getopt --name lsb_release -o hvidrcas -l help,version,id,description,release,codename,all,short -- "$@") || exit 2
34 eval set -- "$options"
35 [ "$1" = "--" ] && show_warning=true
36 while [ $# -gt 0 ] ; do
37 case "$1" in
38 -h|--help) help; exit ;;
39 -v|--version) show_warning=true ;;
40 -i|--id) show_id=true ;;
41 -d|--description) show_desc=true ;;
42 -r|--release) show_release=true ;;
43 -c|--codename) show_codename=true ;;
44 -a|--all) show_warning=true; show_id=true; show_desc=true; show_release=true; show_codename=true ;;
45 -s|--short) short_format=true ;;
46 --) ;;
47 *) { help; echo; echo "lsb_release: error: No arguments are permitted"; } >&2; exit 2
48 esac
49 shift
50 done
51
52 display_line () {
53 label="$1"
54 value="$2"
55
56 if $short_format ; then
57 printf "%s\n" "$value"
58 else
59 printf "%s:\t%s\n" "$label" "$value"
60 fi
61 }
62
63 # Load release info from standard identification data files
64 [ -f /usr/lib/os-release ] && os_release=/usr/lib/os-release
65 [ -f /etc/os-release ] && os_release=/etc/os-release
66 [ "${LSB_OS_RELEASE-x}" != "x" ] && [ -f "$LSB_OS_RELEASE" ] && os_release="$LSB_OS_RELEASE"
67 [ "${os_release-x}" != "x" ] && . "$os_release"
68
69 # Mimic the output of Debian's Python-based lsb_release
70 # Capitalize ID
71 : "${ID=}"
72 ID="$(printf "%s" "$ID" | cut -c1 | tr '[:lower:]' '[:upper:]')$(printf "%s" "$ID" | cut -c2-)"
73 # Use NAME if set and different from ID only in capitalization.
74 if [ "${NAME-x}" != "x" ] ; then
75 lower_case_id=$(printf "%s" "$ID" | tr '[:upper:]' '[:lower:]')
76 lower_case_name=$(printf "%s" "$NAME" | tr '[:upper:]' '[:lower:]')
77 if [ "${lower_case_id}" = "${lower_case_name}" ] ; then
78 ID="$NAME"
79 fi
80 fi
81
82 # Generate minimal standard-conform output (if stdout is a TTY).
83 [ -t 1 ] && $show_warning && echo "No LSB modules are available." >&2
84
85 if $show_id ; then
86 display_line "Distributor ID" "${ID:-n/a}"
87 fi
88
89 if $show_desc ; then
90 display_line "Description" "${PRETTY_NAME:-n/a}"
91 fi
92
93 if $show_release ; then
94 display_line "Release" "${VERSION_ID:-n/a}"
95 fi
96
97 if $show_codename ; then
98 display_line "Codename" "${VERSION_CODENAME:-n/a}"
99 fi