2012-05-10 07:09:25 +00:00
|
|
|
#!/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')):
|
2012-07-12 13:38:48 +00:00
|
|
|
os.system('git clone https://github.com/webnotes/wnframework.git lib')
|
2012-05-10 07:09:25 +00:00
|
|
|
|
|
|
|
# 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')):
|
2012-05-10 07:26:10 +00:00
|
|
|
os.symlink(os.path.join(erpnext_path, 'lib', 'images'),
|
2012-05-10 07:09:25 +00:00
|
|
|
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)
|
2012-05-10 07:40:06 +00:00
|
|
|
sys.path.append(os.path.join(erpnext_path, 'lib', 'py'))
|
2012-05-10 07:09:25 +00:00
|
|
|
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)
|
2012-07-12 13:22:54 +00:00
|
|
|
os.system("lib/wnf.py --update origin master")
|
2012-05-14 11:06:10 +00:00
|
|
|
|
2012-05-10 09:45:43 +00:00
|
|
|
# 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")
|
|
|
|
|
2012-05-10 07:09:25 +00:00
|
|
|
steps_remaining = """
|
2012-07-12 14:20:53 +00:00
|
|
|
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
|
2012-07-12 16:36:27 +00:00
|
|
|
Options -Indexes +FollowSymLinks +ExecCGI
|
2012-07-12 14:20:53 +00:00
|
|
|
|
|
|
|
# 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>
|
|
|
|
#-----------------------------------------------------------
|
|
|
|
|
2012-05-10 07:09:25 +00:00
|
|
|
To Do:
|
|
|
|
|
|
|
|
* Configure apache/http conf file to point to public folder
|
|
|
|
* chown recursively all files in your folder to apache user
|
2012-05-10 10:27:05 +00:00
|
|
|
* login using: user="Administrator" and password="admin"
|
2012-07-12 14:20:53 +00:00
|
|
|
|
2012-05-10 07:09:25 +00:00
|
|
|
"""
|
|
|
|
|
|
|
|
print steps_remaining
|
|
|
|
|