-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathinstall.sh
More file actions
83 lines (67 loc) · 2.73 KB
/
install.sh
File metadata and controls
83 lines (67 loc) · 2.73 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
#!/usr/bin/env bash
# Use sudo here to prompt the password straight away
sudo echo "This script will install the DigitME2 OEE Server."
echo "Select the branch you want to download:"
PS3="Please enter your choice: "
options=("master (latest)" "production (stable)")
select opt in "${options[@]}"
do
case $opt in
"master (latest)")
branch="master"
break
;;
"production (stable)")
branch="production"
break
;;
*) echo "Invalid option $REPLY";;
esac
done
# Install requirements
echo "Installing apt packages..."
sudo apt-get update -qqq
sudo apt-get install -qq -y git npm redis virtualenv nginx > /dev/null
echo "Downloading from github..."
git clone https://github.com/DigitME2/oee_server.git ~/oee_server --quiet --branch $branch --depth=1
cd ~/oee_server
# Copy default config
cp ./example-confs/config.example.py config.py
# Change the secret key to a random string
SECRET_KEY=$(echo $RANDOM | md5sum | head -c 20)
sed -i "s/change-this-secret-key/$SECRET_KEY/g" config.py
# install npm package in /app/static
echo "Running npm install..."
npm --prefix ./app/static install ./app/static
# Set up virtual environment
echo "Creating python virtual environment..."
virtualenv --quiet venv
./venv/bin/pip install --quiet -r requirements.txt
# install gunicorn
./venv/bin/pip install gunicorn
# Set up database
./venv/bin/python3 setup_database.py
# Copy systemd files
echo "Configuring systemd services..."
sudo cp ./example-confs/oee_server.service /etc/systemd/system
sudo cp ./example-confs/oee_discovery.service /etc/systemd/system
sudo cp ./example-confs/oee_scheduler.service /etc/systemd/system
# Edit default values (user, working directory) in example systemd files
sudo sed -i 's&(USERNAME)&'$USER'&g' /etc/systemd/system/oee_server.service /etc/systemd/system/oee_scheduler.service /etc/systemd/system/oee_discovery.service
sudo sed -i 's&/home/user/oee_server&'$PWD'&g' /etc/systemd/system/oee_server.service /etc/systemd/system/oee_scheduler.service /etc/systemd/system/oee_discovery.service
# Enable & start services
sudo systemctl daemon-reload
sudo systemctl enable oee_server oee_discovery oee_scheduler
sudo systemctl start oee_server oee_discovery oee_scheduler
# Set up Nginx
echo "Setting up Nginx..."
sudo unlink /etc/nginx/sites-enabled/default
sudo cp ./example-confs/nginx-conf-example /etc/nginx/sites-available/oee-server
sudo sed -i 's&/home/user/oee_server&'$PWD'&g' /etc/nginx/sites-available/oee-server
sudo ln -s /etc/nginx/sites-available/oee-server /etc/nginx/sites-enabled
sudo nginx -t
sudo nginx -s reload
sudo ufw allow 'Nginx Full'
# Stamp database with version for flask-migrate
.venv/bin/flask db stamp head
echo "Installation Finished"