blob: 240eca676bf7a1c69a96a5cb30d191d4f4c5be79 [file] [log] [blame]
Anand Doshi17fb35f2012-05-10 12:39:25 +05301#!/usr/bin/python
Anand Doshi486f9df2012-07-19 13:40:31 +05302from __future__ import unicode_literals
Anand Doshi17fb35f2012-05-10 12:39:25 +05303import os, commands
4
5# ask for root mysql password
6import getpass
7
8root_pwd = None
9while not root_pwd:
10 root_pwd = getpass.getpass("MySQL Root user's Password: ")
11
12# test root connection
13op = commands.getoutput("mysql -u root -p%s -e 'exit'" % \
14 root_pwd.replace('$', '\$').replace(' ', '\ '))
15if "access denied" in op.lower():
16 raise Exception("Incorrect MySQL Root user's password")
17
18# ask for new dbname
19new_dbname = None
20while not new_dbname:
21 new_dbname = raw_input("New ERPNext Database Name: ")
22
23# ask for new dbpassword
24new_dbpassword = None
25while not new_dbpassword:
26 new_dbpassword = raw_input("New ERPNext Database's Password: ")
27
28# get erpnext path
29erpnext_path = os.path.dirname(os.path.abspath(__file__))
30os.chdir(erpnext_path)
31
32# setup backups
33if not os.path.exists(os.path.join(erpnext_path, 'backups')):
34 os.makedirs('backups')
35 os.symlink(os.path.join(erpnext_path, 'backups'),
36 os.path.join(erpnext_path, 'public', 'backups'))
37
38# setup files
39if not os.path.exists(os.path.join(erpnext_path, 'files')):
40 os.makedirs('files')
41 os.symlink(os.path.join(erpnext_path, 'files'),
42 os.path.join(erpnext_path, 'public', 'files'))
43
44# setup logs
45if not os.path.exists(os.path.join(erpnext_path, 'logs')):
46 os.makedirs('logs')
47 os.system('touch logs/error_log.txt')
48
49# setup lib -- framework repo with read only access
50# change this if you have your own fork
51if not os.path.exists(os.path.join(erpnext_path, 'lib')):
Anand Doshic655f472012-07-12 19:08:48 +053052 os.system('git clone https://github.com/webnotes/wnframework.git lib')
Anand Doshi17fb35f2012-05-10 12:39:25 +053053
54# setup symlinks in public
55if not os.path.exists(os.path.join(erpnext_path, 'public', 'js', 'lib')):
56 os.symlink(os.path.join(erpnext_path, 'lib', 'js', 'lib'),
57 os.path.join(erpnext_path, 'public', 'js', 'lib'))
58if not os.path.exists(os.path.join(erpnext_path, 'public', 'images', 'lib')):
Anand Doshi8ec5ddf2012-05-10 12:56:10 +053059 os.symlink(os.path.join(erpnext_path, 'lib', 'images'),
Anand Doshi17fb35f2012-05-10 12:39:25 +053060 os.path.join(erpnext_path, 'public', 'images', 'lib'))
61
62# extract master
63if os.path.exists(os.path.join(erpnext_path, 'data', 'master.sql.gz')):
64 os.system('gunzip data/master.sql.gz')
65
66# setup conf
67if not os.path.exists(os.path.join(erpnext_path, 'conf.py')):
68 # read template conf file
69 with open(os.path.join(erpnext_path, 'lib', 'conf', 'conf.py'), 'r') as template:
70 content = template.read()
71
72 # manipulate content
73 import re
74
75 # set new_dbname, new_dbpassword, modules_path, files_path, backup_path, log_file_name
76 content = re.sub("db_name.*", "db_name = '%s'" % new_dbname, content)
77 content = re.sub("db_password.*", "db_password = '%s'" % new_dbpassword, content)
78 content = re.sub("modules_path.*", "modules_path = '%s'" % \
79 os.path.join(erpnext_path, 'erpnext'), content)
80 content = re.sub("files_path.*", "files_path = '%s'" % \
81 os.path.join(erpnext_path, 'files'), content)
82 content = re.sub("backup_path.*", "backup_path = '%s'" % \
83 os.path.join(erpnext_path, 'backups'), content)
84 content = re.sub("log_file_name.*", "log_file_name = '%s'" % \
85 os.path.join(erpnext_path, 'logs', 'error_log.txt'), content)
86
87
88 # write conf file
89 with open(os.path.join(erpnext_path, 'conf.py'), 'w') as new_conf:
90 new_conf.write(content)
91
92# install db
93import sys
94sys.path.append(erpnext_path)
Anand Doshi45b187d2012-05-10 13:10:06 +053095sys.path.append(os.path.join(erpnext_path, 'lib', 'py'))
Anand Doshi17fb35f2012-05-10 12:39:25 +053096import conf
97sys.path.append(conf.modules_path)
98
99from webnotes.install_lib.install import Installer
100inst = Installer('root', root_pwd)
101inst.import_from_db(new_dbname, source_path=os.path.join(erpnext_path, 'data', 'master.sql'), verbose = 1)
102
103# apply patches
104os.chdir(erpnext_path)
Anand Doshi9b88baa2012-07-12 18:52:54 +0530105os.system("lib/wnf.py --update origin master")
Anand Doshi79af9632012-05-14 16:36:10 +0530106
Anand Doshi3fa25fa2012-05-10 15:15:43 +0530107# set filemode false
108os.system("git config core.filemode false")
109os.chdir(os.path.join(erpnext_path, 'lib'))
110os.system("git config core.filemode false")
111
Anand Doshi17fb35f2012-05-10 12:39:25 +0530112steps_remaining = """
Anand Doshi54e79bb2012-07-12 19:50:53 +0530113Notes:
114------
115
116sample apache conf file
117#-----------------------------------------------------------
118SetEnv PYTHON_EGG_CACHE /var/www
119
120# you can change 99 to any other port
121
122Listen 99
123NameVirtualHost *:99
124<VirtualHost *:99>
125 ServerName localhost
126 DocumentRoot {path to erpnext's folder}/public
127 AddHandler cgi-script .cgi .xml .py
128
129 <Directory {path to erpnext's folder}/public/>
130 # directory specific options
Anand Doshiaf1f4372012-07-12 22:06:27 +0530131 Options -Indexes +FollowSymLinks +ExecCGI
Anand Doshi54e79bb2012-07-12 19:50:53 +0530132
133 # directory's index file
134 DirectoryIndex web.py
135
136 # rewrite rule
137 RewriteEngine on
138
139 # condition 1:
140 # ignore login-page.html, app.html, blank.html, unsupported.html
141 RewriteCond %{REQUEST_URI} ^((?!app\.html|blank\.html|unsupported\.html).)*$
142
143 # condition 2: if there are no slashes
144 # and file is .html or does not containt a .
145 RewriteCond %{REQUEST_URI} ^(?!.+/)((.+\.html)|([^.]+))$
146
147 # rewrite if both of the above conditions are true
148 RewriteRule ^(.+)$ web.py?page=$1 [NC,L]
149
150 AllowOverride all
151 Order Allow,Deny
152 Allow from all
153 </Directory>
154</VirtualHost>
155#-----------------------------------------------------------
156
Anand Doshi17fb35f2012-05-10 12:39:25 +0530157To Do:
158
159* Configure apache/http conf file to point to public folder
160* chown recursively all files in your folder to apache user
Anand Doshia3851752012-05-10 15:57:05 +0530161* login using: user="Administrator" and password="admin"
Anand Doshi54e79bb2012-07-12 19:50:53 +0530162
Anand Doshi17fb35f2012-05-10 12:39:25 +0530163"""
164
165print steps_remaining
166