-
Notifications
You must be signed in to change notification settings - Fork 2
/
detect-distro.sh
executable file
·57 lines (52 loc) · 1.42 KB
/
detect-distro.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/bin/bash
STDOUT=2
error() {
local msg="$1"
[ -n "$msg" ] && echo -e "\n${0##*/}: $msg" >&$STDOUT
}
fatal() {
error "$2"
exit $1
}
if which lsb_release >/dev/null 2>&1; then
name="$(lsb_release -s -i)"
version="$(lsb_release -s -r)"
case "$name" in
"EnterpriseEnterpriseServer")
name="oel"
;;
"RedHatEnterpriseServer" | "ScientificSL" | "CentOS")
name="rhel"
;;
"SUSE LINUX")
name="sles"
PATCHLEVEL=$(sed -n -e 's/^PATCHLEVEL = //p' /etc/SuSE-release)
version="${version}.$PATCHLEVEL"
;;
"Fedora")
name="fc"
;;
*)
fatal 1 "I don't know what distro name $name and version $version is.\nEither update autodetect_distro() or use the --distro argument."
;;
esac
else
error "You really ought to install lsb_release for accurate distro identification"
# try some heuristics
if [ -f /etc/SuSE-release ]; then
name=sles
version=$(sed -n -e 's/^VERSION = //p' /etc/SuSE-release)
PATCHLEVEL=$(sed -n -e 's/^PATCHLEVEL = //p' /etc/SuSE-release)
version="${version}.$PATCHLEVEL"
elif [ -f /etc/redhat-release ]; then
#name=$(head -1 /etc/redhat-release)
name=rhel
version=$(echo "$distroname" |
sed -e 's/^[^0-9.]*//g' | sed -e 's/[ ].*//')
fi
if [ -z "$name" -o -z "$version" ]; then
fatal 1 "I don't know how to determine distro type/version.\nEither update autodetect_distro() or use the --distro argument."
fi
fi
echo ${name}-${version}
exit 0