1 | #!/bin/sh
|
---|
2 |
|
---|
3 | # Print information about a Linux system
|
---|
4 | # @param distribution name of the distribution
|
---|
5 | # @param version version of the distribution
|
---|
6 | print_linux_info () {
|
---|
7 | # The following regex is not quite correct for an e-mail address, as
|
---|
8 | # the local part may not start or end with a dot. Please correct if
|
---|
9 | # this upsets you.
|
---|
10 | kern_ver=`cat /proc/version | sed -e 's/ ([a-zA-Z0-9.!#$%*/?^{}\`+=_-]*@[a-zA-Z0-9.-]*)//'`
|
---|
11 | echo "Distribution: $1 | Version: $2 | Kernel: $kern_ver"
|
---|
12 | }
|
---|
13 |
|
---|
14 | # Determine the distribution name and release for a Linux system and print
|
---|
15 | # send the information to stdout using the print_linux_info function.
|
---|
16 | # For practical reasons (i.e. lack of time), this function only gives
|
---|
17 | # information for distribution releases considered "of interest" and reports
|
---|
18 | # others as unknown. It can be extended later if other distributions are
|
---|
19 | # found to be "of interest".
|
---|
20 | get_linux_info () {
|
---|
21 | if [ -r /etc/lsb-release ] && grep Ubuntu /etc/lsb-release >/dev/null 2>&1
|
---|
22 | then
|
---|
23 | # Ubuntu-based system
|
---|
24 | . /etc/lsb-release
|
---|
25 | print_linux_info "Ubuntu" $DISTRIB_RELEASE
|
---|
26 | elif [ -r /etc/debian_version ]
|
---|
27 | then
|
---|
28 | # Debian-based system
|
---|
29 | release=`cat /etc/debian_version`
|
---|
30 | print_linux_info "Debian" $release
|
---|
31 | elif [ -r /etc/mandriva-release ]
|
---|
32 | then
|
---|
33 | # Mandriva-based system
|
---|
34 | release=`cat /etc/mandriva-release | sed -e 's/[A-Za-z ]* release //'`
|
---|
35 | print_linux_info "Mandriva" $release
|
---|
36 | elif [ -r /etc/fedora-release ]
|
---|
37 | then
|
---|
38 | # Fedora-based
|
---|
39 | release=`cat /etc/fedora-release | sed -e 's/[A-Za-z ]* release //'`
|
---|
40 | print_linux_info "Fedora" $release
|
---|
41 | elif [ -r /etc/SuSE-release ]
|
---|
42 | then
|
---|
43 | # SUSE-based.
|
---|
44 | release=`cat /etc/SuSE-release | grep "VERSION" | sed -e 's/VERSION = //'`
|
---|
45 | if grep openSUSE /etc/SuSE-release
|
---|
46 | then
|
---|
47 | # Is it worth distinguishing here? I did it mainly to prevent
|
---|
48 | # confusion with the version number
|
---|
49 | print_linux_info "openSUSE" $release
|
---|
50 | else
|
---|
51 | print_linux_info "SUSE" $release
|
---|
52 | fi
|
---|
53 | elif [ -r /etc/gentoo-release ]
|
---|
54 | then
|
---|
55 | # Gentoo-based
|
---|
56 | release=`cat /etc/gentoo-release | sed -e 's/[A-Za-z ]* release //'`
|
---|
57 | print_linux_info "Gentoo" $release
|
---|
58 | elif [ -r /etc/slackware-version ]
|
---|
59 | then
|
---|
60 | # Slackware
|
---|
61 | release=`cat /etc/slackware-version | sed -e 's/Slackware //'`
|
---|
62 | print_linux_info "Slackware" $release
|
---|
63 | elif [ -r /etc/arch-release ]
|
---|
64 | then
|
---|
65 | # Arch Linux
|
---|
66 | print_linux_info "Arch Linux" "none"
|
---|
67 | elif [ -r /etc/redhat-release ]
|
---|
68 | then
|
---|
69 | # Redhat-based. This should come near the end, as it other
|
---|
70 | # distributions may give false positives.
|
---|
71 | release=`cat /etc/redhat-release | sed -e 's/[A-Za-z ]* release //'`
|
---|
72 | print_linux_info "Redhat" $release
|
---|
73 | else
|
---|
74 | print_linux_info "unknown" "unknown"
|
---|
75 | fi
|
---|
76 | }
|
---|
77 |
|
---|
78 | # Print information about a Solaris system. FIXME.
|
---|
79 | get_solaris_info () {
|
---|
80 | kernel=`uname -v`
|
---|
81 | echo "Kernel: $kernel"
|
---|
82 | }
|
---|
83 |
|
---|
84 | # Print information about a MacOS system. FIXME.
|
---|
85 | get_macos_info () {
|
---|
86 | machine=`uname -m`
|
---|
87 | kernel=`uname -v`
|
---|
88 | echo "Machine: $machine | Kernel: $kernel"
|
---|
89 | }
|
---|
90 |
|
---|
91 | # Print information about a FreeBSD system. FIXME.
|
---|
92 | get_freebsd_info () {
|
---|
93 | kernel=`uname -v`
|
---|
94 | echo "Kernel: $kernel"
|
---|
95 | }
|
---|
96 |
|
---|
97 | system=`uname -s`
|
---|
98 | case "$system" in
|
---|
99 | Linux|linux)
|
---|
100 | get_linux_info
|
---|
101 | ;;
|
---|
102 | SunOS)
|
---|
103 | get_solaris_info
|
---|
104 | ;;
|
---|
105 | Darwin)
|
---|
106 | get_macos_info
|
---|
107 | ;;
|
---|
108 | FreeBSD)
|
---|
109 | get_freebsd_info
|
---|
110 | ;;
|
---|
111 | *)
|
---|
112 | echo "System unknown"
|
---|
113 | exit 1
|
---|
114 | ;;
|
---|
115 | esac
|
---|
116 | exit 0
|
---|