-
Notifications
You must be signed in to change notification settings - Fork 292
/
bootstrap
executable file
·148 lines (132 loc) · 4.31 KB
/
bootstrap
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#!/bin/bash
set -e
if [ $# -eq 0 ]; then
install=false
else
if [ "$1" = "install" ]; then
install=true
else
echo "Invalid command, supported commands are: 'install'"
exit 1
fi
fi
if [[ "$PYTHON" =~ "python2" ]]; then
echo "python2 is not supported." >&2
exit 1
fi
# Use the newest version we find
if [ -z "$PYTHON" ]; then
for i in 12 11 10; do
command -v "python3.$i" && PYTHON="python3.$i" &>/dev/null && break
done
fi
if [ -z "$PYTHON" ]; then
# This would be bizarre, but I suppose possible
PYTHON=${PYTHON:-"python3"}
fi
case "$(uname -s)" in
Linux)
if command -v lsb_release; then
OS=$(lsb_release --id --short)
else
. /etc/os-release
OS=$(echo $NAME | tr -d ' ')
fi
# rpm/dnf is the default, to reduce repetition in the case statement
has_pkg="rpm --whatprovides"
install_pkg="sudo dnf install -y"
case "$OS" in
Ubuntu|Debian|LinuxMint)
deps=(qemu-utils python3-dev libssl-dev python3-pip python3-wheel $PYTHON-venv libev-dev libvirt-dev libffi-dev libyaml-dev)
has_pkg="dpkg -C"
install_pkg="sudo apt install -y"
;;
RedHatEnterpriseWorkstation|RedHatEnterpriseServer|RedHatEnterprise|CentOS)
deps=(python39-pip python39-devel mariadb-devel libev-devel libvirt-devel libffi-devel)
;;
CentOSStream)
PYTHON=python3.12
deps=($PYTHON-pip $PYTHON-devel)
;;
AlmaLinux|RockyLinux)
PYTHON=python3.12
deps=($PYTHON-pip $PYTHON-devel libev-devel libvirt-devel libffi-devel)
;;
Fedora|FedoraLinux)
PYTHON=python3.12
deps=($PYTHON-pip $PYTHON-devel libev-devel libvirt-devel libffi-devel)
;;
"openSUSE project"|"SUSE LINUX"|"openSUSE"|"openSUSELeap"|"openSUSETumbleweed")
PYTHON=python3.12
deps=(python312-pip python312-devel python312 libev-devel libvirt-devel libffi-devel)
install_pkg="sudo zypper install"
;;
esac
;;
Darwin)
deps="python libvirt libev libffi"
has_pkg="brew list"
install_pkg="brew install"
;;
esac
for package in ${deps[@]}; do
if ! $has_pkg $package &>/dev/null; then
# add a space after old values
missing="${missing:+$missing }$package"
echo missing=${missing}
fi
done
if [ -n "$missing" ]; then
echo "$0: missing required packages:" 1>&2
echo "$missing"
if [ "$install" = true ]; then
echo "Installing missing packages..."
$install_pkg $missing
else
echo "Please install missing packages or run './bootstrap install'"
echo "$install_pkg $missing"
exit 1
fi
fi
PYTHON_BIN=$(command -v $PYTHON)
if [ -z $PYTHON_BIN -o ! -e $PYTHON_BIN -o ! -x $PYTHON_BIN ]; then
echo "Cannot find $PYTHON!"
exit 1
fi
PYTHON_VER_OUT=$($PYTHON_BIN --version)
VENV=${VENV:-"./virtualenv"}
# If the venv was set to use system site-packages, fix that
if [ -f "$VENV/pyvenv.cfg" ]; then
sed -i'' -e 's/\(include-system-site-packages\s*=\s*\)true/\1false/g' $VENV/pyvenv.cfg
fi
# Attempt to force a UTF-8 locale without being specific to English
export LANG=${LANG:-C.UTF-8}
(echo $LANG | grep -qi utf-8) || export LC_ALL=$LANG.UTF-8
if [ -z "$NO_CLOBBER" ] && \
[ ! -e "$VENV/bin/pip" -o ! -e "$VENV/bin/$PYTHON" ] || \
[ "${PYTHON_VER_OUT}" != "$($VENV/bin/$PYTHON --version)" ] \
; then
rm -rf virtualenv
fi
if [ -z "$NO_CLOBBER" ] || [ ! -e $VENV ]; then
$PYTHON_BIN -m venv $VENV
fi
$VENV/bin/pip install packaging
# It is impossible to upgrade ansible from 2.9 to 2.10 via pip.
# See https://docs.ansible.com/ansible/devel/porting_guides/porting_guide_2.10.html#known-issues
if [ -f "$VENV/bin/ansible" ]; then
uninstall_ansible=$($VENV/bin/python3 -c "import ansible; from packaging.version import parse; print(parse(ansible.__version__) < parse('2.10.0'))")
if [ "$uninstall_ansible" = "True" ]; then
$VENV/bin/pip uninstall -y ansible
fi
fi
# First, upgrade pip
$VENV/bin/pip install --upgrade pip
# See https://github.com/pypa/pip/issues/8559
$VENV/bin/pip install -r requirements.txt --use-pep517
# By default, install teuthology in editable mode
$VENV/bin/pip install ${PIP_INSTALL_FLAGS:---editable '.[test]'}
# Check to make sure requirements are met
$VENV/bin/pip check
# Install ansible collections
$VENV/bin/ansible-galaxy install -r requirements.yml