Anand Doshi | 17fb35f | 2012-05-10 12:39:25 +0530 | [diff] [blame] | 1 | #!/usr/bin/python |
| 2 | import os, commands |
| 3 | |
| 4 | # ask for root mysql password |
| 5 | import getpass |
| 6 | |
| 7 | root_pwd = None |
| 8 | while not root_pwd: |
| 9 | root_pwd = getpass.getpass("MySQL Root user's Password: ") |
| 10 | |
| 11 | # test root connection |
| 12 | op = commands.getoutput("mysql -u root -p%s -e 'exit'" % \ |
| 13 | root_pwd.replace('$', '\$').replace(' ', '\ ')) |
| 14 | if "access denied" in op.lower(): |
| 15 | raise Exception("Incorrect MySQL Root user's password") |
| 16 | |
| 17 | # ask for new dbname |
| 18 | new_dbname = None |
| 19 | while not new_dbname: |
| 20 | new_dbname = raw_input("New ERPNext Database Name: ") |
| 21 | |
| 22 | # ask for new dbpassword |
| 23 | new_dbpassword = None |
| 24 | while not new_dbpassword: |
| 25 | new_dbpassword = raw_input("New ERPNext Database's Password: ") |
| 26 | |
| 27 | # get erpnext path |
| 28 | erpnext_path = os.path.dirname(os.path.abspath(__file__)) |
| 29 | os.chdir(erpnext_path) |
| 30 | |
| 31 | # setup backups |
| 32 | if 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 |
| 38 | if 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 |
| 44 | if 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 |
| 50 | if not os.path.exists(os.path.join(erpnext_path, 'lib')): |
Anand Doshi | 8ec5ddf | 2012-05-10 12:56:10 +0530 | [diff] [blame] | 51 | os.system('git clone git://github.com/webnotes/wnframework.git lib') |
Anand Doshi | 17fb35f | 2012-05-10 12:39:25 +0530 | [diff] [blame] | 52 | |
| 53 | # setup symlinks in public |
| 54 | if 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')) |
| 57 | if not os.path.exists(os.path.join(erpnext_path, 'public', 'images', 'lib')): |
Anand Doshi | 8ec5ddf | 2012-05-10 12:56:10 +0530 | [diff] [blame] | 58 | os.symlink(os.path.join(erpnext_path, 'lib', 'images'), |
Anand Doshi | 17fb35f | 2012-05-10 12:39:25 +0530 | [diff] [blame] | 59 | os.path.join(erpnext_path, 'public', 'images', 'lib')) |
| 60 | |
| 61 | # extract master |
| 62 | if os.path.exists(os.path.join(erpnext_path, 'data', 'master.sql.gz')): |
| 63 | os.system('gunzip data/master.sql.gz') |
| 64 | |
| 65 | # setup conf |
| 66 | if 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 |
| 92 | import sys |
| 93 | sys.path.append(erpnext_path) |
Anand Doshi | 45b187d | 2012-05-10 13:10:06 +0530 | [diff] [blame] | 94 | sys.path.append(os.path.join(erpnext_path, 'lib', 'py')) |
Anand Doshi | 17fb35f | 2012-05-10 12:39:25 +0530 | [diff] [blame] | 95 | import conf |
| 96 | sys.path.append(conf.modules_path) |
| 97 | |
| 98 | from webnotes.install_lib.install import Installer |
| 99 | inst = Installer('root', root_pwd) |
| 100 | inst.import_from_db(new_dbname, source_path=os.path.join(erpnext_path, 'data', 'master.sql'), verbose = 1) |
| 101 | |
| 102 | # apply patches |
| 103 | os.chdir(erpnext_path) |
| 104 | os.system("lib/wnf.py -l") |
| 105 | |
| 106 | # force sync all |
| 107 | os.system("lib/wnf.py --sync_all -f") |
| 108 | |
Anand Doshi | 79af963 | 2012-05-14 16:36:10 +0530 | [diff] [blame] | 109 | # create website files |
| 110 | #from webnotes.model.code import get_obj |
| 111 | # rewrite pages |
| 112 | #get_obj('Website Settings').rewrite_pages() |
| 113 | |
| 114 | #ss = get_obj('Style Settings') |
| 115 | #ss.validate() |
| 116 | #ss.on_update() |
| 117 | |
Anand Doshi | 3fa25fa | 2012-05-10 15:15:43 +0530 | [diff] [blame] | 118 | # set filemode false |
| 119 | os.system("git config core.filemode false") |
| 120 | os.chdir(os.path.join(erpnext_path, 'lib')) |
| 121 | os.system("git config core.filemode false") |
| 122 | |
Anand Doshi | 17fb35f | 2012-05-10 12:39:25 +0530 | [diff] [blame] | 123 | steps_remaining = """ |
| 124 | To Do: |
| 125 | |
| 126 | * Configure apache/http conf file to point to public folder |
| 127 | * chown recursively all files in your folder to apache user |
Anand Doshi | a385175 | 2012-05-10 15:57:05 +0530 | [diff] [blame] | 128 | * login using: user="Administrator" and password="admin" |
Anand Doshi | 17fb35f | 2012-05-10 12:39:25 +0530 | [diff] [blame] | 129 | """ |
| 130 | |
| 131 | print steps_remaining |
| 132 | |