Skip to content

Commit

Permalink
[CE-196] Fix script mis-usage with alias
Browse files Browse the repository at this point in the history
Alias cannot be used inside shell scripts.

Also fix the formating to use tab uniquely.

Change-Id: I5de30b2df23b20008d6ccaaadf825c17a1feca44
Signed-off-by: Baohua Yang <yangbaohua@gmail.com>
  • Loading branch information
yeasy committed Dec 14, 2017
1 parent 1b9f8ba commit 79945bf
Show file tree
Hide file tree
Showing 14 changed files with 211 additions and 139 deletions.
24 changes: 13 additions & 11 deletions scripts/header.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,26 @@ PROJECT=cello

## 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"
[ $# -ne 1 ] && return 0
echo -e "\033[31m$1\033[0m"
}
echo_g () {
[ $# -ne 1 ] && return 0
echo -e "\033[32m$1\033[0m"
[ $# -ne 1 ] && return 0
echo -e "\033[32m$1\033[0m"
}
echo_y () {
[ $# -ne 1 ] && return 0
echo -e "\033[33m$1\033[0m"
[ $# -ne 1 ] && return 0
echo -e "\033[33m$1\033[0m"
}
echo_b () {
[ $# -ne 1 ] && return 0
echo -e "\033[34m$1\033[0m"
[ $# -ne 1 ] && return 0
echo -e "\033[34m$1\033[0m"
}

pull_image() {
[ $# -ne 1 ] && return 0
name=$1
[[ "$(sudo docker images -q ${name} 2> /dev/null)" == "" ]] && echo_r "Not found ${name}, may need some time to pull it down..." && sudo docker pull ${name}
[ $# -ne 1 ] && return 0
name=$1
[[ "$(sudo docker images -q ${name} 2> /dev/null)" == "" ]] \
&& echo_r "Not found ${name}, may need some time to pull it down..." \
&& sudo docker pull ${name}
}
16 changes: 11 additions & 5 deletions scripts/master_node/build_js.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,19 @@
# Detecting whether can import the header file to render colorful cli output
# Need add choice option
if [ -f ../header.sh ]; then
source ../header.sh
source ../header.sh
elif [ -f scripts/header.sh ]; then
source scripts/header.sh
source scripts/header.sh
else
alias echo_r="echo"
alias echo_g="echo"
alias echo_b="echo"
echo_r() {
echo "$@"
}
echo_g() {
echo "$@"
}
echo_b() {
echo "$@"
}
fi


Expand Down
16 changes: 11 additions & 5 deletions scripts/master_node/download_images.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,19 @@
# Detecting whether can import the header file to render colorful cli output
# Need add choice option
if [ -f ../header.sh ]; then
source ../header.sh
source ../header.sh
elif [ -f scripts/header.sh ]; then
source scripts/header.sh
source scripts/header.sh
else
alias echo_r="echo"
alias echo_g="echo"
alias echo_b="echo"
echo_r() {
echo "$@"
}
echo_g() {
echo "$@"
}
echo_b() {
echo "$@"
}
fi

echo_b "This script will setup the docker images for master node"
Expand Down
17 changes: 11 additions & 6 deletions scripts/master_node/npm_install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,21 @@
# Detecting whether can import the header file to render colorful cli output
# Need add choice option
if [ -f ../header.sh ]; then
source ../header.sh
source ../header.sh
elif [ -f scripts/header.sh ]; then
source scripts/header.sh
source scripts/header.sh
else
alias echo_r="echo"
alias echo_g="echo"
alias echo_b="echo"
echo_r() {
echo "$@"
}
echo_g() {
echo "$@"
}
echo_b() {
echo "$@"
}
fi


echo_b "Start install npm packages..."
docker-compose -f docker-compose-npm-install.yml up --force-recreate

Expand Down
16 changes: 11 additions & 5 deletions scripts/master_node/redeploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,19 @@
# Detecting whether can import the header file to render colorful cli output
# Need add choice option
if [ -f ../header.sh ]; then
source ../header.sh
source ../header.sh
elif [ -f scripts/header.sh ]; then
source scripts/header.sh
source scripts/header.sh
else
alias echo_r="echo"
alias echo_g="echo"
alias echo_b="echo"
echo_r() {
echo "$@"
}
echo_g() {
echo "$@"
}
echo_b() {
echo "$@"
}
fi

if [ "$#" -ne 1 ]; then
Expand Down
122 changes: 64 additions & 58 deletions scripts/master_node/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,34 @@
# Detecting whether can import the header file to render colorful cli output
# Need add choice option
if [ -f ../header.sh ]; then
source ../header.sh
source ../header.sh
elif [ -f scripts/header.sh ]; then
source scripts/header.sh
source scripts/header.sh
else
alias echo_r="echo"
alias echo_g="echo"
alias echo_b="echo"
echo_r() {
echo "$@"
}
echo_g() {
echo "$@"
}
echo_b() {
echo "$@"
}
fi

# collect ID from /etc/os-release as distribution name
# tested on debian,ubuntu,mint , centos,fedora ,opensuse
function get_distribution {
distribution="Unknown"
while read -r line
do
element=$(echo $line | cut -f1 -d=)
if [ "$element" = "ID" ]
then
distribution=$(echo $line | cut -f2 -d=)
fi
done < "/etc/os-release"
echo "${distribution//\"}"
get_distribution() {
distribution="Unknown"
while read -r line
do
element=$(echo $line | cut -f1 -d=)
if [ "$element" = "ID" ]
then
distribution=$(echo $line | cut -f2 -d=)
fi
done < "/etc/os-release"
echo "${distribution//\"}"
}

USER=`whoami`
Expand All @@ -41,53 +47,53 @@ DB_DIR=/opt/${PROJECT}/mongo

echo_b "Install python-pip, tox, and docker-engine"
case $DISTRO in
ubuntu)
sudo apt-get update && sudo apt-get install -y curl python-pip tox;
echo_b "Checking to install Docker-engine..."
command -v docker >/dev/null 2>&1 || { echo_r >&2 "No docker-engine found, try installing"; curl -sSL https://get.docker.com/ | sh; sudo service docker restart; }
;;
linuxmint)
sudo apt-get install apt-transport-https ca-certificates -y
sudo apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D
sudo echo deb https://apt.dockerproject.org/repo ubuntu-xenial main >> /etc/apt/sources.list.d/docker.list
sudo apt-get update
sudo apt-get purge lxc-docker
sudo apt-get install python-pip
sudo apt-get install linux-image-extra-$(uname -r) -y
sudo apt-get install docker-engine cgroup-lite apparmor -y
sudo service docker start
;;
ubuntu)
sudo apt-get update && sudo apt-get install -y curl python-pip tox;
echo_b "Checking to install Docker-engine..."
command -v docker >/dev/null 2>&1 || { echo_r >&2 "No docker-engine found, try installing"; curl -sSL https://get.docker.com/ | sh; sudo service docker restart; }
;;
linuxmint)
sudo apt-get install apt-transport-https ca-certificates -y
sudo apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D
sudo echo deb https://apt.dockerproject.org/repo ubuntu-xenial main >> /etc/apt/sources.list.d/docker.list
sudo apt-get update
sudo apt-get purge lxc-docker
sudo apt-get install python-pip
sudo apt-get install linux-image-extra-$(uname -r) -y
sudo apt-get install docker-engine cgroup-lite apparmor -y
sudo service docker start
;;
debian)
sudo apt-get install apt-transport-https ca-certificates -y
sudo sh -c "echo deb https://apt.dockerproject.org/repo debian-jessie main > /etc/apt/sources.list.d/docker.list"
sudo apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D
sudo apt-get update
sudo apt-cache policy docker-engine
sudo apt-get install docker-engine curl python-pip -y
sudo service docker start
;;
sudo apt-get install apt-transport-https ca-certificates -y
sudo sh -c "echo deb https://apt.dockerproject.org/repo debian-jessie main > /etc/apt/sources.list.d/docker.list"
sudo apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D
sudo apt-get update
sudo apt-cache policy docker-engine
sudo apt-get install docker-engine curl python-pip -y
sudo service docker start
;;
centos)
sudo yum install -y epel-release yum-utils
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
sudo yum makecache fast
sudo yum update && sudo yum install -y docker-ce python-pip
sudo systemctl enable docker
sudo systemctl start docker
;;
sudo yum install -y epel-release yum-utils
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
sudo yum makecache fast
sudo yum update && sudo yum install -y docker-ce python-pip
sudo systemctl enable docker
sudo systemctl start docker
;;
fedora)
sudo dnf -y update
sudo dnf -y install docker python-pip --allowerasing
sudo systemctl enable docker
sudo systemctl start docker
;;
sudo dnf -y update
sudo dnf -y install docker python-pip --allowerasing
sudo systemctl enable docker
sudo systemctl start docker
;;
opensuse)
sudo zypper refresh
sudo zypper install docker docker-compose python-pip
sudo systemctl restart docker
;;
sudo zypper refresh
sudo zypper install docker docker-compose python-pip
sudo systemctl restart docker
;;
*)
echo "Linux distribution not identified !!! skipping docker & pip installation"
;;
echo "Linux distribution not identified !!! skipping docker & pip installation"
;;
esac

echo_b "Add existing user to docker group"
Expand Down
30 changes: 18 additions & 12 deletions scripts/master_node/start_mongoexpress.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,19 @@
# Detecting whether can import the header file to render colorful cli output
# Need add choice option
if [ -f ../header.sh ]; then
source ../header.sh
source ../header.sh
elif [ -f scripts/header.sh ]; then
source scripts/header.sh
source scripts/header.sh
else
alias echo_r="echo"
alias echo_g="echo"
alias echo_b="echo"
echo_r() {
echo "$@"
}
echo_g() {
echo "$@"
}
echo_b() {
echo "$@"
}
fi

NET=${PROJECT}_default
Expand All @@ -27,10 +33,10 @@ BIND_ADDR=0.0.0.0
echo "Access port 8081 for the mongo-express UI"

docker run -d \
--name mongo-express \
--link mongo:mongo \
--net ${NET} \
-p ${BIND_ADDR}:8081:8081 \
-e ME_CONFIG_BASICAUTH_USERNAME=admin \
-e ME_CONFIG_BASICAUTH_PASSWORD=pass \
mongo-express:0.30
--name mongo-express \
--link mongo:mongo \
--net ${NET} \
-p ${BIND_ADDR}:8081:8081 \
-e ME_CONFIG_BASICAUTH_USERNAME=admin \
-e ME_CONFIG_BASICAUTH_PASSWORD=pass \
mongo-express:0.30
12 changes: 6 additions & 6 deletions scripts/master_node/start_netdata.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
#

docker run -d \
--net=host \
--cap-add SYS_PTRACE \
-v /proc:/host/proc:ro \
-v /sys:/host/sys:ro \
-v /var/run/docker.sock:/var/run/docker.sock \
-p 19999:19999 titpetric/netdata
--net=host \
--cap-add SYS_PTRACE \
-v /proc:/host/proc:ro \
-v /sys:/host/sys:ro \
-v /var/run/docker.sock:/var/run/docker.sock \
-p 19999:19999 titpetric/netdata
17 changes: 11 additions & 6 deletions scripts/master_node/watch_mode.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,21 @@
# Detecting whether can import the header file to render colorful cli output
# Need add choice option
if [ -f ../header.sh ]; then
source ../header.sh
source ../header.sh
elif [ -f scripts/header.sh ]; then
source scripts/header.sh
source scripts/header.sh
else
alias echo_r="echo"
alias echo_g="echo"
alias echo_b="echo"
echo_r() {
echo "$@"
}
echo_g() {
echo "$@"
}
echo_b() {
echo "$@"
}
fi


echo_b "Run watch mode for react js files..."
docker-compose -f docker-compose-watch-mode.yml up --no-recreate

Expand Down
Loading

0 comments on commit 79945bf

Please sign in to comment.