-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·142 lines (107 loc) · 4.52 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
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
#!/bin/bash
# TODO: Add Nginx support
# TODO: Create log folder /var/log/open-cr
# use `fuser -k 8080/tcp` to kill the process on port 8080
# Open-CR CONSTANTS
CLAVE_ADDRESS=localhost
CLAVE_PORT=5777
CLAVE_CERT_DIR=/tmp/
CLAVE_INSTALL_DIR=/var/local/Open-CR/
CLAVE_SECRET="$(head -c 48 /dev/urandom | base64)"
CLAVE_MODULE_DIR=${CLAVE_INSTALL_DIR}/backend/modules/
# CouchDB CONSTANTS
INSTALL_COUCHDB=true
COUCHDB_USER=admin
COUCHDB_ADDRESS=localhost
COUCHDB_PORT=5984
COUCHDB_PASS="$(head -c 48 /dev/urandom | base64)" # Create a randomized password for the CouchDB server
COUCHDB_DIR_ARCH=/etc/couchdb/
COUCHDB_DIR_DEB=/opt/couchdb/etc/
COUCHDB_DIR_RASP=/home/couchdb/etc/
if [ ! -d "$CLAVE_INSTALL_DIR" ]; then
mkdir $CLAVE_INSTALL_DIR
fi
# Configure CouchDB
if [ $INSTALL_COUCHDB == "true" ]; then
printf "**** Configuring CouchDB ****\n\n"
# Set Local variables
couchdb_dir=""
couchdb_installed=false
# Configure CouchDB depending on OS
OS="$(cat /etc/os-release | grep ^NAME | sed 's/NAME=//g' | sed 's/"//g')"
if [ "$OS" == "Arch Linux" ]; then
# Check if CouchDB is installed
if [ ! -d $COUCHDB_DIR_ARCH ]; then
printf "**** Installing CouchDB ****\n\n"
sudo pacman -Sy couchdb
fi
couchdb_dir=$COUCHDB_DIR_ARCH
couchdb_installed=true
elif [ "$OS" == "Ubuntu" ] || [ "$OS" == "Debian GNU/Linux" ]; then
if [ ! -d $COUCHDB_DIR_DEB ]; then
"**** Installing CouchDB ****\n\n"
curl -L https://couchdb.apache.org/repo/bintray-pubkey.asc | sudo apt-key add -
echo "deb https://apache.bintray.com/couchdb-deb focal main" | sudo tee -a /etc/apt/sources.list
sudo apt update && sudo apt install couchdb
fi
couchdb_dir=$COUCHDB_DIR_DEB
couchdb_installed=true
elif [ "$OS" == "Raspbian GNU/Linux" ]; then
if [ ! -d $COUCHDB_DIR_RASP ]; then
# Install CouchDB
sudo ./CouchDB.sh
fi
couchdb_dir=$COUCHDB_DIR_RASP
sudo cp ./configuration/couchdb.service /lib/systemd/system/
couchdb_installed=true
fi
if [ $couchdb_installed == "true" ]; then
printf "${COUCHDB_USER} = ${COUCHDB_PASS}" | sudo tee -a $couchdb_dir/local.ini > /dev/null
# Create log file directory
if [ ! -d "/var/log/couchdb/" ]; then
mkdir /var/log/couchdb/
fi
sudo chown couchdb:couchdb /var/log/couchdb
# Enable CouchDB as a service
sudo systemctl daemon-reload
sudo systemctl enable couchdb.service
sudo systemctl start couchdb.service
else
printf "Your Operating System is currently Unsupported. Please Install CouchDB Manually"
printf "Follow the same instructions found in the README regarding pre-installed CouchDB"
exit # Exit the installation so user can install CouchDB
fi
fi
# Save the backend configuration
cp ./configuration/backend.env.json ./backend/.env.json
sed -i "s|\$CLAVE_ADDRESS|$CLAVE_ADDRESS|" ./backend/.env.json
sed -i "s|\$CLAVE_PORT|$CLAVE_PORT|" ./backend/.env.json
sed -i "s|\$CLAVE_CERT_DIR|$CLAVE_CERT_DIR|" ./backend/.env.json
sed -i "s|\$CLAVE_SECRET|$CLAVE_SECRET|" ./backend/.env.json
sed -i "s|\$MODULE_DIR|$CLAVE_MODULE_DIR|" ./backend/.env.json
sed -i "s|\$DB_USER|$COUCHDB_USER|" ./backend/.env.json
sed -i "s|\$DB_PASS|$COUCHDB_PASS|" ./backend/.env.json
sed -i "s|\$DB_PORT|$COUCHDB_PORT|" ./backend/.env.json
sed -i "s|\$DB_ADDRESS|$COUCHDB_ADDRESS|" ./backend/.env.json
# Save the frontend configuration
cp ./configuration/frontend.env ./frontend/.env
sed -i "s|\$CLAVE_ADDRESS|$CLAVE_ADDRESS|" ./frontend/.env
sed -i "s|\$CLAVE_PORT|$CLAVE_PORT|" ./frontend/.env
# Python Dependencies installation
sudo pip3 install -r ./requirements.txt
# Frontend Dependencies
cd frontend && npm install && cd ..
# TODO: Build the frontend portion and export it instead of the code
# TODO: Generate a server certificate so connections are secured
# # Move website files and folders to installation location
# sudo cp -r ./backend/ $INSTALL_DIR
# sudo cp -r ./frontend/ $INSTALL_DIR
# # Configure Gunicorn
# sudo rm /etc/systemd/system/gunicorn.service
# sudo cp ./configuration/gunicorn.service && sed -i "s|\$INSTALL_DIR|$INSTALL_DIR|" ./gunicorn.service
# sudo mv ./gunicorn.service /etc/systemd/system/
# # Enable and Run Gunicorn
# sudo systemctl enable gunicorn.service
# sudo systemctl start gunicorn.service
# Finished!
printf "\n\n******* Installion Finished!! Please Restart Your System for Open-CR to Run! *******\n\n"