-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.py
148 lines (107 loc) · 4.05 KB
/
install.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
"""
Install wnframework and port
"""
import sys, os
# settings
from install_settings import *
def make_defs():
os.system('cp %s %s' % (os.path.join('wnframework','cgi-bin','webnotes','defs_template.py'), os.path.join('wnframework','cgi-bin','webnotes','defs.py')))
global db_password, db_name
# ask for the user password
new_db_name = raw_input('Name of the new database (default: %s):' % db_name)
if new_db_name:
db_name = new_db_name
if not db_password:
db_password = raw_input('Password of the new database:')
defs_content = open(os.path.join('wnframework','cgi-bin','webnotes','defs_template.py'), 'r').readlines()
defs = open(os.path.join('wnframework','cgi-bin','webnotes','defs.py'), 'w')
# replace the line that begin with db_password and modules_path with
for d in defs_content:
if d.startswith('db_password'):
defs.write('db_password="%s"\n' % db_password.replace('"', '\"'))
elif d.startswith('default_db_name'):
defs.write('default_db_name="%s"\n' % db_name.replace('"', '\"'))
elif d.startswith('modules_path'):
defs.write('modules_path="%s"\n' % os.path.join(os.path.abspath('erpnext')))
else:
defs.write(d)
defs.close()
def restore_db():
"""
import the database
"""
sys.path.append(os.path.join('wnframework','cgi-bin'))
import webnotes
from webnotes.db import Database
from webnotes.install_lib.install import Installer
global db_name
root_password = raw_input('Root password for mysql (for db and user creation):')
inst = Installer('root', root_password)
# gunzip
os.system("gunzip -c %s > master.sql" % os.path.join('erpnext', 'master.sql.gz'))
# import
print "Importing database..."
inst.import_from_db(db_name, 'master.sql')
# cleanup
webnotes.conn = Database('localhost','root',root_password)
webnotes.conn.use(db_name)
webnotes.conn.begin()
webnotes.conn.set_value('Control Panel',None,'company_name',raw_input('[ERPNext setup] Enter the name of the full name of your company:'))
webnotes.conn.sql("delete from tabSingles where field='sync_with_gateway'")
webnotes.conn.commit()
os.remove('master.sql')
# copy icons
if not os.path.exists(os.path.join('wnframework','images','user')):
os.mkdir(os.path.join('wnframework','images','user'))
os.system("cp %s %s" % (os.path.join('erpnext','module-icons.png'),os.path.join('wnframework','images','user')))
def setup_httpd():
conf = """
# generated by erpnext install.py
User %(www_user)s
<VirtualHost *:%(port)s>
# web root folder
DocumentRoot %(document_root)s
# allow cgi execution in the app
Options +ExecCGI
AddHandler cgi-script .cgi
# default index is .cgi
DirectoryIndex index.cgi
# dont show .py files
<Directory "/">
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .py [F]
</IfModule>
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
"""
# redhat
if os.path.exists(os.path.join('/', 'etc', 'httpd', 'conf.d')):
conf_file = open(os.path.join('/', 'etc', 'httpd', 'conf.d', 'erpnext.conf'),'w')
# ubuntu
elif os.path.exists(os.path.join('/', 'etc', 'apache2', 'conf.d')):
conf_file = open(os.path.join('/', 'etc', 'apache2', 'conf.d', 'erpnext.conf'),'w')
# mac
elif os.path.exists(os.path.join('/', 'etc', 'httpd', 'users')):
conf_file = open(os.path.join('/', 'etc', 'httpd', 'users', 'erpnext.conf'),'w')
else:
print "[Error] Could not find apache config files in the usual places, please manually add the erpnext.conf file in your apache conf folder"
conf_file = open('erpnext.conf', 'w')
conf_file.write(conf % {'port': http_port, 'document_root': os.path.abspath('wnframework'), 'www_user':www_user})
conf_file.close()
def set_perms():
"""make the current folder writable by www user"""
print "Adding user %s..." % www_user
os.system("useradd -g users %s" % www_user)
print "Making %s owner of erpnext..." % www_user
os.system("chown -R %s ." % www_user)
def install():
make_defs()
restore_db()
setup_httpd()
set_perms()
print "Install complete. Please restart your http server and go to http://localhost:%s on your browser to start erpnext" % http_port
if __name__=='__main__':
install()