From 3bf572b7a4b11b095406befcdf0282427f5e572c Mon Sep 17 00:00:00 2001 From: Arian Acosta Date: Sat, 15 Jul 2017 13:52:23 -0400 Subject: [PATCH] added colors --- docker-sync.yml | 2 +- env-example | 10 ++++++++-- sync.sh | 49 +++++++++++++++++++++++++++++++++++-------------- 3 files changed, 44 insertions(+), 17 deletions(-) diff --git a/docker-sync.yml b/docker-sync.yml index 1da12b77..0a3b4394 100644 --- a/docker-sync.yml +++ b/docker-sync.yml @@ -8,6 +8,6 @@ syncs: src: '${APPLICATION}' # host source directory sync_userid: 1000 # giving permissions to www-data user (as defined in nginx and php-fpm Dockerfiles) - sync_strategy: 'native_osx' # for windows use 'unison', for linux docker-sync is not necessary + sync_strategy: '${DOCKER_SYNC_STRATEGY}' # for osx use 'native_osx', for windows use 'unison' sync_excludes: ['laradock', 'ignored_folder_example'] # ignored directories diff --git a/env-example b/env-example index 23eba15a..91d295cc 100644 --- a/env-example +++ b/env-example @@ -255,6 +255,13 @@ CADDY_CUSTOM_CADDYFILE=./caddy/Caddyfile LARAVEL_ECHO_SERVER_PORT=6001 +### DOCKER-SYNC ################################################################################################ + +# osx: 'native_osx' (default) +# windows: 'unison' +# linux: docker-sync not required + +DOCKER_SYNC_STRATEGY=native_osx ##### TO BE CONTINUE ................................. @@ -262,8 +269,6 @@ LARAVEL_ECHO_SERVER_PORT=6001 # ......... # ......... - - ############################ # Miscellaneous ############################ @@ -281,3 +286,4 @@ PHP_IDE_CONFIG=serverName=laradock # Fix for windows users to make sure the application path works. COMPOSE_CONVERT_WINDOWS_PATHS=1 + diff --git a/sync.sh b/sync.sh index c452eb1e..3cf8bf0a 100755 --- a/sync.sh +++ b/sync.sh @@ -1,39 +1,60 @@ #!/bin/bash + +# prints colored text +print_style () { + + if [ "$2" == "info" ] ; then + COLOR="1;96m"; + elif [ "$2" == "success" ] ; then + COLOR="1;92m"; + elif [ "$2" == "warning" ] ; then + COLOR="1;93m"; + elif [ "$2" == "danger" ] ; then + COLOR="1;31m"; + else #white + COLOR="1;97m"; + fi + + printf "\e[$COLOR%-6s\e[m" "$1"; +} + if [[ $# -eq 0 ]] ; then - printf "Available commands:\n"; - printf " install\t\t Installs docker-sync gem on the host machine.\n"; - printf " up \t Starts docker-sync and runs docker compose.\n"; - printf " down \t\t Stops containers and docker-sync.\n"; - printf " trigger \t\t Manually triggers the synchronization of files.\n"; - printf " clean \t\t Removes all synched files from docker-sync container.\n"; + print_style "Invalid argument." 'danger'; printf " Available commands:\n"; + print_style " install" "success"; printf "\t\t Installs docker-sync gem on the host machine.\n"; + print_style " up " "success"; printf "\t Starts docker-sync and runs docker compose.\n"; + print_style " down" "success"; printf "\t\t\t Stops containers and docker-sync.\n"; + print_style " trigger" "success"; printf "\t\t Manually triggers the synchronization of files.\n"; + print_style " clean" "warning"; printf "\t\t Removes all synched files from docker-sync container.\n"; + exit 1 fi if [ "$1" == "up" ] ; then - printf "Initializing Docker Sync (may take several minutes the first time)"; + print_style "Initializing Docker Sync\n" 'info'; + print_style "(May take a long time (15min+) on the 'Looking for changes' step the first time)\n" 'warning'; docker-sync start; - printf "Initializing Docker Compose"; + print_style "Initializing Docker Compose\n" 'info'; shift; # removing first argument docker-compose -f docker-compose.yml -f docker-compose.sync.yml up -d ${@}; elif [ "$1" == "down" ]; then - printf "Stopping Docker Compose"; + print_style "Stopping Docker Compose\n" 'info'; docker-compose down; - printf "Stopping Docker Sync"; + print_style "Stopping Docker Sync\n" 'info'; docker-sync stop; elif [ "$1" == "install" ]; then - printf "Installing docker-sync"; + print_style "Installing docker-sync" 'info'; gem install docker-sync; elif [ "$1" == "trigger" ]; then - printf "Manually triggering sync between host and docker-sync container."; + print_style "Manually triggering sync between host and docker-sync container.\n" 'info'; docker-sync sync; elif [ "$1" == "clean" ]; then - printf "Removing and cleaning up files from the docker-sync container."; + print_style "Removing and cleaning up files from the docker-sync container.\n" 'warning'; docker-sync clean; else - printf "Invalid argument. Use 'up','down','install','trigger' or 'clean' "; + print_style "Invalid argument. Use 'up','down','install','trigger' or 'clean'\n" 'danger'; fi