-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall_refstack.sh
More file actions
executable file
·125 lines (104 loc) · 4.87 KB
/
install_refstack.sh
File metadata and controls
executable file
·125 lines (104 loc) · 4.87 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
#!/bin/bash
# ==============================================================================
# Script installs and configure a refstack server (UI and API):
# See: https://github.com/openstack/refstack/blob/master/doc/source/refstack.rst
# ==============================================================================
# Comment the following line to stop debugging this script
# set -o xtrace
# Comment the following like to stop script on failure (Fail fast)
# set -e
#=================================================
# GLOBAL DEFINITION
#=================================================
_PASSWORD='secure123'
_DEST_PATH='/opt/refstack'
[[ ! -f common_functions ]] && wget https://raw.githubusercontent.com/dlux/InstallScripts/master/common_functions
source common_functions
# ======================= Processes installation options =====================
while [[ ${1} ]]; do
case "${1}" in
--password|-p)
if [[ -z "${2}" || "${2}" == -* ]]; then
PrintError "Missing password."
else
_PASSWORD="${2}"
fi
shift
;;
--help|-h)
PrintHelp "Install refstack server " $(basename "$0") " --password | -p Password to be used on the DB."
;;
*)
HandleOptions "$@"
shift
esac
shift
done
# ==================================== Install Dependencies ===================
EnsureRoot
SetLocale /root
umask 022
# If proxy is set on the env - expand it
[[ -n $http_proxy ]] && SetProxy $http_proxy
# If proxy passed as parameter - set it on the VENV
[[ -n $_PROXY ]] && source ".PROXY"
[[ ! -f install_devtools.sh ]] && wget https://raw.githubusercontent.com/dlux/InstallScripts/master/install_devtools.sh
[[ -z "${_ORIGINAL_PROXY}" ]] && ./install_devtools.sh || ./install_devtools.sh -x $_ORIGINAL_PROXY
apt-get install -y python-setuptools python-mysqldb
debconf-set-selections <<< "mysql-server mysql-server/root_password password ${_PASSWORD}"
debconf-set-selections <<< "mysql-server mysql-server/root_password_again password ${_PASSWORD}"
apt-get install -q -y mysql-server
curl -sL https://deb.nodesource.com/setup_4.x | bash -
apt-get install -y nodejs
# ======================================= Setup Database ======================
mysql -uroot -p"${_PASSWORD}" <<MYSQL_SCRIPT
CREATE DATABASE refstack;
CREATE USER 'refstack'@'localhost' IDENTIFIED BY '$_PASSWORD';
GRANT ALL PRIVILEGES ON refstack . * TO 'refstack'@'localhost';
FLUSH PRIVILEGES;
MYSQL_SCRIPT
# ======================================= Setup Refstack ======================
caller_user=$(who -m | awk '{print $1;}')
caller_user=${caller_user:-'ubuntu'}
host="$(hostname)"
domain="$(hostname -d)"
[[ -n "${domain}" ]] && fqdn="$host.$domain" || fqdn="$host"
# Install refstack client - Shorter task
echo "INSTALLING REFSTACK CLIENT"
refclient="$_DEST_PATH-client"
[[ ! -d "$refclient" ]] && git clone http://github.com/openstack/refstack-client $refclient
chown -R $caller_user $refclient
pushd $refclient
sudo -HE -u $caller_user bash -c "./setup_env"
popd
echo "INSTALLING REFSTACK SERVER, API AND UI"
[[ ! -d "$_DEST_PATH" ]] && git clone http://github.com/openstack/refstack $_DEST_PATH
chown -R $caller_user $_DEST_PATH
pushd $_DEST_PATH
sudo -HE -u $caller_user bash -c 'virtualenv .venv --system-site-package; source .venv/bin/activate; pip install .; pip install pymysql; pip install gunicorn'
sudo -HE -u $caller_user bash -c 'npm install'
sudo -HE -u $caller_user bash -c 'cp etc/refstack.conf.sample etc/refstack.conf'
# Generate local about page documentation
echo "Generate HTML templates from docs"
sudo -HE -u $caller_user bash -c "source .venv/bin/activate; python tools/convert-docs.py -o refstack-ui/app/components/about/templates doc/source/*.rst"
sed -i "s/#connection = <None>/connection = mysql+pymysql\:\/\/refstack\:$_PASSWORD\@localhost\/refstack/g" etc/refstack.conf
sed -i "/ui_url/a ui_url = http://$fqdn:8000" etc/refstack.conf
sed -i "/api_url/a api_url = http://$fqdn:8000" etc/refstack.conf
sed -i "/app_dev_mode/a app_dev_mode = true" etc/refstack.conf
sed -i "/debug = false/a debug = true" etc/refstack.conf
sudo -HE -u $caller_user bash -c 'cp refstack-ui/app/config.json.sample refstack-ui/app/config.json'
sed -i "s/refstack.openstack.org\/api/$fqdn:8000/g" refstack-ui/app/config.json
# DB SYNC IF VERSION IS None
source .venv/bin/activate
if [[ ! -z $(refstack-manage --config-file etc/refstack.conf version | grep -i none) ]];then
refstack-manage --config-file etc/refstack.conf upgrade --revision head
# Verify upgrade actually happened
msg="After sync DB, version is still displayed as None."
[[ ! -z $(refstack-manage --config-file etc/refstack.conf version | grep -i none) ]] && PrintError $msg
fi
popd
echo "Starting Refstack Server. Run next daemon on screen session."
echo "refstack-api --env REFSTACK_OSLO_CONFIG=etc/refstack.conf"
echo "Finished Installation Script"
# Cleanup _proxy from apt if added - first coincedence
UnsetProxy $_ORIGINAL_PROXY