-
Notifications
You must be signed in to change notification settings - Fork 244
/
Copy pathinstall.sh
executable file
·133 lines (113 loc) · 2.9 KB
/
install.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#!/bin/bash
set -e
set -o pipefail
shopt -s compat31
# Default python binary
PY_BINARY="${PY_BINARY:-python3}"
INSTALL_PYTHON="y"
# Taken from https://stackoverflow.com/a/14203146
OPTIND=1
while getopts "sp:" opt; do
case "$opt" in
p)
PY_BINARY=$OPTARG
;;
s)
INSTALL_PYTHON=n
;;
esac
done
shift $((OPTIND-1))
[ "${1:-}" = "--" ] && shift
#
# Run an OS-specific installer
#
# Not installed?
if ! [ -x "$(command -v $PY_BINARY)" ]; then
if [ "$(type -p apt-get)" ]
then
sudo apt-get update
[ "$INSTALL_PYTHON" == "y" ] && sudo apt-get install -y --reinstall ${PY_BINARY}
elif [ "$(type -p yum)" ]
then
if [ "$(type -p dnf)" ]
then
sudo dnf update -y
if [ ! "$(type -p lsb_release)" ]
then
sudo dnf install -y redhat-lsb-core
fi
if [ ! "$(type -p python3)" ]
then
[ "$INSTALL_PYTHON" == "y" ] && sudo dnf install -y python3
fi
else
sudo yum update -y
if [ ! "$(type -p lsb_release)" ]
then
sudo yum install -y redhat-lsb-core
fi
if [ ! "$(type -p python3)" ]
then
[ "$INSTALL_PYTHON" == "y" ] && sudo yum install -y python3
fi
fi
elif [ "$(uname -s)" = "Darwin" ]
then
[ "$INSTALL_PYTHON" == "y" ] && brew install $PY_BINARY
else
echo "install.sh: Unsupported OS: could not detect OS X, apt-get or yum." >&2
exit 1
fi
fi
# Confirm such a Python version is accessible
if ! [ -x "$(command -v $PY_BINARY)" ]; then
echo "Error: Could not find Python binary '$PY_BINARY'"
exit 1
fi
#
# Ensure current working directory is the parent directory of install.sh, i.e.
# <git_repo>/code. Taken from https://gist.github.com/josephwecker/2884332
#
function switch_to_basedir()
{
local dir="${BASH_SOURCE[0]}"
if [[ "$(uname -s)" == 'Darwin' ]]
then
local f="-f"
fi
while ([ -L "${dir}" ])
do
dir="$(readlink $f "$dir")"
done
cd "$(dirname "${dir}")"
if ! [ -f "install.sh" ]
then
echo "$0: Could not locate <git_repo>/code directory." >&2
exit 1
fi
}
switch_to_basedir
#
# Run an OS-specific installer
#
if [ "$(type -p apt-get)" ]
then
# source ./clean.sh
source ./_install-deb.sh $PY_BINARY ${INSTALL_PYTHON}
elif [ "$(type -p yum)" ] || [ "$(type -p dnf)" ]
then
source ./clean.sh
source ./_install-rhel.sh $PY_BINARY ${INSTALL_PYTHON}
elif [ "$(uname -s)" = "Darwin" ]
then
source ./clean.sh
source ./_install-mac.sh $PY_BINARY ${INSTALL_PYTHON}
elif [ "$(type -p zypper)" ]
then
source ./clean.sh
source ./_install-suse.sh $PY_BINARY ${INSTALL_PYTHON}
else
echo "install.sh: Unsupported OS: could not detect Mac, apt-get, yum or zypper." >&2
exit 1
fi