Blame view

install/install_requirements.sh 4.35 KB
6101568a   haribo   Improved install_...
1
2
#!/bin/bash

31929284   haribo   install script im...
3
4
5
# prevent globbing interpreting (for SQL_SCRIPT variable)
set -f

6101568a   haribo   Improved install_...
6
7
PYTHON='python3.5'
INSTALL_DIR='install'
42eb7d4d   carens_p   venv_py3 instead ...
8
VENV_NAME="venv_py3_pyros"
6101568a   haribo   Improved install_...
9

31929284   haribo   install script im...
10
11
12
13
USERNAME="root"

DB_USER="pyros"
DB_PASSWORD="DjangoPyros"
97b042a0   Microaster   Changed installat...
14
MYSQL=0
31929284   haribo   install script im...
15

a046fe99   haribo   Message at the en...
16
17
PORT=8000

6101568a   haribo   Improved install_...
18
19
# String variables

9b5bad52   haribo   Commented all the...
20
ASK_USE_MYSQL="-Do you wish to use mysql in your project ? Only if mysql-server is installed. (Default: No) (Y/N)"
ae543d0a   carens_p   test mysql
21
ASK_MYSQL_USERNAME="-MySQL server login (default $USERNAME): "
ad5a0b45   haribo   Fix privileges on...
22
SQL_SCRIPT="CREATE DATABASE IF NOT EXISTS pyros; GRANT USAGE ON *.* TO '$DB_USER'; DROP USER '$DB_USER'; GRANT ALL ON pyros.* TO '$DB_USER'@'localhost' IDENTIFIED BY '$DB_PASSWORD'; GRANT ALL ON test_pyros.* TO '$DB_USER'@'localhost'"
31929284   haribo   install script im...
23
24
25
26
SQL_FAIL="-Failed to execute database script, probably due to a wrong username or password"
TELL_MYSQL_CREATIONS="-Created pyros database.\n-Created new user '$DB_USER' with password '$DB_PASSWORD'"
USE_SQLITE="-Sqlite will be used by default. There is no required configuration."

6101568a   haribo   Improved install_...
27
28
29
30
31
32
WRONG_DIRECTORY="-Wrong directory : please run this script from the '$INSTALL_DIR' directory"
PRIVATE_DIR_CREATE="-Created 'private' directory"
PYTHON_NOT_INSTALLED="-Cannot find $PYTHON, please install it or configure PYTHON variable in this script"
PYTHON_FOUND="-Found $PYTHON at"
VENV_CREATE="-Creating virtualenv $VENV_NAME... "
VENV_ACTIVATE="-Activating virtual environment... "
31929284   haribo   install script im...
33
VENV_FAIL="-Failed to activate virtualenv. Ask project administrators for further information"
6101568a   haribo   Improved install_...
34
35
36
37
DONE="done."
UPGRADE_PIP="-Upgrading pip:"
UPGRADE_WHEEL="-Upgrading wheel:"
INSTALL_PACKAGES="-Installing required packages from install/REQUIREMENTS.txt"
31929284   haribo   install script im...
38
CREATE_DATABASE_CONTENT="-Creating database tables :"
6101568a   haribo   Improved install_...
39
CREATE_SUPERUSER="-Creating database superuser :"
31929284   haribo   install script im...
40
CREATE_SUPERUSER_SCRIPT="from django.contrib.auth.models import User; User.objects.filter(username='$DB_USER').delete(); User.objects.create_superuser('$DB_USER', 'admin@example.com', '$DB_PASSWORD')"
6101568a   haribo   Improved install_...
41
INSTALLATION_FINISHED="-Installation finished"
609eb83d   haribo   Improved install_...
42
BAD_SQL_CONFIGURATION="-Migration cannot be applied to the database : check your database configuration, or use sqlite instead"
97b042a0   Microaster   Changed installat...
43
TELL_SUPERUSER_CREATION="-Superuser created for django admin interface. Login: $DB_USER , password: $DB_PASSWORD"
1cf0d0fc   haribo   Date: 26/05/2016
44
MAKE_MIGRATIONS="-Make migrations for DB models"
a046fe99   haribo   Message at the en...
45
FINAL_MESSAGE="-Please run './pyrosrun server' then go to localhost:$PORT/admin and log in with these id"
6101568a   haribo   Improved install_...
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62

# Getting python location
PYTHON_DIR=`which $PYTHON`
if [ $? -ne 0 ]; then
    echo $PYTHON_NOT_INSTALLED
    exit
fi
echo $PYTHON_FOUND $PYTHON_DIR

