-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathlibinstall.sh
More file actions
57 lines (51 loc) · 1.83 KB
/
libinstall.sh
File metadata and controls
57 lines (51 loc) · 1.83 KB
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
function get_os_info(){
local os_name="unknown"
local os_version="unknown"
local cpu_arch="unknown"
#Check OS name and version
if [ -f /etc/os-release ]; then
. /etc/os-release
#check ubuntu
if [ "$ID" = "ubuntu" ] || [ "$ID_LIKE" = "debian" ]; then
os_name="ubuntu"
os_version=$VERSION_ID
#check centos
elif [ "$ID" = "centos" ]; then
os_name="centos"
os_version=$VERSION_ID
#check rocky
elif [ "$ID" = "rocky" ]; then
os_name="rocky"
os_version=$VERSION_ID
#check redhat
elif [ "$ID" = "rhel" ] || [ "$ID_LIKE" = "rhel" ] || [ "$NAME" = "Red Hat Enterprise Linux" ]; then
os_name="redhat"
os_version=$VERSION_ID
fi
# Compatible with older systems without /etc/os-release
else
if [ -f /etc/redhat-release ]; then
release=$(cat /etc/redhat-release)
# Check CentOS
if echo "$release" | grep -qi "centos"; then
os_name="centos"
os_version=$(echo "$release" | awk '{print $4}' | cut -d '.' -f 1)
# Check RedHat
elif echo "$release" | grep -qi "red hat"; then
os_name="redhat"
os_version=$(echo "$release" | awk '{print $7}' | cut -d '.' -f 1)
fi
elif [ -f /etc/lsb-release ]; then
. /etc/lsb-release
if [ "$DISTRIB_ID" = "Ubuntu" ]; then
os_name="ubuntu"
os_version=$DISTRIB_RELEASE
fi
fi
fi
# Check main version
os_version=$(echo "$os_version" | sed -E 's/[^0-9.]//g' | cut -d '.' -f 1)
cpu_arch=$(uname -m)
echo $os_name $os_version $cpu_arch
}