-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcheck_required_packages.sh
More file actions
132 lines (118 loc) · 3.92 KB
/
check_required_packages.sh
File metadata and controls
132 lines (118 loc) · 3.92 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
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
130
131
132
#!/bin/bash
set -euo pipefail
# Detects the OS distribution and version.
function identify_platform() {
platform="$(. /etc/os-release && echo "$ID")"
version_id="$(. /etc/os-release && echo "$VERSION_ID")"
major_version="${version_id%%.*}"
}
# Determines which packages are required based on the distribution or the external requirements file fed as input.
#
# Basic: Requirements needed for the distribution is checked if no input file is provided.
# Extensive: For extensive check for the release, the package requirements of the release corresponding to the linux distribution
# is fed as an argument to the script.
function get_required_packages() {
if [[ $# -gt 0 ]]; then
package_file=$1
required_packages="$(awk '{print $1}' $package_file)"
if [[ -z "$required_packages" ]]; then
echo "ERROR: could not parse required packages for $platform from $package_file"
exit 1
fi
return
fi
case "${platform,,}" in
"centos" | "rhel" | "rocky")
required_packages=('fontconfig' 'libX11' 'libxkbcommon-x11' 'xcb-util-renderutil' 'libglvnd-egl' 'libglvnd-opengl' 'libxkbcommon')
;;
"ubuntu")
required_packages=('fontconfig' 'libegl1' 'libopengl0' 'libxkbcommon0' 'libxcb-xinput0')
;;
*)
echo "WARNING: List of dependencies for distribution \"$platform\" is unknown."
echo "Please install libX11 and/or libfontconfig packages."
echo "List of supported platforms can be found at: https://www.schrodinger.com/supportedplatforms"
exit 1
;;
esac
}
# Selects the command according to the OS to check if a package is installed.
function check_if_package_installed() {
case "$platform" in
"ubuntu")
cmd="dpkg -s"
;;
"centos" | "rhel" | "rocky" | "sled" | "sles")
cmd="rpm -q"
;;
*)
echo "WARNING: package check command for distribution \"$platform\" is unknown."
;;
esac
}
# Determines the appropriate package manager according to the OS.
function get_package_manager() {
case "$platform" in
"centos" | "rhel" | "rocky")
package_manager="yum"
if [[ "$major_version" -gt 7 ]]; then
package_manager="dnf"
fi
;;
"ubuntu")
package_manager="apt-get"
;;
"sles" | "sled")
package_manager="zypper"
;;
*)
echo "WARNING: package manager for distribution \"$platform\" is unknown."
;;
esac
}
# Identifies if additional repositories (like EPEL) are needed
function get_extra_repos() {
extra_repos=()
case "$platform" in
"centos" | "rhel" | "rocky")
extra_repos+=("epel-release")
;;
*)
;;
esac
}
# Iterate through required packages and suggests how to install if missing.
function get_missing_package() {
missing_packages=()
for package in ${required_packages[@]}; do
if ! ($cmd $package); then
missing_packages+=($package)
fi
done
if [ ${#missing_packages[@]} -eq 0 ]; then
echo "Your machine has the required packages."
else
echo "(${missing_packages[@]}) is/are required package/s to use Schrödinger suite. Please install them using:"
if [ ${#extra_repos[@]} -gt 0 ]; then
echo -e "\tsudo $package_manager install ${extra_repos[@]}"
fi
echo -e "\tsudo $package_manager install ${missing_packages[@]}"
exit 1
fi
}
## Main execution
# Identify the platform and version
identify_platform
if [[ -z "$platform" ]]; then
echo "ERROR: This system couldn't be identified."
exit 1
else
echo "INFO: This system was identified as \"$platform\"."
fi
# Get the required packages for the platform and check if they are installed
get_required_packages "$@"
check_if_package_installed
get_package_manager
get_extra_repos
echo -e "required_packages for your platform are: \n${required_packages[@]}"
get_missing_package