From 182be6152e9f9291b8e98ce456aecb58edfa33f6 Mon Sep 17 00:00:00 2001 From: chabad360 Date: Thu, 2 Aug 2018 15:12:52 -0700 Subject: [PATCH 01/21] setting up getopt --- dbench | 110 +++++++++++++++------------------------------------ dbench.bak | 113 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 144 insertions(+), 79 deletions(-) create mode 100644 dbench.bak diff --git a/dbench b/dbench index 06ca10a4..b90f5d65 100644 --- a/dbench +++ b/dbench @@ -1,18 +1,24 @@ #!/bin/bash +options=$(getopt -o hd:ac: --long add,help,developer:,setup::,start::,init:: -- "$@") +[ $? -eq 0 ] || { + echo "entering container" + docker exec -it frappe bash +} + function usage { echo "Usage: dbench [-hda [sitename] | --init [-ed] [sitename] | --setup [-d] | --start [-b] | -c \"\"]" echo '' echo 'where:' echo ' -h show this help text' - echo ' -c send a command to the frappe container' + echo ' -c command send a command to bench in the container' echo ' -d [sitename] enables developer mode for specified site' echo ' -a adds site-names to /etc/hosts file in the container to facilitate multisite access' echo ' --setup [-d] builds docker containers, NOTE: assumes you have docker installed' echo ' -d start up docker containers as well' echo ' --start [-b] starts frappe docker' echo ' -b starts bench as well' - echo ' --init [-e | -d] [sitename] initializes frappe-bench in docker and adds a site "sitename" (if not specified, it will default to site1.local)' + echo ' --init [-ed] [sitename] initializes frappe-bench in docker and adds a site "sitename" (if not specified, it will default to site1.local)' echo ' -e initializes frappe-bench and installs erpnext' echo ' -d initializes frappe-bench and enables developer mode' } @@ -31,83 +37,29 @@ function frappe_installer { echo "$1 added" } -if [[ $# -eq 0 ]]; then - echo "entering container" - docker exec -it frappe bash - -elif [ $1 == '--init' ]; then - site=$3 - if [ -z "$3" ]; then - site="site1.local" - fi - if [ -z "$2" ]; then - site="site1.local" - else - site=$2 - fi - echo "$site" - frappe_installer "$site" - if [ "$2" == '-e' ]; then - echo "installing erpnext" - docker exec -it frappe bash -c "bench get-app erpnext" - docker exec -it frappe bash -c "bench --site $site install-app erpnext" - echo "finished" - elif [ "$2" == '-d' ]; then - docker exec -it -u root frappe bash -c "bench --site $site set-config \"developer_mode\" 1 && bench clear-cache" - elif [ "$2" == '-ed' ]; then - echo "installing erpnext" - docker exec -it frappe bash -c "bench get-app erpnext" - docker exec -it frappe bash -c "bench --site $site install-app erpnext" - docker exec -it -u root frappe bash -c "bench --site $site set-config \"developer_mode\" 1 && bench clear-cache" - echo "finished" - fi - -elif [ "$1" == '--setup' ]; then - docker-compose build - if [ "$2" == '-d' ]; then - docker-compose up -d - else - docker-compose up - fi -elif [ "$1" == '--start' ]; then - docker-compose start - ./dbench -a - if [ "$2" == '-b' ]; then - docker exec -i frappe bash -c "bench start" - fi - -else - while getopts ':hadc:' option; do - case "$option" in - h) - display_usage - exit - ;; - a) - a=$(docker exec -i frappe bash -c "cd ~/frappe-bench && ls sites/*/site_config.json" | grep -o '/.\+/') - a="${a//$'\n'/ }" - a=$(echo $a | tr -d / ) - result="127.0.0.1 ${a}" - echo $result - docker exec -u root -i frappe bash -c "echo ${result} | tee --append /etc/hosts" - docker exec -itu root frappe bash -c "printf '# User rules for frappe\nfrappe ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers.d/frappe" - ;; - d) - docker exec -it -u root frappe bash -c "bench --site $OPTARG set-config \"developer_mode\" 1 && bench clear-cache" +eval set -- "$options" +while true; do + case "$1" in + -h | --help) + usage + ;; + -a | --add) + a=$(docker exec -i frappe bash -c "cd ~/frappe-bench && ls sites/*/site_config.json" | grep -o '/.\+/') + a="${a//$'\n'/ }" + a=$(echo "$a" | tr -d / ) + result="127.0.0.1 ${a}" + echo "$result" + docker exec -u root -i frappe bash -c "echo ${result} | tee --append /etc/hosts" + docker exec -itu root frappe bash -c "printf '# User rules for frappe\nfrappe ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers.d/frappe" + ;; + -d | --developer) + shift; # The arg is next in position args + docker exec -it -u root frappe bash -c "bench --site $$ set-config \"developer_mode\" 1 && bench clear-cache" ;; - c) - docker exec -it -u root frappe bash -c "bench $OPTARG" - ;; - \?) - echo "Invalid option: -$OPTARG" >&2 - usage - exit 1 - ;; - :) - echo "Option -$OPTARG requires an argument." >&2 - usage - exit 1 + --) + shift + break ;; esac - done -fi + shift +done \ No newline at end of file diff --git a/dbench.bak b/dbench.bak new file mode 100644 index 00000000..06ca10a4 --- /dev/null +++ b/dbench.bak @@ -0,0 +1,113 @@ +#!/bin/bash + +function usage { + echo "Usage: dbench [-hda [sitename] | --init [-ed] [sitename] | --setup [-d] | --start [-b] | -c \"\"]" + echo '' + echo 'where:' + echo ' -h show this help text' + echo ' -c send a command to the frappe container' + echo ' -d [sitename] enables developer mode for specified site' + echo ' -a adds site-names to /etc/hosts file in the container to facilitate multisite access' + echo ' --setup [-d] builds docker containers, NOTE: assumes you have docker installed' + echo ' -d start up docker containers as well' + echo ' --start [-b] starts frappe docker' + echo ' -b starts bench as well' + echo ' --init [-e | -d] [sitename] initializes frappe-bench in docker and adds a site "sitename" (if not specified, it will default to site1.local)' + echo ' -e initializes frappe-bench and installs erpnext' + echo ' -d initializes frappe-bench and enables developer mode' +} + +function frappe_installer { + echo "starting frappe_docker setup" + docker exec -i -u root frappe bash -c "cd /home/frappe && chown -R frappe:frappe ./*" + docker exec -it frappe bash -c "cd .. && bench init frappe-bench --ignore-exist --skip-redis-config-generation && cd frappe-bench" + docker exec -it frappe bash -c "mv Procfile_docker Procfile && mv sites/common_site_config_docker.json sites/common_site_config.json" + echo "frappe-bench folder setup" + docker exec -it -u root frappe bash -c "apt-get install vim -y && apt-get install sudo -y && usermod -aG sudo frappe && printf '# User rules for frappe\nfrappe ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers.d/frappe" + echo "adding $1" + docker exec -it frappe bash -c "bench new-site $1" + docker exec -i -u root frappe bash -c "echo 127.0.0.1 $1 >> /etc/hosts" + sudo su -c 'echo 127.0.0.1 $1 >> /etc/hosts' + echo "$1 added" +} + +if [[ $# -eq 0 ]]; then + echo "entering container" + docker exec -it frappe bash + +elif [ $1 == '--init' ]; then + site=$3 + if [ -z "$3" ]; then + site="site1.local" + fi + if [ -z "$2" ]; then + site="site1.local" + else + site=$2 + fi + echo "$site" + frappe_installer "$site" + if [ "$2" == '-e' ]; then + echo "installing erpnext" + docker exec -it frappe bash -c "bench get-app erpnext" + docker exec -it frappe bash -c "bench --site $site install-app erpnext" + echo "finished" + elif [ "$2" == '-d' ]; then + docker exec -it -u root frappe bash -c "bench --site $site set-config \"developer_mode\" 1 && bench clear-cache" + elif [ "$2" == '-ed' ]; then + echo "installing erpnext" + docker exec -it frappe bash -c "bench get-app erpnext" + docker exec -it frappe bash -c "bench --site $site install-app erpnext" + docker exec -it -u root frappe bash -c "bench --site $site set-config \"developer_mode\" 1 && bench clear-cache" + echo "finished" + fi + +elif [ "$1" == '--setup' ]; then + docker-compose build + if [ "$2" == '-d' ]; then + docker-compose up -d + else + docker-compose up + fi +elif [ "$1" == '--start' ]; then + docker-compose start + ./dbench -a + if [ "$2" == '-b' ]; then + docker exec -i frappe bash -c "bench start" + fi + +else + while getopts ':hadc:' option; do + case "$option" in + h) + display_usage + exit + ;; + a) + a=$(docker exec -i frappe bash -c "cd ~/frappe-bench && ls sites/*/site_config.json" | grep -o '/.\+/') + a="${a//$'\n'/ }" + a=$(echo $a | tr -d / ) + result="127.0.0.1 ${a}" + echo $result + docker exec -u root -i frappe bash -c "echo ${result} | tee --append /etc/hosts" + docker exec -itu root frappe bash -c "printf '# User rules for frappe\nfrappe ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers.d/frappe" + ;; + d) + docker exec -it -u root frappe bash -c "bench --site $OPTARG set-config \"developer_mode\" 1 && bench clear-cache" + ;; + c) + docker exec -it -u root frappe bash -c "bench $OPTARG" + ;; + \?) + echo "Invalid option: -$OPTARG" >&2 + usage + exit 1 + ;; + :) + echo "Option -$OPTARG requires an argument." >&2 + usage + exit 1 + ;; + esac + done +fi From 60b8eb1922a384925fddb2a5f08dbdeb72d5a45d Mon Sep 17 00:00:00 2001 From: chabad360 Date: Thu, 2 Aug 2018 15:18:54 -0700 Subject: [PATCH 02/21] remove dockerhub from travis, setup dbench more --- curl-travis | 3 --- dbench | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) delete mode 100644 curl-travis diff --git a/curl-travis b/curl-travis deleted file mode 100644 index 4a9c7e31..00000000 --- a/curl-travis +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash - -curl -H "Content-Type: application/json" --data '{"docker_tag": "env"}' -X POST https://registry.hub.docker.com/u/chabad360/frappe/trigger/$hubkey/ \ No newline at end of file diff --git a/dbench b/dbench index b90f5d65..bc1b43e9 100644 --- a/dbench +++ b/dbench @@ -54,7 +54,7 @@ while true; do ;; -d | --developer) shift; # The arg is next in position args - docker exec -it -u root frappe bash -c "bench --site $$ set-config \"developer_mode\" 1 && bench clear-cache" + docker exec -it -u root frappe bash -c "bench --site $1 set-config \"developer_mode\" 1 && bench clear-cache" ;; --) shift From 1581a9eff58734d58b1260d067fe159a5669f65d Mon Sep 17 00:00:00 2001 From: chabad360 Date: Thu, 2 Aug 2018 15:21:02 -0700 Subject: [PATCH 03/21] remove curl from travis --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 6564c319..a93fa8ab 100644 --- a/.travis.yml +++ b/.travis.yml @@ -35,5 +35,4 @@ script: - docker-compose ps | grep -i redis-socketio - docker-compose ps | grep -i mariadb - python test.py - - ./curl-travis - docker-compose stop \ No newline at end of file From 36d31df67a39cb1fc286cb10cc15f5139d127946 Mon Sep 17 00:00:00 2001 From: chabad360 Date: Thu, 2 Aug 2018 15:56:29 -0700 Subject: [PATCH 04/21] added most args, implemented setup --- dbench | 59 +++++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 38 insertions(+), 21 deletions(-) diff --git a/dbench b/dbench index bc1b43e9..f4ab2979 100644 --- a/dbench +++ b/dbench @@ -1,26 +1,34 @@ #!/bin/bash -options=$(getopt -o hd:ac: --long add,help,developer:,setup::,start::,init:: -- "$@") -[ $? -eq 0 ] || { +if ! options=$(getopt -o hd:ac:e:: --long add,help,developer:,setup::,start::,init:: -- "$@") +then echo "entering container" docker exec -it frappe bash -} +fi + +add=0 +setup=0 +start=0 +init=0 +dev=0 +erp=0 +mangr=0 +site=0 function usage { - echo "Usage: dbench [-hda [sitename] | --init [-ed] [sitename] | --setup [-d] | --start [-b] | -c \"\"]" + echo "Usage: dbench [-had sitename | --init [-e] [sitename] | --setup [-d] | --start [-b] | -c \"\"]" echo '' echo 'where:' echo ' -h show this help text' echo ' -c command send a command to bench in the container' - echo ' -d [sitename] enables developer mode for specified site' + echo ' -d sitename enables developer mode for specified site' echo ' -a adds site-names to /etc/hosts file in the container to facilitate multisite access' echo ' --setup [-d] builds docker containers, NOTE: assumes you have docker installed' echo ' -d start up docker containers as well' echo ' --start [-b] starts frappe docker' echo ' -b starts bench as well' - echo ' --init [-ed] [sitename] initializes frappe-bench in docker and adds a site "sitename" (if not specified, it will default to site1.local)' + echo ' --init [-e] [sitename] initializes frappe-bench in docker and adds a site "sitename" (if not specified, it will default to site1.local)' echo ' -e initializes frappe-bench and installs erpnext' - echo ' -d initializes frappe-bench and enables developer mode' } function frappe_installer { @@ -42,24 +50,33 @@ while true; do case "$1" in -h | --help) usage + exit 0 ;; -a | --add) - a=$(docker exec -i frappe bash -c "cd ~/frappe-bench && ls sites/*/site_config.json" | grep -o '/.\+/') - a="${a//$'\n'/ }" - a=$(echo "$a" | tr -d / ) - result="127.0.0.1 ${a}" - echo "$result" - docker exec -u root -i frappe bash -c "echo ${result} | tee --append /etc/hosts" - docker exec -itu root frappe bash -c "printf '# User rules for frappe\nfrappe ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers.d/frappe" + add=1 ;; -d | --developer) - shift; # The arg is next in position args - docker exec -it -u root frappe bash -c "bench --site $1 set-config \"developer_mode\" 1 && bench clear-cache" - ;; + shift; # The arg is next in position args + dev=1 + site=$optopt + ;; + -c) + docker exec -it frappe bash -c "$optopt" + ;; + --setup) + setup=1 + ;; + --init) + init=1 + site=$optopt + ;; --) - shift - break - ;; + break + ;; esac shift -done \ No newline at end of file +done + +if setup; then + docker-compose +fi \ No newline at end of file From 86755f4a650c0249671f74b2b061c8bba1cfa64b Mon Sep 17 00:00:00 2001 From: chabad360 Date: Thu, 2 Aug 2018 15:57:21 -0700 Subject: [PATCH 05/21] fixed chmod on travis --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index a93fa8ab..fccfe49f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,7 +17,6 @@ before_install: - chmod +x docker-compose - sudo mv docker-compose /usr/local/bin - chmod u+x ./dbench - - chmod u+x ./curl-travis install: - ./dbench --setup -d From 71bb7b340ef71f4414de20e7cb1563723e31288d Mon Sep 17 00:00:00 2001 From: chabad360 Date: Thu, 2 Aug 2018 16:03:25 -0700 Subject: [PATCH 06/21] update travis and start func --- .travis.yml | 2 +- dbench | 19 ++++++++++++++----- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index fccfe49f..480a8b47 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,7 +19,7 @@ before_install: - chmod u+x ./dbench install: - - ./dbench --setup -d + - ./dbench --setup -u - ./dbench --init - ./dbench --start - pip install --upgrade virtualenv diff --git a/dbench b/dbench index f4ab2979..0741f18a 100644 --- a/dbench +++ b/dbench @@ -1,6 +1,6 @@ #!/bin/bash -if ! options=$(getopt -o hd:ac:e:: --long add,help,developer:,setup::,start::,init:: -- "$@") +if ! options=$(getopt -o hd:ace --long add,help,developer:,setup,start,init -- "$@") then echo "entering container" docker exec -it frappe bash @@ -8,6 +8,7 @@ fi add=0 setup=0 +d=0 start=0 init=0 dev=0 @@ -23,8 +24,8 @@ function usage { echo ' -c command send a command to bench in the container' echo ' -d sitename enables developer mode for specified site' echo ' -a adds site-names to /etc/hosts file in the container to facilitate multisite access' - echo ' --setup [-d] builds docker containers, NOTE: assumes you have docker installed' - echo ' -d start up docker containers as well' + echo ' --setup [-u] builds docker containers, NOTE: assumes you have docker installed' + echo ' -u start up docker containers as well' echo ' --start [-b] starts frappe docker' echo ' -b starts bench as well' echo ' --init [-e] [sitename] initializes frappe-bench in docker and adds a site "sitename" (if not specified, it will default to site1.local)' @@ -58,11 +59,14 @@ while true; do -d | --developer) shift; # The arg is next in position args dev=1 - site=$optopt + site=$1 ;; -c) docker exec -it frappe bash -c "$optopt" ;; + -u) + d=1 + ;; --setup) setup=1 ;; @@ -78,5 +82,10 @@ while true; do done if setup; then - docker-compose + docker-compose build + if d; then + docker-compose -d + else + docker-compose + fi fi \ No newline at end of file From 949a5051000682d68ea145e9cdf0540c64309abe Mon Sep 17 00:00:00 2001 From: chabad360 Date: Thu, 2 Aug 2018 16:07:45 -0700 Subject: [PATCH 07/21] update dbench to include -u --- dbench | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/dbench b/dbench index 0741f18a..0df6f5df 100644 --- a/dbench +++ b/dbench @@ -1,6 +1,6 @@ #!/bin/bash -if ! options=$(getopt -o hd:ace --long add,help,developer:,setup,start,init -- "$@") +if ! options=$(getopt -o hd:aceu --long add,help,developer:,setup,start,init -- "$@") then echo "entering container" docker exec -it frappe bash @@ -88,4 +88,12 @@ if setup; then else docker-compose fi + exit 0 +fi + +if init; then + if ! site; then + site="site1.local" + fi + frappe_installer site fi \ No newline at end of file From 4acb2cb6caf6c10a59551b21e9ad16d344a4e2c6 Mon Sep 17 00:00:00 2001 From: chabad360 Date: Thu, 2 Aug 2018 16:45:07 -0700 Subject: [PATCH 08/21] fixing missing var tags --- dbench | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/dbench b/dbench index 0df6f5df..411afe84 100644 --- a/dbench +++ b/dbench @@ -72,7 +72,7 @@ while true; do ;; --init) init=1 - site=$optopt + site="$optopt" ;; --) break @@ -81,9 +81,9 @@ while true; do shift done -if setup; then +if $setup; then docker-compose build - if d; then + if $d; then docker-compose -d else docker-compose @@ -91,9 +91,9 @@ if setup; then exit 0 fi -if init; then - if ! site; then +if $init; then + if ! $site; then site="site1.local" fi - frappe_installer site + frappe_installer $site fi \ No newline at end of file From 6013270c231ee6ea274e45a502b151bb54f4d11b Mon Sep 17 00:00:00 2001 From: chabad360 Date: Thu, 2 Aug 2018 16:50:33 -0700 Subject: [PATCH 09/21] this should work --- dbench | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/dbench b/dbench index 411afe84..d776619f 100644 --- a/dbench +++ b/dbench @@ -81,9 +81,9 @@ while true; do shift done -if $setup; then +if [ $setup == 1 ]; then docker-compose build - if $d; then + if [ $d == 1 ]; then docker-compose -d else docker-compose @@ -91,7 +91,7 @@ if $setup; then exit 0 fi -if $init; then +if [ $init == 1 ]; then if ! $site; then site="site1.local" fi From b9e89a7d2f7d0b057116c571fe6b3e07e65f17ce Mon Sep 17 00:00:00 2001 From: chabad360 Date: Thu, 2 Aug 2018 17:03:09 -0700 Subject: [PATCH 10/21] dbench should work for init --- dbench | 44 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 37 insertions(+), 7 deletions(-) diff --git a/dbench b/dbench index d776619f..f5e53186 100644 --- a/dbench +++ b/dbench @@ -1,6 +1,6 @@ #!/bin/bash -if ! options=$(getopt -o hd:aceu --long add,help,developer:,setup,start,init -- "$@") +if ! options=$(getopt -o hdaceumb --long add,help,developer,setup,start,init -- "$@") then echo "entering container" docker exec -it frappe bash @@ -13,11 +13,13 @@ start=0 init=0 dev=0 erp=0 -mangr=0 +mgr=0 site=0 +bench=0 +initf=0 function usage { - echo "Usage: dbench [-had sitename | --init [-e] [sitename] | --setup [-d] | --start [-b] | -c \"\"]" + echo "Usage: dbench " echo '' echo 'where:' echo ' -h show this help text' @@ -59,7 +61,7 @@ while true; do -d | --developer) shift; # The arg is next in position args dev=1 - site=$1 + site="$optopt" ;; -c) docker exec -it frappe bash -c "$optopt" @@ -67,6 +69,12 @@ while true; do -u) d=1 ;; + -m) + mgr=1 + ;; + -b) + bench=1 + ;; --setup) setup=1 ;; @@ -74,6 +82,9 @@ while true; do init=1 site="$optopt" ;; + --start) + start=1 + ;; --) break ;; @@ -84,9 +95,9 @@ done if [ $setup == 1 ]; then docker-compose build if [ $d == 1 ]; then - docker-compose -d + docker-compose up -d else - docker-compose + docker-compose up fi exit 0 fi @@ -96,4 +107,23 @@ if [ $init == 1 ]; then site="site1.local" fi frappe_installer $site -fi \ No newline at end of file +fi + +if [ $mgr == 1 ]; then + docker exec -it frappe bash -c "bench setup manager" +fi + +if [ $erp == 1 ]; then + echo "installing erpnext" + docker exec -it frappe bash -c "bench get-app erpnext" + docker exec -it frappe bash -c "bench --site $site install-app erpnext" + docker exec -it -u root frappe bash -c "bench --site $site set-config \"developer_mode\" 1 && bench clear-cache" + echo "finished" +fi + +if [ $d == 1 ]; then + docker exec -it -u root frappe bash -c "bench --site $site set-config \"developer_mode\" 1 && bench clear-cache" + exit 0 +fi + +exit 0 \ No newline at end of file From ee3c4147a446cdf8d73e2cfaa8ecb089cdcdf59c Mon Sep 17 00:00:00 2001 From: chabad360 Date: Thu, 2 Aug 2018 17:16:58 -0700 Subject: [PATCH 11/21] added start to dbanch and testing if optopt works --- .travis.yml | 2 +- dbench | 35 +++++++++++++++++++++++++---------- 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/.travis.yml b/.travis.yml index 480a8b47..83d0be29 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,7 +20,7 @@ before_install: install: - ./dbench --setup -u - - ./dbench --init + - ./dbench --init site2.local - ./dbench --start - pip install --upgrade virtualenv - virtualenv -p python3 testenv diff --git a/dbench b/dbench index f5e53186..99a2060c 100644 --- a/dbench +++ b/dbench @@ -106,19 +106,34 @@ if [ $init == 1 ]; then if ! $site; then site="site1.local" fi + frappe_installer $site + + if [ $mgr == 1 ]; then + echo "installing bench manager" + docker exec -it frappe bash -c "bench setup manager" + fi + + if [ $erp == 1 ]; then + echo "installing erpnext" + docker exec -it frappe bash -c "bench get-app erpnext" + docker exec -it frappe bash -c "bench --site $site install-app erpnext" + docker exec -it -u root frappe bash -c "bench --site $site set-config \"developer_mode\" 1 && bench clear-cache" + echo "finished" + fi + + if [ $d == 1 ]; then + docker exec -it -u root frappe bash -c "bench --site $site set-config \"developer_mode\" 1 && bench clear-cache" + fi + exit 0 fi -if [ $mgr == 1 ]; then - docker exec -it frappe bash -c "bench setup manager" -fi - -if [ $erp == 1 ]; then - echo "installing erpnext" - docker exec -it frappe bash -c "bench get-app erpnext" - docker exec -it frappe bash -c "bench --site $site install-app erpnext" - docker exec -it -u root frappe bash -c "bench --site $site set-config \"developer_mode\" 1 && bench clear-cache" - echo "finished" +if [ $start == 1 ]; then + docker-compose start + ./dbench -a + if [ $bench == 1 ]; then + docker exec -it frappe bash -c "bench start" + fi fi if [ $d == 1 ]; then From e6af58086371f7dfecd376a8c2951bee2554d236 Mon Sep 17 00:00:00 2001 From: chabad360 Date: Thu, 2 Aug 2018 17:24:19 -0700 Subject: [PATCH 12/21] fixed somethings in init should work now --- dbench | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/dbench b/dbench index 99a2060c..9d5fd224 100644 --- a/dbench +++ b/dbench @@ -16,10 +16,9 @@ erp=0 mgr=0 site=0 bench=0 -initf=0 function usage { - echo "Usage: dbench " + echo "Usage: dbench [ --setup [-d] | --init [-med] [sitename] | " echo '' echo 'where:' echo ' -h show this help text' @@ -103,7 +102,7 @@ if [ $setup == 1 ]; then fi if [ $init == 1 ]; then - if ! $site; then + if [ "$site" == 0 ] || [ "$site" == "" ]; then site="site1.local" fi @@ -128,6 +127,14 @@ if [ $init == 1 ]; then exit 0 fi +if [ $d == 1 ]; then + if [ "$site" == 0 ]; then + site="site1.local" + fi + docker exec -it -u root frappe bash -c "bench --site $site set-config \"developer_mode\" 1 && bench clear-cache" + exit 0 +fi + if [ $start == 1 ]; then docker-compose start ./dbench -a From 6bab2b4cf72a96f95dc1bec3fb87e48a881ad06d Mon Sep 17 00:00:00 2001 From: chabad360 Date: Thu, 2 Aug 2018 17:33:48 -0700 Subject: [PATCH 13/21] trying a few other things --- dbench | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/dbench b/dbench index 9d5fd224..1bb82f73 100644 --- a/dbench +++ b/dbench @@ -63,7 +63,8 @@ while true; do site="$optopt" ;; -c) - docker exec -it frappe bash -c "$optopt" + shift + docker exec -it frappe bash -c "bench $optarg" ;; -u) d=1 @@ -79,7 +80,7 @@ while true; do ;; --init) init=1 - site="$optopt" + site="$optarg" ;; --start) start=1 From ea945b6917c705af48d2bfaad4e1c06b13b70a29 Mon Sep 17 00:00:00 2001 From: chabad360 Date: Thu, 2 Aug 2018 17:47:25 -0700 Subject: [PATCH 14/21] passing optional args nicely in getopt is a pain --- dbench | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/dbench b/dbench index 1bb82f73..311b1785 100644 --- a/dbench +++ b/dbench @@ -60,11 +60,11 @@ while true; do -d | --developer) shift; # The arg is next in position args dev=1 - site="$optopt" + site="$1" ;; -c) shift - docker exec -it frappe bash -c "bench $optarg" + docker exec -it frappe bash -c "bench $*" ;; -u) d=1 @@ -80,7 +80,6 @@ while true; do ;; --init) init=1 - site="$optarg" ;; --start) start=1 @@ -92,6 +91,10 @@ while true; do shift done +if [ $site == "" ]; then + site=$1 +fi + if [ $setup == 1 ]; then docker-compose build if [ $d == 1 ]; then From 48e98086f379c0c3e353223b949d9d9effde895d Mon Sep 17 00:00:00 2001 From: chabad360 Date: Thu, 2 Aug 2018 17:57:04 -0700 Subject: [PATCH 15/21] trashing getopt found a better way --- dbench | 72 +++++++++++++++++++++++++++++++--------------------------- 1 file changed, 39 insertions(+), 33 deletions(-) diff --git a/dbench b/dbench index 311b1785..8006bdb5 100644 --- a/dbench +++ b/dbench @@ -1,22 +1,5 @@ #!/bin/bash -if ! options=$(getopt -o hdaceumb --long add,help,developer,setup,start,init -- "$@") -then - echo "entering container" - docker exec -it frappe bash -fi - -add=0 -setup=0 -d=0 -start=0 -init=0 -dev=0 -erp=0 -mgr=0 -site=0 -bench=0 - function usage { echo "Usage: dbench [ --setup [-d] | --init [-med] [sitename] | " echo '' @@ -47,9 +30,25 @@ function frappe_installer { echo "$1 added" } -eval set -- "$options" -while true; do - case "$1" in + +add=0 +setup=0 +d=0 +start=0 +init=0 +dev=0 +erp=0 +mgr=0 +site=0 +bench=0 +cmd=0 + +positional=() + +while [[ $# -gt 0 ]]; do +key="$1" + + case "key" in -h | --help) usage exit 0 @@ -58,13 +57,10 @@ while true; do add=1 ;; -d | --developer) - shift; # The arg is next in position args dev=1 - site="$1" ;; -c) - shift - docker exec -it frappe bash -c "bench $*" + cmd=1 ;; -u) d=1 @@ -84,16 +80,14 @@ while true; do --start) start=1 ;; - --) - break + *) + positional+="$key" ;; esac shift done - -if [ $site == "" ]; then - site=$1 -fi +set -- "${POSITIONAL[@]}" +site="$1" if [ $setup == 1 ]; then docker-compose build @@ -106,9 +100,6 @@ if [ $setup == 1 ]; then fi if [ $init == 1 ]; then - if [ "$site" == 0 ] || [ "$site" == "" ]; then - site="site1.local" - fi frappe_installer $site @@ -152,4 +143,19 @@ if [ $d == 1 ]; then exit 0 fi +if [ $cmd == 1 ]; then + docker exec -it frappe bash -c "bench $*" + exit 0 +fi + +if [ $add == 1 ]; then + a=$(docker exec -i frappe bash -c "cd ~/frappe-bench && ls sites/*/site_config.json" | grep -o '/.\+/') + a="${a//$'\n'/ }" + a=$(echo $a | tr -d / ) + result="127.0.0.1 ${a}" + echo $result + docker exec -u root -i frappe bash -c "echo ${result} | tee --append /etc/hosts" + docker exec -itu root frappe bash -c "printf '# User rules for frappe\nfrappe ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers.d/frappe" + +fi exit 0 \ No newline at end of file From c5daea64ad5961e5465ac13269fb95234e657c33 Mon Sep 17 00:00:00 2001 From: chabad360 Date: Thu, 2 Aug 2018 18:00:02 -0700 Subject: [PATCH 16/21] one small typo screwed everything --- dbench | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dbench b/dbench index 8006bdb5..e1354b49 100644 --- a/dbench +++ b/dbench @@ -48,7 +48,7 @@ positional=() while [[ $# -gt 0 ]]; do key="$1" - case "key" in + case "$key" in -h | --help) usage exit 0 From 56cf9f546c62db6338d65a045eb99a235552c43f Mon Sep 17 00:00:00 2001 From: chabad360 Date: Thu, 2 Aug 2018 18:19:55 -0700 Subject: [PATCH 17/21] case can be really annoying --- dbench | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/dbench b/dbench index e1354b49..aacc1cb2 100644 --- a/dbench +++ b/dbench @@ -33,7 +33,7 @@ function frappe_installer { add=0 setup=0 -d=0 +up=0 start=0 init=0 dev=0 @@ -63,7 +63,7 @@ key="$1" cmd=1 ;; -u) - d=1 + up=1 ;; -m) mgr=1 @@ -86,12 +86,13 @@ key="$1" esac shift done -set -- "${POSITIONAL[@]}" +set -- "${positional[@]}" + site="$1" if [ $setup == 1 ]; then docker-compose build - if [ $d == 1 ]; then + if [ $up == 1 ]; then docker-compose up -d else docker-compose up @@ -116,7 +117,7 @@ if [ $init == 1 ]; then echo "finished" fi - if [ $d == 1 ]; then + if [ $dev == 1 ]; then docker exec -it -u root frappe bash -c "bench --site $site set-config \"developer_mode\" 1 && bench clear-cache" fi exit 0 From 3502f053e9d4086d0197f66852ac01ae72c3f9e8 Mon Sep 17 00:00:00 2001 From: chabad360 Date: Thu, 2 Aug 2018 18:31:03 -0700 Subject: [PATCH 18/21] gonna push it --- .travis.yml | 4 ++-- dbench | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 83d0be29..aad56f39 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,11 +16,11 @@ before_install: - curl -L https://github.com/docker/compose/releases/download/${DOCKER_COMPOSE_VERSION}/docker-compose-`uname -s`-`uname -m` > docker-compose - chmod +x docker-compose - sudo mv docker-compose /usr/local/bin - - chmod u+x ./dbench + - chmod ugo+x ./dbench install: - ./dbench --setup -u - - ./dbench --init site2.local + - ./dbench --init -med - ./dbench --start - pip install --upgrade virtualenv - virtualenv -p python3 testenv diff --git a/dbench b/dbench index aacc1cb2..bfcb6940 100644 --- a/dbench +++ b/dbench @@ -81,7 +81,7 @@ key="$1" start=1 ;; *) - positional+="$key" + positional+=("$key") ;; esac shift From 7588546871e53151272c95a497dde00c43769da6 Mon Sep 17 00:00:00 2001 From: chabad360 Date: Thu, 2 Aug 2018 18:32:22 -0700 Subject: [PATCH 19/21] small recomendation from shellcheck --- dbench | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dbench b/dbench index bfcb6940..33c6965b 100644 --- a/dbench +++ b/dbench @@ -102,7 +102,7 @@ fi if [ $init == 1 ]; then - frappe_installer $site + frappe_installer "$site" if [ $mgr == 1 ]; then echo "installing bench manager" From a2ce6c729ae07c6bddb20ad4744eee9971ed8a39 Mon Sep 17 00:00:00 2001 From: chabad360 Date: Thu, 2 Aug 2018 18:37:37 -0700 Subject: [PATCH 20/21] making a few fixes --- dbench | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/dbench b/dbench index 33c6965b..28e71cb9 100644 --- a/dbench +++ b/dbench @@ -123,7 +123,7 @@ if [ $init == 1 ]; then exit 0 fi -if [ $d == 1 ]; then +if [ $dev == 1 ]; then if [ "$site" == 0 ]; then site="site1.local" fi @@ -139,7 +139,7 @@ if [ $start == 1 ]; then fi fi -if [ $d == 1 ]; then +if [ $dev == 1 ]; then docker exec -it -u root frappe bash -c "bench --site $site set-config \"developer_mode\" 1 && bench clear-cache" exit 0 fi @@ -152,9 +152,9 @@ fi if [ $add == 1 ]; then a=$(docker exec -i frappe bash -c "cd ~/frappe-bench && ls sites/*/site_config.json" | grep -o '/.\+/') a="${a//$'\n'/ }" - a=$(echo $a | tr -d / ) + a=$(echo "$a" | tr -d / ) result="127.0.0.1 ${a}" - echo $result + echo "$result" docker exec -u root -i frappe bash -c "echo ${result} | tee --append /etc/hosts" docker exec -itu root frappe bash -c "printf '# User rules for frappe\nfrappe ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers.d/frappe" From 2aabd6b45ae446540390676484f1014d97494519 Mon Sep 17 00:00:00 2001 From: chabad360 Date: Thu, 2 Aug 2018 18:46:27 -0700 Subject: [PATCH 21/21] screwred up travis should build now --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index aad56f39..c755b13e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,7 +20,7 @@ before_install: install: - ./dbench --setup -u - - ./dbench --init -med + - ./dbench --init -m -e -d - ./dbench --start - pip install --upgrade virtualenv - virtualenv -p python3 testenv