Blame view

install/install_requirements_windows.bat 4.13 KB
42983157   haribo   #3443 pyrosrun sc...
1
@echo off
8f45bac7   Microaster   install script fo...
2
3
4
5

SET PYTHON=python
SET VENV_NAME=venv_py35_pyros

97b042a0   Microaster   Changed installat...
6
7
8
9
10
11
SET USERNAME=root

SET DB_USER=pyros
SET DB_PASSWORD=DjangoPyros
SET MYSQL=0

a046fe99   haribo   Message at the en...
12
13
SET PORT=8000

8f45bac7   Microaster   install script fo...
14
15
REM String variables

97b042a0   Microaster   Changed installat...
16
17
18
19
20
21
22
SET ASK_USE_MYSQL=-Do you wish to use mysql in your project ? Only if mysql-server is installed. (Y/N)
SET ASK_MYSQL_USERNAME=-MySQL server login (default 'root'): 
SET SQL_SCRIPT=CREATE DATABASE IF NOT EXISTS pyros; DROP USER IF EXISTS '%DB_USER%'; CREATE USER '%DB_USER%' IDENTIFIED BY '%DB_PASSWORD%'; GRANT ALL PRIVILEGES ON pyros.* TO %DB_USER%;
SET SQL_FAIL=-Failed to execute database script, probably due to a wrong username or password
SET TELL_MYSQL_CREATIONS=-Created pyros database.\n-Created new user '%DB_USER%' with password '%DB_PASSWORD%'
SET USE_SQLITE=-Sqlite will be used by default. There is no required configuration.

8f45bac7   Microaster   install script fo...
23
SET PRIVATE_DIR_CREATE=-Created 'private' directory
97b042a0   Microaster   Changed installat...
24
SET PYTHON_NOT_INSTALLED=-Cannot find %PYTHON%, please install it or configure PYTHON variable in this script
8f45bac7   Microaster   install script fo...
25
26
SET PYTHON_FOUND=-Found %PYTHON% at
SET VENV_CREATE=-Creating virtualenv $VENV_NAME... 
97b042a0   Microaster   Changed installat...
27
28
SET VENV_ACTIVATE=-Activating virtual environment...
SET VENV_FAIL=-Failed to activate virtualenv. Ask project administrators for further information
8f45bac7   Microaster   install script fo...
29
30
31
32
SET DONE=done.
SET UPGRADE_PIP=-Upgrading pip:
SET UPGRADE_WHEEL=-Upgrading wheel:
SET INSTALL_PACKAGES=-Installing required packages from install/REQUIREMENTS.txt
97b042a0   Microaster   Changed installat...
33
SET CREATE_DATABASE_CONTENT=-Creating database tables :
8f45bac7   Microaster   install script fo...
34
SET CREATE_SUPERUSER=-Creating database superuser :
97b042a0   Microaster   Changed installat...
35
SET 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%')
8f45bac7   Microaster   install script fo...
36
37
SET INSTALLATION_FINISHED=-Installation finished
SET BAD_SQL_CONFIGURATION=-Migration cannot be applied to the database : check your database configuration, or use sqlite instead
97b042a0   Microaster   Changed installat...
38
SET TELL_SUPERUSER_CREATION=-Superuser created for django admin interface. Login: %DB_USER% , password: %DB_PASSWORD%
a046fe99   haribo   Message at the en...
39
SET FINAL_MESSAGE=-Please run './pyrosrun server' then go to localhost:%PORT%/admin and log in with these id
8f45bac7   Microaster   install script fo...
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

REM Getting python location
where %PYTHON% > tmp.txt

IF %ERRORLEVEL% NEQ 0 (
	ECHO %PYTHON_NOT_INSTALLED%
	del tmp.txt
	PAUSE
	EXIT
)

SET /p PYTHON_DIR=<tmp.txt
del tmp.txt


ECHO %PYTHON_FOUND% %PYTHON_DIR%

REM Move into the .bat file directory (should be install/)

cd %~dp0%