# Getting current path to test if we are in the install directory
CURRENT_PATH=`pwd`
CURRENT_PATH=${CURRENT_PATH##*/}

if [ "$CURRENT_PATH" != $INSTALL_DIR ]; then
    echo $WRONG_DIRECTORY
    exit
fi
e56481aa   Etienne Pallier   new install script
63
64
65

# Create a virtual env for Python3
cd ../
6101568a   haribo   Improved install_...
66
67
68
69
70

mkdir -p private

echo $PRIVATE_DIR_CREATE

e56481aa   Etienne Pallier   new install script
71
cd private/
6101568a   haribo   Improved install_...
72

d5a2d7dd   Etienne Pallier   bugfix venv name
73
# create a venv_py3_pyros/ folder inside PYROS/private/
6101568a   haribo   Improved install_...
74
75
echo $VENV_CREATE
virtualenv $VENV_NAME -p $PYTHON_DIR
e56481aa   Etienne Pallier   new install script
76
77

# Activate the virtual env
6101568a   haribo   Improved install_...
78
echo $VENV_ACTIVATE
d5a2d7dd   Etienne Pallier   bugfix venv name
79
source ./$VENV_NAME/bin/activate
e56481aa   Etienne Pallier   new install script
80

31929284   haribo   install script im...
81
82
83
84
85
if [ $? -ne 0 ]; then
    echo $VENV_FAIL
    exit
fi

6101568a   haribo   Improved install_...
86
87
echo "Python version :"
python -V
3253ad8e   Etienne Pallier   new script for in...
88

31929284   haribo   install script im...
89
90
91
92
93
94
95
# Ask for using MySQL
echo $ASK_USE_MYSQL
read ANSWER
if echo "$ANSWER" | grep -iq "^y"; then
    echo -n $ASK_MYSQL_USERNAME
    read ANSWER
    if [ "$ANSWER" != "" ]; then
97b042a0   Microaster   Changed installat...
96
		USERNAME="$ANSWER"
31929284   haribo   install script im...
97
98
99
100
101
    fi
    
    echo $SQL_SCRIPT | mysql -u "$USERNAME" -p

    if [ $? -ne 0 ]; then
97b042a0   Microaster   Changed installat...
102
103
		echo $SQL_FAIL
		exit
31929284   haribo   install script im...
104
105
106
107
108
    fi

    echo -e $TELL_MYSQL_CREATIONS

    sed -i -e "s/MYSQL = False/MYSQL = True/g" ../src/pyros/settings.py
97b042a0   Microaster   Changed installat...
109
	MYSQL=1
31929284   haribo   install script im...
110
111
112
else
    sed -i -e "s/MYSQL = True/MYSQL = False/g" ../src/pyros/settings.py
    echo $USE_SQLITE
97b042a0   Microaster   Changed installat...
113
	MYSQL=0
31929284   haribo   install script im...
114
115
116
117
fi

read -n1 -r -p "Press any key to continue..." key

97b042a0   Microaster   Changed installat...
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# Upgrade pip
echo $UPGRADE_PIP
pip install --upgrade pip

# Upgrade wheel
echo $UPGRADE_WHEEL
pip install --upgrade wheel

# Install the needed python packages
echo $INSTALL_PACKAGES
if [ $MYSQL -ne 0 ]; then
	pip install -r ../install/REQUIREMENTS.txt
else
	pip install -r ../install/REQUIREMENTS_SQLITE.txt
fi

31929284   haribo   install script im...
134
# Create the database content and a superuser pyros
e56481aa   Etienne Pallier   new install script
135
cd ../src/
31929284   haribo   install script im...
136
echo $CREATE_DATABASE_CONTENT
6101568a   haribo   Improved install_...
137
138
139
python manage.py makemigrations
python manage.py migrate

609eb83d   haribo   Improved install_...
140
141
142
143
144
if [ $? -ne 0 ]; then
    echo $BAD_SQL_CONFIGURATION
    exit
fi

6101568a   haribo   Improved install_...
145
echo $CREATE_SUPERUSER
31929284   haribo   install script im...
146
echo $CREATE_SUPERUSER_SCRIPT | python ../src/manage.py shell
e56481aa   Etienne Pallier   new install script
147

97b042a0   Microaster   Changed installat...
148
149
echo $TELL_SUPERUSER_CREATION
read -n1 -r -p "Press any key to continue..." key
a046fe99   haribo   Message at the en...
150
151
echo $FINAL_MESSAGE
read -n1 -r -p "Press any key to continue..." key
97b042a0   Microaster   Changed installat...
152

6101568a   haribo   Improved install_...
153
echo $INSTALLATION_FINISHED