forked from frappe/erpnext
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install_erpnext.py
165 lines (128 loc) · 4.95 KB
/
install_erpnext.py
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#!/usr/bin/python
import os, commands
# ask for root mysql password
import getpass
root_pwd = None
while not root_pwd:
root_pwd = getpass.getpass("MySQL Root user's Password: ")
# test root connection
op = commands.getoutput("mysql -u root -p%s -e 'exit'" % \
root_pwd.replace('$', '\$').replace(' ', '\ '))
if "access denied" in op.lower():
raise Exception("Incorrect MySQL Root user's password")
# ask for new dbname
new_dbname = None
while not new_dbname:
new_dbname = raw_input("New ERPNext Database Name: ")
# ask for new dbpassword
new_dbpassword = None
while not new_dbpassword:
new_dbpassword = raw_input("New ERPNext Database's Password: ")
# get erpnext path
erpnext_path = os.path.dirname(os.path.abspath(__file__))
os.chdir(erpnext_path)
# setup backups
if not os.path.exists(os.path.join(erpnext_path, 'backups')):
os.makedirs('backups')
os.symlink(os.path.join(erpnext_path, 'backups'),
os.path.join(erpnext_path, 'public', 'backups'))
# setup files
if not os.path.exists(os.path.join(erpnext_path, 'files')):
os.makedirs('files')
os.symlink(os.path.join(erpnext_path, 'files'),
os.path.join(erpnext_path, 'public', 'files'))
# setup logs
if not os.path.exists(os.path.join(erpnext_path, 'logs')):
os.makedirs('logs')
os.system('touch logs/error_log.txt')
# setup lib -- framework repo with read only access
# change this if you have your own fork
if not os.path.exists(os.path.join(erpnext_path, 'lib')):
os.system('git clone https://github.com/webnotes/wnframework.git lib')
# setup symlinks in public
if not os.path.exists(os.path.join(erpnext_path, 'public', 'js', 'lib')):
os.symlink(os.path.join(erpnext_path, 'lib', 'js', 'lib'),
os.path.join(erpnext_path, 'public', 'js', 'lib'))
if not os.path.exists(os.path.join(erpnext_path, 'public', 'images', 'lib')):
os.symlink(os.path.join(erpnext_path, 'lib', 'images'),
os.path.join(erpnext_path, 'public', 'images', 'lib'))
# extract master
if os.path.exists(os.path.join(erpnext_path, 'data', 'master.sql.gz')):
os.system('gunzip data/master.sql.gz')
# setup conf
if not os.path.exists(os.path.join(erpnext_path, 'conf.py')):
# read template conf file
with open(os.path.join(erpnext_path, 'lib', 'conf', 'conf.py'), 'r') as template:
content = template.read()
# manipulate content
import re
# set new_dbname, new_dbpassword, modules_path, files_path, backup_path, log_file_name
content = re.sub("db_name.*", "db_name = '%s'" % new_dbname, content)
content = re.sub("db_password.*", "db_password = '%s'" % new_dbpassword, content)
content = re.sub("modules_path.*", "modules_path = '%s'" % \
os.path.join(erpnext_path, 'erpnext'), content)
content = re.sub("files_path.*", "files_path = '%s'" % \
os.path.join(erpnext_path, 'files'), content)
content = re.sub("backup_path.*", "backup_path = '%s'" % \
os.path.join(erpnext_path, 'backups'), content)
content = re.sub("log_file_name.*", "log_file_name = '%s'" % \
os.path.join(erpnext_path, 'logs', 'error_log.txt'), content)
# write conf file
with open(os.path.join(erpnext_path, 'conf.py'), 'w') as new_conf:
new_conf.write(content)
# install db
import sys
sys.path.append(erpnext_path)
sys.path.append(os.path.join(erpnext_path, 'lib', 'py'))
import conf
sys.path.append(conf.modules_path)
from webnotes.install_lib.install import Installer
inst = Installer('root', root_pwd)
inst.import_from_db(new_dbname, source_path=os.path.join(erpnext_path, 'data', 'master.sql'), verbose = 1)
# apply patches
os.chdir(erpnext_path)
os.system("lib/wnf.py --update origin master")
# set filemode false
os.system("git config core.filemode false")
os.chdir(os.path.join(erpnext_path, 'lib'))
os.system("git config core.filemode false")
steps_remaining = """
Notes:
------
sample apache conf file
#-----------------------------------------------------------
SetEnv PYTHON_EGG_CACHE /var/www
# you can change 99 to any other port
Listen 99
NameVirtualHost *:99
<VirtualHost *:99>
ServerName localhost
DocumentRoot {path to erpnext's folder}/public
AddHandler cgi-script .cgi .xml .py
<Directory {path to erpnext's folder}/public/>
# directory specific options
Options -Indexes +FollowSymLinks +ExecCGI
# directory's index file
DirectoryIndex web.py
# rewrite rule
RewriteEngine on
# condition 1:
# ignore login-page.html, app.html, blank.html, unsupported.html
RewriteCond %{REQUEST_URI} ^((?!app\.html|blank\.html|unsupported\.html).)*$
# condition 2: if there are no slashes
# and file is .html or does not containt a .
RewriteCond %{REQUEST_URI} ^(?!.+/)((.+\.html)|([^.]+))$
# rewrite if both of the above conditions are true
RewriteRule ^(.+)$ web.py?page=$1 [NC,L]
AllowOverride all
Order Allow,Deny
Allow from all
</Directory>
</VirtualHost>
#-----------------------------------------------------------
To Do:
* Configure apache/http conf file to point to public folder
* chown recursively all files in your folder to apache user
* login using: user="Administrator" and password="admin"
"""
print steps_remaining