forked from stanford-rc/robinhood
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpkgs_precheck.sh
executable file
·118 lines (109 loc) · 2.95 KB
/
pkgs_precheck.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
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
#!/bin/bash
#
# dpkg_precheck.sh
# used to check build packages dependency for ubuntu
check_deb_pkg() {
# get package name
pkg_name=$1
dpkg -l $pkg_name 1> /dev/null 2>&1
if [ "$?" -ne 0 ]
then
echo package \'$pkg_name\' not found
echo please run \'sudo apt install $pkg_name\' to install package
return 1
else
#
# need check further, because 'dpkg -l' command will return 0 if
# pkg ever installed but uninstalled now with output as:
#
# un libglib2.0-dev <none> <none> (no description available)
#
# package installed with output as:
# ii libglib2.0-dev:amd64 2.64.6-1~ubuntu20.04.7 amd64 Development files for the GLib library
#
pkg_state=`dpkg -l $pkg_name | grep -w $pkg_name | awk '{print $1}'`
if [ "$pkg_state" == "ii" ]
then
echo found package \'$pkg_name\'
return 0
else
echo found package \'$pkg_name\' uninstalled
echo please run \'sudo apt install $pkg_name\' to install package
return 1
fi
fi
}
check_rpm_pkg() {
# get package name
pkg_name=$1
rpm -q $pkg_name 1> /dev/null 2>&1
if [ "$?" -ne 0 ]
then
echo package \'$pkg_name\' not found
echo please run \'sudo yum install $pkg_name\' to install package
return 1
else
echo found package \'$pkg_name\'
return 0
fi
}
uname -a | grep -i ubuntu 1> /dev/null 2>&1
is_ubuntu=$?
if [ $is_ubuntu -eq 0 ]
then
pkgs_dep=("automake" "autoconf" "make" "gcc" "g++" "libjemalloc-dev" "libglib2.0-dev" "mysql-server" "libmysqlclient-dev" "bison" "libattr1-dev" "libtool-bin" "rpm")
for pkg_name in ${pkgs_dep[@]};
do
echo check if \'$pkg_name\' installed
check_deb_pkg "$pkg_name"
if [ "$?" -ne 0 ]
then
# install package which not installed
apt install "$pkg_name" -y
# if failed to install package, quit
if [ "$?" -ne 0 ]
then
echo failed to install $pkg_name
exit 1
fi
fi
done
else
# yum based system, RHEL/almaLinux/CentOS/openEuler
which yum 1> /dev/null 2>&1
if [ "$?" -eq 0 ]
then
pkgs_dep=("automake" "autoconf" "make" "gcc" "gcc-c++" "glib2-devel" "libattr-devel" "mariadb-devel" "bison" "flex" "libtool" "rpm-build")
for pkg_name in ${pkgs_dep[@]};
do
echo check if \'$pkg_name\' installed
check_rpm_pkg "$pkg_name"
if [ "$?" -ne 0 ]
then
# install package which not installed
yum install "$pkg_name" -y
# if failed to install package, quit
if [ "$?" -ne 0 ]
then
echo failed to install $pkg_name
exit 1
fi
fi
done
else
echo -e "\033[31mcannot get os-release\033[0m"
echo manual copy robinhood.spec.in.ubuntu or robinhood.spec.in.rhel to robinhood.spec.in
rm -f $wdir/robinhood.spec.in 1> /dev/null 2>&1
exit 1
fi
fi
wdir=$(dirname $(readlink -m "$0"))
if [ $is_ubuntu -eq 0 ]
then
# prepare robinhood.spec.in file for build in ubuntu
cp $wdir/robinhood.spec.in.ubuntu $wdir/robinhood.spec.in
else
# prepare robinhood.spec.in file for build in RHEL/CentOS/AlmaLinux/openEuler
cp $wdir/robinhood.spec.in.rhel $wdir/robinhood.spec.in
fi
exit 0