-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathinstall_os_prereq.sh
More file actions
executable file
·71 lines (59 loc) · 1.9 KB
/
install_os_prereq.sh
File metadata and controls
executable file
·71 lines (59 loc) · 1.9 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
#!/bin/bash
source ./common_funcs.sh
check_root
PYTHON_VERSION=$1
# check appname was supplied as argument
if [ "$PYTHON_VERSION" == "" ]; then
echo "Usage:"
echo " $ install_os_prereq.sh [python-version]"
echo
echo " Python version is 2 or 3 and defaults to 3 if not specified. Subversion"
echo " of Python will be determined during runtime. The required Python version"
echo " has to be installed and available globally."
echo
exit 1
fi
# Default python version to 3. OS has to have it installed.
if [ "$PYTHON_VERSION" == "" ]; then
PYTHON_VERSION=3
fi
if [ "$PYTHON_VERSION" != "3" -a "$PYTHON_VERSION" != "2" ]; then
error_exit "Invalid Python version specified. Acceptable values are 2 or 3 (default)"
fi
# Prerequisite standard packages. If any of these are missing,
# script will attempt to install it. If installation fails, it will abort.
if [ "$PYTHON_VERSION" == "3" ]; then
PIP="pip3"
LINUX_PREREQ=('git' 'build-essential' 'python3-dev' 'python3-pip' 'nginx' 'postgresql' 'libpq-dev' )
else
PIP="pip"
LINUX_PREREQ=('git' 'build-essential' 'python-dev' 'python-pip' 'nginx' 'postgresql' 'libpq-dev')
fi
PYTHON_PREREQ=('virtualenv' 'supervisor')
# Test prerequisites
echo "Checking if required packages are installed..."
declare -a MISSING
for pkg in "${LINUX_PREREQ[@]}"
do
echo "Installing '$pkg'..."
apt-get -y install $pkg
if [ $? -ne 0 ]; then
echo "Error installing system package '$pkg'"
exit 1
fi
done
for ppkg in "${PYTHON_PREREQ[@]}"
do
echo "Installing Python package '$ppkg'..."
$PIP install $ppkg
if [ $? -ne 0 ]; then
echo "Error installing python package '$ppkg'"
exit 1
fi
done
if [ ${#MISSING[@]} -ne 0 ]; then
echo "Following required packages are missing, please install them first."
echo ${MISSING[*]}
exit 1
fi
echo "All required packages have been installed!"