forked from AlloSphere-Research-Group/AlloSystem
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install_all_dependencies.sh
executable file
·87 lines (68 loc) · 2.17 KB
/
install_all_dependencies.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
#!/bin/sh
# Modules with dependency files.
modules="allocore allocv allonect alloutil examples/mysql"
# Override if module are passed in as arguments.
if [ "$#" -gt 0 ]; then
modules="$*"
fi
ROOT=`pwd`
PLATFORM=`uname`
ARCH=`uname -m`
echo "Installing for ${PLATFORM} ${ARCH} from ${ROOT}"
# Callbacks.
binary_exists(){
command -v "$1" >/dev/null 2>&1;
}
files_exist(){
ls -u "$@" >/dev/null 2>&1;
}
# Prepend redirection to apply to entire piped command.
is_callback(){
type "$1" 2>/dev/null | grep -i 'function' >/dev/null 2>&1;
}
# package_manager: used to pick correct dependency lists and callbacks.
if binary_exists 'apt-get'; then
package_manager='apt'
sudo apt-get update
installer="sudo apt-get install"
# Homebrew is the preferred Mac package manager of the AlloTeam.
elif binary_exists 'brew'; then
package_manager='brew'
brew update
installer="brew install"
elif binary_exists 'port'; then
package_manager='port'
sudo port selfupdate
installer="sudo port install"
# Only MSYS2 is supported on Windows due to the presence of a package manager.
elif uname | grep 'MINGW' > /dev/null 2>&1; then
if binary_exists 'pacman'; then
package_manager='pacman'
arch="$(uname -m)"
pacman -Syy
installer='pacman -S'
fi
else
echo 'Error: No suitable package manager found.'
echo 'Error: Install Apt, Homebrew, MacPorts, or MSYS2 and try again.'
fi
# Path to this script.
appended_relative=$(dirname "$0" ; echo x)
sanitized_relative=${appended_relative%??}
appended_absolute="$( cd "$sanitized_relative" && pwd; echo x)"
sanitized_absolute=${appended_absolute%??}
for module in $modules; do
# Source the variables and callbacks of each module.
eval ". $sanitized_absolute/${module}/dependencies"
# Workaround for embedded scripts like examples/mysql.
module="$(basename "$module")"
# Append dependencies of each module to install_list.
module_packages="${module}_${package_manager}"
eval "install_list=\"${install_list} \$${module_packages}\""
# Run callback if it exists.
if is_callback "${module_packages}_callback"; then
eval "${module_packages}_callback"
fi
done
# Install contatenated dependency list.
exec $installer $install_list