From 736d14f9889bcbee1785d576c54b3dc50c920919 Mon Sep 17 00:00:00 2001 From: Pratik Vyas Date: Wed, 22 Oct 2014 12:15:41 +0530 Subject: [PATCH] pass admin-password and root password to new-site --- bench/cli.py | 6 ++++-- bench/utils.py | 11 +++++++++-- install_scripts/setup_frappe.sh | 26 ++++++++++++++++++-------- 3 files changed, 31 insertions(+), 12 deletions(-) diff --git a/bench/cli.py b/bench/cli.py index 412d1b1c..548c2af8 100644 --- a/bench/cli.py +++ b/bench/cli.py @@ -83,10 +83,12 @@ def new_app(app_name): _new_app(app_name) @click.command('new-site') +@click.option('--mariadb-root-password', help="MariaDB root password") +@click.option('--admin-password', help="admin password to set for site") @click.argument('site') -def new_site(site): +def new_site(site, mariadb_root_password=None, admin_password=None): "Create a new site in the bench" - _new_site(site) + _new_site(site, mariadb_root_password=mariadb_root_password, admin_password=admin_password) #TODO: Not DRY @click.command('update') diff --git a/bench/utils.py b/bench/utils.py index 72534cbf..43c8f09d 100644 --- a/bench/utils.py +++ b/bench/utils.py @@ -71,9 +71,16 @@ def setup_procfile(bench='.'): worker: sh -c 'cd sites && exec ../env/bin/python -m frappe.celery_app worker' workerbeat: sh -c 'cd sites && exec ../env/bin/python -m frappe.celery_app beat -s scheduler.schedule'""") -def new_site(site, bench='.'): +def new_site(site, mariadb_root_password=None, admin_password=None, bench='.'): logger.info('creating new site {}'.format(site)) - exec_cmd("{frappe} --install {site} {site}".format(frappe=get_frappe(bench=bench), site=site), cwd=os.path.join(bench, 'sites')) + mariadb_root_password_fragment = '--root_password {}'.format(mariadb_root_password) if mariadb_root_password else '' + admin_password_fragment = '--admin_password {}'.format(admin_password) if admin_password else '' + exec_cmd("{frappe} --install {site} {site} {mariadb_root_password_fragment} {admin_password_fragment}".format( + frappe=get_frappe(bench=bench), + site=site, + mariadb_root_password_fragment=mariadb_root_password_fragment, + admin_password_fragment=admin_password_fragment + ), cwd=os.path.join(bench, 'sites')) if len(get_sites(bench=bench)) == 1: exec_cmd("{frappe} --use {site}".format(frappe=get_frappe(bench=bench), site=site), cwd=os.path.join(bench, 'sites')) diff --git a/install_scripts/setup_frappe.sh b/install_scripts/setup_frappe.sh index 251423de..a0084832 100644 --- a/install_scripts/setup_frappe.sh +++ b/install_scripts/setup_frappe.sh @@ -179,18 +179,26 @@ install_supervisor_centos6() { ### config get_mariadb_password() { + get_password "MariaDB root" MSQ_PASS +} + +get_site_admin_password() { + get_password "Admin password" ADMIN_PASS +} + +get_password() { if [ -z "$MSQ_PASS" ]; then read -t 1 -n 10000 discard || true echo - read -p "Enter mysql root password to set:" -s MSQ_PASS1 + read -p "Enter $1 password to set:" -s TMP_PASS1 echo - read -p "Re enter mysql root password to set:" -s MSQ_PASS2 + read -p "Re enter $1 password to set:" -s TMP_PASS2 echo - if [ $MSQ_PASS1 == $MSQ_PASS2 ]; then - export MSQ_PASS=$MSQ_PASS1 + if [ $TMP_PASS1 == $TMP_PASS2 ]; then + export $2=$TMp_PASS1 else echo Passwords do not match - get_mariadb_password + get_password $1 $2 fi fi } @@ -260,9 +268,11 @@ install_bench() { setup_bench() { echo Installing frappe-bench run_cmd sudo su $FRAPPE_USER -c "cd /home/$FRAPPE_USER && bench init frappe-bench --apps_path https://raw.githubusercontent.com/frappe/bench/master/install_scripts/erpnext-apps.json" - sudo su $FRAPPE_USER -c "cd /home/$FRAPPE_USER/frappe-bench && bench new-site site1.local" - sudo su $FRAPPE_USER -c "cd /home/$FRAPPE_USER/frappe-bench && bench frappe --install_app erpnext" - sudo su $FRAPPE_USER -c "cd /home/$FRAPPE_USER/frappe-bench && bench frappe --install_app shopping_cart" + echo Setting up first site + get_site_admin_password + run_cmd sudo su $FRAPPE_USER -c "cd /home/$FRAPPE_USER/frappe-bench && bench new-site site1.local --root-password $MSQ_PASS --admin_password $ADMIN_PASS" + run_cmd sudo su $FRAPPE_USER -c "cd /home/$FRAPPE_USER/frappe-bench && bench frappe --install_app erpnext" + run_cmd sudo su $FRAPPE_USER -c "cd /home/$FRAPPE_USER/frappe-bench && bench frappe --install_app shopping_cart" } add_user() {