REM Create a virtual env for Python3
cd ..

if not exist private mkdir private

echo %PRIVATE_DIR_CREATE%

cd private/

REM create a venv_py35_pyros/ folder inside PYROS/private/
echo %VENV_CREATE%
virtualenv %VENV_NAME% -p %PYTHON_DIR%


REM Activate the virtual env
echo %VENV_ACTIVATE%
31929284   haribo   install script im...
77
CALL %VENV_NAME%/Scripts/activate
8f45bac7   Microaster   install script fo...
78

97b042a0   Microaster   Changed installat...
79
80
81
82
83
84
IF %ERRORLEVEL% NEQ 0 (
    echo %VENV_FAIL%
	pause
    exit
)

8f45bac7   Microaster   install script fo...
85
86
87
echo Python location :
where python

97b042a0   Microaster   Changed installat...
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
REM Ask for using MySQL
SET /p ANSWER= "%ASK_USE_MYSQL%"

IF /I "%ANSWER%" == "y" (
	SET /p ANSWER= "%ASK_MYSQL_USERNAME%"
	IF "%ANSWER%" NEQ "" (
		SET USERNAME=%ANSWER%
	)
	
	echo %SQL_SCRIPT% | mysql -u %USERNAME% -p

	IF %ERRORLEVEL% NEQ 0 (
		echo %SQL_FAIL%
		pause
		exit
	)
	
	echo %TELL_MYSQL_CREATIONS% 
	
7805dcc5   Microaster   fix bug of null b...
107
	powershell -Command "(gc ../src/pyros/settings.py) -replace 'MYSQL = False', 'MYSQL = True' | Out-File -encoding UTF8 ../src/pyros/settings.py"
97b042a0   Microaster   Changed installat...
108
109
	SET MYSQL=1
) ELSE (
7805dcc5   Microaster   fix bug of null b...
110
	powershell -Command "(gc ../src/pyros/settings.py) -replace 'MYSQL = True', 'MYSQL = False' | Out-File -encoding UTF8 ../src/pyros/settings.py"
97b042a0   Microaster   Changed installat...
111
112
113
114
115
116
    echo %USE_SQLITE%
	SET MYSQL=0
)

pause

8f45bac7   Microaster   install script fo...
117
118
119
120
121
122
123
124
125
126
REM Upgrade pip
echo %UPGRADE_PIP%
pip install --upgrade pip

REM Upgrade wheel
echo %UPGRADE_WHEEL%
pip install --upgrade wheel

REM Install the needed python packages
echo %INSTALL_PACKAGES%
97b042a0   Microaster   Changed installat...
127
128
129
130
131
132
IF %MYSQL% NEQ 0 (
	pip install -r ../install/REQUIREMENTS.txt
) ELSE (
	pip install -r ../install/REQUIREMENTS_SQLITE.txt
)
REM Create the database content and a superuser pyros
8f45bac7   Microaster   install script fo...
133
cd ../src/
97b042a0   Microaster   Changed installat...
134
echo %CREATE_DATABASE_CONTENT%
8f45bac7   Microaster   install script fo...
135
136
137
138
139
140
141
142
143
144
python manage.py makemigrations
python manage.py migrate

IF %ERRORLEVEL% NEQ 0 (
    echo %BAD_SQL_CONFIGURATION%
	pause
    exit
)

echo %CREATE_SUPERUSER%
7805dcc5   Microaster   fix bug of null b...
145
echo %CREATE_SUPERUSER_SCRIPT% | python ../src/manage.py shell
8f45bac7   Microaster   install script fo...
146

97b042a0   Microaster   Changed installat...
147
148
149
echo %TELL_SUPERUSER_CREATION%
pause

8f45bac7   Microaster   install script fo...
150
151
echo %INSTALLATION_FINISHED%

a046fe99   haribo   Message at the en...
152
153
154
155
156
157
pause

echo %FINAL_MESSAGE%

pause

8f45bac7   Microaster   install script fo...
158
EXIT