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