From 8a6aef897de6fecf34b7829d11b4f856f0f68a86 Mon Sep 17 00:00:00 2001 From: Baohua Yang Date: Fri, 12 May 2017 13:42:40 +0800 Subject: [PATCH] Support colorful cmd --- hyperledger/1.0/scripts/download_images.sh | 8 +++++--- hyperledger/1.0/scripts/header.sh | 19 +++++++++++++++++++ hyperledger/1.0/scripts/setup_Docker.sh | 15 +++++++++++---- hyperledger/1.0/scripts/start_fabric.sh | 6 ++++-- 4 files changed, 39 insertions(+), 9 deletions(-) create mode 100644 hyperledger/1.0/scripts/header.sh diff --git a/hyperledger/1.0/scripts/download_images.sh b/hyperledger/1.0/scripts/download_images.sh index 8639c279..381c0626 100644 --- a/hyperledger/1.0/scripts/download_images.sh +++ b/hyperledger/1.0/scripts/download_images.sh @@ -1,11 +1,13 @@ -#! /bin/bash +#!/usr/bin/env bash + +source ./header.sh ARCH=x86_64 BASE_VERSION=1.0.0-preview PROJECT_VERSION=1.0.0-preview IMG_VERSION=0.9.2 -echo "Downloading images from DockerHub..." +echo_b "Downloading images from DockerHub..." docker pull yeasy/hyperledger-fabric-base:$IMG_VERSION \ && docker pull yeasy/hyperledger-fabric-peer:$IMG_VERSION \ @@ -15,7 +17,7 @@ docker pull yeasy/hyperledger-fabric-base:$IMG_VERSION \ # Only useful for debugging # docker pull yeasy/hyperledger-fabric -echo "Rename images with official tags..." +echo_b "Rename images with official tags..." docker tag yeasy/hyperledger-fabric-peer:$IMG_VERSION hyperledger/fabric-peer \ && docker tag yeasy/hyperledger-fabric-orderer:$IMG_VERSION hyperledger/fabric-orderer \ && docker tag yeasy/hyperledger-fabric-ca:$IMG_VERSION hyperledger/fabric-ca \ diff --git a/hyperledger/1.0/scripts/header.sh b/hyperledger/1.0/scripts/header.sh new file mode 100644 index 00000000..7620a87e --- /dev/null +++ b/hyperledger/1.0/scripts/header.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env bash + +## DO NOT MODIFY THE FOLLOWING PART, UNLESS YOU KNOW WHAT IT MEANS ## +echo_r () { + [ $# -ne 1 ] && return 0 + echo -e "\033[31m$1\033[0m" +} +echo_g () { + [ $# -ne 1 ] && return 0 + echo -e "\033[32m$1\033[0m" +} +echo_y () { + [ $# -ne 1 ] && return 0 + echo -e "\033[33m$1\033[0m" +} +echo_b () { + [ $# -ne 1 ] && return 0 + echo -e "\033[34m$1\033[0m" +} \ No newline at end of file diff --git a/hyperledger/1.0/scripts/setup_Docker.sh b/hyperledger/1.0/scripts/setup_Docker.sh index 310f3a1a..de864461 100644 --- a/hyperledger/1.0/scripts/setup_Docker.sh +++ b/hyperledger/1.0/scripts/setup_Docker.sh @@ -1,22 +1,29 @@ -#! /bin/bash +#!/usr/bin/env bash + +source ./header.sh if [ xroot != x$(whoami) ] then - echo "You must run as root (Hint: sudo su)" + echo_r "You must run as root (Hint: sudo su)" exit fi apt-get update && apt-get install curl -y -echo "Install Docker..." +echo_b "Install Docker..." wget -qO- https://get.docker.com/ | sh sudo service docker stop nohup sudo docker daemon --api-cors-header="*" -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock& -echo "Install Docker-Compose..." +echo_g "Docker Installation Done" + +echo_b "Install Docker-Compose..." curl -L https://github.com/docker/compose/releases/download/1.8.0/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose chmod +x /usr/local/bin/docker-compose docker-compose --version + +echo_g "Docker-Compose Installation Done" + diff --git a/hyperledger/1.0/scripts/start_fabric.sh b/hyperledger/1.0/scripts/start_fabric.sh index 61d1d62a..7dd1beb2 100644 --- a/hyperledger/1.0/scripts/start_fabric.sh +++ b/hyperledger/1.0/scripts/start_fabric.sh @@ -1,4 +1,6 @@ -#! /bin/bash +#!/usr/bin/env bash + +source ./header.sh COMPOSE_FILE=${1:-"docker-compose.yml"} @@ -6,6 +8,6 @@ bash ./setup_Docker.sh bash ./download_images.sh -echo "Start up with ${COMPOSE_FILE}" +echo_b "Start up with ${COMPOSE_FILE}" docker-compose -f ${COMPOSE_FILE} up -d