-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
81 lines (64 loc) · 2.14 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
#!/bin/bash
echo "Prepare python environment"
set -xe
if [[ -z `which virtualenv` ]]; then
sudo python3 -m pip install virtualenv
fi
if [[ -z `which virtualenv` ]]; then
virtualenv_exe=venv
else
if [[ -z `which venv` ]]; then
virtualenv_exe=virtualenv
else
virtualenv_exe="python3 -m virtualenv"
fi
fi
src_dir=`pwd`
opt_dir=/opt/botjagwar
current_user=`whoami`
# Create virtual environment
if [[ -d $opt_dir ]]; then
sudo rm -rf $opt_dir
fi
sudo mkdir -p $opt_dir
sudo chown $current_user $opt_dir
if [[ ! -d $opt_dir/pyenv ]]; then
set -e
$virtualenv_exe $opt_dir/pyenv
$virtualenv_exe $opt_dir/pyenv
source $opt_dir/pyenv/bin/activate
fi
cd "$src_dir"
python3 -m pip install -r requirements.txt
sudo mkdir -p $opt_dir/user_data
sudo cp -r $src_dir/api $opt_dir
sudo cp -r $src_dir/conf $opt_dir
sudo cp -r $src_dir/data $opt_dir
sudo cp -r $src_dir/scripts $opt_dir
sudo cp -r $src_dir/*.py $opt_dir
if [[ -z $TEST ]]; then
# Install dependencies if NOT in test mode
# this should allow for an increase of the speed-up regarding build time and is not needed
# anyway by the unit tests when in testing mode
sudo apt-get install -y haproxy
sudo cp conf/haproxy.cfg $opt_dir/conf/
sudo apt-get install -y supervisor
if [[ -d /etc/supervisor/conf.d ]]; then
sudo cp $src_dir/conf/supervisor-botjagwar.conf /etc/supervisor/conf.d/supervisor-botjagwar.conf
# replace current from a potentially privileged user down to a non-privileged one. Pywikibot user
# might be configured for the user and but not for the root user, as generally advised.
sudo sed -i "s/user=user/user=`whoami`/g" /etc/supervisor/conf.d/supervisor-botjagwar.conf
sudo sed -i "s/\/home\/user/\/home\/`whoami`/g" /etc/supervisor/conf.d/supervisor-botjagwar.conf
echo "Supervisor installation is complete. Reloading config"
sudo supervisorctl reload
fi
fi
if [[ ! -z $INSTALL_PG ]]; then
# Feature coming soon
echo "Automatic postgreSQL installation/configuration is currently not supported."
fi
if [[ ! -d ${opt_dir}/bin ]]; then
mkdir -p ${opt_dir}/bin
fi
cp bin/postgrest $opt_dir/bin
sudo chown `whoami`:`whoami` -R $opt_dir