-
Notifications
You must be signed in to change notification settings - Fork 400
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·219 lines (195 loc) · 6.39 KB
/
install.sh
File metadata and controls
executable file
·219 lines (195 loc) · 6.39 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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
#!/bin/bash
current_folder=`pwd`
relative_script_parent_path=`dirname $0`
if [ ${relative_script_parent_path:0:1} = "/" ]; then
cwd=$relative_script_parent_path
else
cwd=$current_folder/$relative_script_parent_path
fi
pypi_path=file://$cwd/../../../static/pypi/simple
usage() {
echo "usage:$0 [zstack-cli|zstack-ctl|zstack-dashboard|zstack-ui]"
exit 1
}
tool=$1
force=$2
if [ -z $tool ]; then
usage
fi
install_pip() {
pip --version | grep 7.0.3 >/dev/null || easy_install -i $pypi_path --upgrade pip
}
install_virtualenv() {
virtualenv --version | grep 12.1.1 >/dev/null || pip install -i $pypi_path --ignore-installed virtualenv==12.1.1
}
cd $cwd
install_pip
install_virtualenv
cd /tmp
if [ $tool = 'zstack-cli' ]; then
CLI_VIRENV_PATH=/var/lib/zstack/virtualenv/zstackcli
[ ! -z $force ] && rm -rf $CLI_VIRENV_PATH
if [ ! -d "$CLI_VIRENV_PATH" ]; then
virtualenv $CLI_VIRENV_PATH --python=python2.7
if [ $? -ne 0 ]; then
rm -rf $CLI_VIRENV_PATH
exit 1
fi
fi
. $CLI_VIRENV_PATH/bin/activate
cd $cwd
pip install -i $pypi_path --trusted-host localhost --ignore-installed zstackcli-*.tar.gz apibinding-*.tar.gz
if [ $? -ne 0 ]; then
rm -rf $CLI_VIRENV_PATH
exit 1
fi
pip show zstacklib
if [ $? -ne 0 ]; then
# fresh install zstacklib
echo "Installing zstacklib..."
pip install -i $pypi_path --trusted-host localhost --ignore-installed zstacklib-*.tar.gz
if [ $? -ne 0 ]; then
rm -rf $CLI_VIRENV_PATH
exit 1
fi
else
# upgrade zstacklib
echo "Upgrading zstacklib..."
pip install -U -i $pypi_path --trusted-host localhost zstacklib-*.tar.gz
if [ $? -ne 0 ]; then
rm -rf $CLI_VIRENV_PATH
exit 1
fi
fi
chmod +x /usr/bin/zstack-cli
elif [ $tool = 'zstack-ctl' ]; then
CTL_VIRENV_PATH=/var/lib/zstack/virtualenv/zstackctl
rm -rf $CTL_VIRENV_PATH && virtualenv $CTL_VIRENV_PATH --python=python2.7 || exit 1
. $CTL_VIRENV_PATH/bin/activate
cd $cwd
pip install -i $pypi_path --trusted-host localhost --ignore-installed zstackctl-*.tar.gz || exit 1
pip install -i $pypi_path --trusted-host localhost --ignore-installed pycrypto==2.6.1 || exit 1
chmod +x /usr/bin/zstack-ctl
python $CTL_VIRENV_PATH/lib/python2.7/site-packages/zstackctl/generate_zstackctl_bash_completion.py
elif [ $tool = 'zstack-sys' ]; then
SYS_VIRENV_PATH=/var/lib/zstack/virtualenv/zstacksys
NEED_INSTALL=false
if [ -d $SYS_VIRENV_PATH ]; then
. $SYS_VIRENV_PATH/bin/activate
if ! ansible --version | grep -q 'core 2.11.12.3'; then
deactivate
NEED_INSTALL=true
fi
else
NEED_INSTALL=true
fi
if $NEED_INSTALL; then
rm -rf $SYS_VIRENV_PATH && virtualenv $SYS_VIRENV_PATH --python=python2.7 || exit 1
. $SYS_VIRENV_PATH/bin/activate
cd $cwd
pip install -i $pypi_path --trusted-host localhost --ignore-installed setuptools==39.2.0 || exit 1
pip install -i $pypi_path --trusted-host localhost --ignore-installed ansible==4.10.0 || exit 1
cat > /usr/bin/ansible << EOF
#! /bin/sh
VIRTUAL_ENV=/var/lib/zstack/virtualenv/zstacksys
if [ ! -d $VIRTUAL_ENV ]; then
echo "Need to install zstacksys before using it"
exit 1
fi
LANG=en_US.UTF-8
LC_ALL=en_US.utf8
export LANG LC_ALL
. ${VIRTUAL_ENV}/bin/activate
ansible \$@
EOF
chmod +x /usr/bin/ansible
cat > /usr/bin/ansible-playbook << EOF
#! /bin/sh
VIRTUAL_ENV=/var/lib/zstack/virtualenv/zstacksys
if [ ! -d $VIRTUAL_ENV ]; then
echo "Need to install zstacksys before using it"
exit 1
fi
LANG=en_US.UTF-8
LC_ALL=en_US.utf8
export LANG LC_ALL
. ${VIRTUAL_ENV}/bin/activate
ansible-playbook \$@
EOF
chmod +x /usr/bin/ansible-playbook
fi
elif [ $tool = 'zstack-dashboard' ]; then
UI_VIRENV_PATH=/var/lib/zstack/virtualenv/zstack-dashboard
[ ! -z $force ] && rm -rf $UI_VIRENV_PATH
if [ ! -d "$UI_VIRENV_PATH" ]; then
virtualenv $UI_VIRENV_PATH --python=python2.7
if [ $? -ne 0 ]; then
rm -rf $UI_VIRENV_PATH
exit 1
fi
fi
. $UI_VIRENV_PATH/bin/activate
cd $cwd
pip show versiontools
if [ $? -ne 0 ]; then
# fresh install versiontools
echo "Installing versiontools..."
pip install -i $pypi_path --trusted-host localhost versiontools
if [ $? -ne 0 ]; then
rm -rf $UI_VIRENV_PATH
exit 1
fi
else
# upgrade versiontools
echo "Upgrading versiontools..."
pip install -U -i $pypi_path --trusted-host localhost versiontools
if [ $? -ne 0 ]; then
rm -rf $UI_VIRENV_PATH
exit 1
fi
fi
pip show zstack-dashboard
if [ $? -ne 0 ]; then
#fresh install zstack_dashboard
echo "Installing zstack_dashboard..."
pip install -i $pypi_path --trusted-host localhost --upgrade zstack_dashboard-*.tar.gz
if [ $? -ne 0 ]; then
rm -rf $UI_VIRENV_PATH
exit 1
fi
else
#upgrae zstack_dashboard
echo "Upgrading zstack_dashboard..."
pip install -U -i $pypi_path --trusted-host localhost --upgrade zstack_dashboard-*.tar.gz
if [ $? -ne 0 ]; then
rm -rf $UI_VIRENV_PATH
exit 1
fi
fi
chmod +x /etc/init.d/zstack-dashboard
elif [ x"$tool" = x"zstack-ui" ]; then
cd "$cwd"
default_zstack_home='/usr/local/zstack/'
default_ui_home="$default_zstack_home"/zstack-ui/
zstack_home=$(echo ~zstack)
zstack_home=${zstack_home%/}/
ui_home="$zstack_home"/zstack-ui/
mkdir -p "$ui_home"
# Assume:
# - zstack installed in /usr/local/zstacktest
# - zstack-ui installed in /usr/local/zstack/zstack-ui
# After upgrade, zstack-ui will be installed in /usr/local/zstacktest/zstack-ui.
# We need to copy old ui config and certification files back
if [ ! -f "$ui_home"/zstack-ui.war -a -f "$default_ui_home"/zstack-ui.war ]; then
cp -rf "$default_ui_home"/* "$ui_home"
sed -i "s|$default_zstack_home|$zstack_home|g" "$ui_home"/zstack.ui.properties
fi
cp -f zstack-ui.war "$ui_home"
rm -rf "$ui_home"/tmp
unzip zstack-ui.war -d "$ui_home"/tmp
cp -f zstack-ui /etc/init.d/
chmod a+x /etc/init.d/zstack-ui
chown -R zstack:zstack "$ui_home"
else
usage
fi