Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

166 lines (128 sloc) 5.066 kb
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__))
# setup backups
if not os.path.exists(os.path.join(erpnext_path, '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.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.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 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, '')):
# read template conf file
with open(os.path.join(erpnext_path, 'lib', 'conf', ''), 'r') as template:
content =
# 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, ''), 'w') as new_conf:
# install db
import sys
sys.path.append(os.path.join(erpnext_path, 'lib', 'py'))
import conf
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.system("lib/ --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 = """
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
# 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 ^(.+)$$1 [NC,L]
AllowOverride all
Order Allow,Deny
Allow from all
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
Jump to Line
Something went wrong with that request. Please try again.