-
Notifications
You must be signed in to change notification settings - Fork 2
/
install.sh
85 lines (74 loc) · 2.53 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
#!/bin/bash
# This is a test script for installing NABS, I have not tested it to the end,
# if you have problems when running it, contact me.
# shellcheck disable=SC2164
cd "$(dirname "$0")"
VIRTUALENV="$(pwd -P)/venv"
PYTHON="${PYTHON:-python3}"
# Remove the existing virtual environment (if any)
if [ -d "$VIRTUALENV" ]; then
COMMAND="rm -rf ${VIRTUALENV}"
echo "Removing old virtual environment..."
eval $COMMAND
else
WARN_MISSING_VENV=1
fi
# Create a new virtual environment
COMMAND="${PYTHON} -m venv ${VIRTUALENV}"
echo "Creating a new virtual environment at ${VIRTUALENV}..."
eval $COMMAND || {
echo "--------------------------------------------------------------------"
echo "ERROR: Failed to create the virtual environment. Check that you have"
echo "the required system packages installed and the following path is"
echo "writable: ${VIRTUALENV}"
echo "--------------------------------------------------------------------"
exit 1
}
# Activate the virtual environment
source "${VIRTUALENV}/bin/activate"
# Upgrade pip
COMMAND="pip install --upgrade pip"
echo "Updating pip ($COMMAND)..."
eval $COMMAND || exit 1
pip -V
# Install necessary system packages
COMMAND="pip install wheel"
echo "Installing Python system packages ($COMMAND)..."
eval $COMMAND || exit 1
# Install required Python packages
COMMAND="pip install -r requirements.txt"
echo "Installing core dependencies ($COMMAND)..."
eval $COMMAND || exit 1
# Init DB
COMMAND="flask db init"
echo "Initialization DB($COMMAND)..."
eval $COMMAND || exit 1
# Migration DB
COMMAND="flask db migrate"
echo "Migration DB ($COMMAND)..."
eval $COMMAND || exit
# Upgrade DB
COMMAND="flask db upgrade"
echo "Upgrade DB ($COMMAND)..."
eval $COMMAND || exit
COMMAND="cp config_example.py config.py"
echo "Create config file ($COMMAND)..."
eval $COMMAND || exit
# Status massage
if [ -v WARN_MISSING_VENV ]; then
echo "--------------------------------------------------------------------"
echo "WARNING: No existing virtual environment was detected. A new one has"
echo "been created. Update your systemd service files to reflect the new"
echo "Python and gunicorn executables. (If this is a new installation,"
echo "this warning can be ignored.)"
echo ""
echo "nabs.service ExecStart:"
echo " ${VIRTUALENV}/bin/gunicorn"
echo ""
echo "nabs.service ExecStart:"
echo " ${VIRTUALENV}/bin/python"
echo ""
echo "After modifying these files, reload the systemctl daemon:"
echo " > systemctl daemon-reload"
echo "--------------------------------------------------------------------"
fi