blob: 81c62effae87d81c8faa0bacb9fa8913d2fef885 [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 Doshi8ec5ddf2012-05-10 12:56:10 +053051 os.system('git clone git://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)
104os.system("lib/wnf.py -l")
105
106# force sync all
107os.system("lib/wnf.py --sync_all -f")
108
109steps_remaining = """
110To Do:
111
112* Configure apache/http conf file to point to public folder
113* chown recursively all files in your folder to apache user
114"""
115
116print steps_remaining
117