-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon
executable file
·129 lines (117 loc) · 2.89 KB
/
common
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#
# Check distro name and package type
# Set DESTRO (ubuntu/centos/fedora, etc)
# Set PKG_TYPE (DEB/RPM/TGZ)
# Set PKG_TYPE (DEB/RPM/TGZ)
# Set CODENAME (for ubuntu: precise,saucy,trusty,etc)
# Set ARCH (amd64,x86_64,i386)
#
check_distro ()
{
cat /etc/*release | grep -i -q "CentOS release 5."
if [ $? -eq 0 ]
then
DISTRO=centos
PKG_TYPE=rpm
DISTRO_DISPLAY_NAME=CentOS
CODENAME=el5
ARCH=$(uname -m)
return
fi
declare -A _distros
_distros=(
[ubuntu]=deb,amd64,lsb-release,,Ubuntu
[debian]=deb,amd64,lsb-release,,Debian
[centos]=rpm,x86_64,redhat-release,el,CentOS
[fedora]=rpm,x86_64,redhat-release,el,Fedora
[redhat]=rpm,x86_64,redhat-release,el,RedHat
[suse]=rpm,x86_64,SuSE-release,suse,SuSE
[gentoo]=rpm,amd64,gentoo-release,,Gentoo
)
# Get DISTRO and PKG_TYPE
_tmp_file=distro_$$.txt
cat /etc/*release > $_tmp_file
for _distro in "${!_distros[@]}"
do
_count=$(grep -i -c ${_distro} $_tmp_file)
if [ $_count -gt 0 ]
then
DISTRO=${_distro}
PKG_TYPE=$(echo ${_distros[$_distro]} | cut -d',' -f1)
DISTRO_DISPLAY_NAME=$(echo ${_distros[$_distro]} | cut -d',' -f5)
break
fi
done
$CMD_PREFIX rm -rf $_tmp_file
# Get ARCH
arch=$(uname -m)
case "$arch" in
"x86_64")
ARCH=$(echo ${_distros[$DISTRO]} | cut -d',' -f2)
;;
"i386" | "i686")
ARCH="i386"
;;
esac
# Get CODENAME
release_file=$(echo ${_distros[$DISTRO]} | cut -d',' -f3)
if [ -e /etc/debian_version ]
then
if [ -e /etc/lsb-release ]
then
. /etc/lsb-release
CODENAME=${DISTRIB_CODENAME}
else
case $(cat /etc/debian_version) in
5.*)
CODENAME=lenny
;;
6.*)
CODENAME=squeeze
;;
7.*)
CODENAME=wheezy
;;
"sid")
CODENAME=sid
;;
esac
fi
elif [ -e /etc/gentoo-release ]
then
CODENAME=gentoo
else
release_file=$(echo ${_distros[$DISTRO]} | cut -d',' -f3)
codename_prefix=$(echo ${_distros[$DISTRO]} | cut -d',' -f4)
_version=$(/bin/rpm -q --qf "%{VERSION}" --whatprovides /etc/${release_file})
CODENAME=${codename_prefix}${_version}
fi
}
get_distro_version()
{
_distro=$1
_codename=$2
case "$_distro" in
cenos|fedora|redhat|suse)
echo ${_codename:2}
;;
ubuntu)
case "$_codename" in
lucid)
echo 10.04
;;
precise)
echo 12.04
;;
trusty)
echo 14.04
;;
esac
;;
esac
}
#check_distro
#echo $DISTRO
#echo $PKG_TYPE
#echo $ARCH
#echo $CODENAME