diff options
Diffstat (limited to 'clientgerrit/dgerrit.sh')
-rwxr-xr-x | clientgerrit/dgerrit.sh | 408 |
1 files changed, 408 insertions, 0 deletions
diff --git a/clientgerrit/dgerrit.sh b/clientgerrit/dgerrit.sh new file mode 100755 index 0000000..e18347a --- /dev/null +++ b/clientgerrit/dgerrit.sh @@ -0,0 +1,408 @@ +#! /bin/sh +#=============================================================================== +# Tizen gerrit+drupal+openldap +# 01/17 2015 +# +# Copyright (c) 2014-2015 Samsung Electronics Co., Ltd. +# Author onstudy@samsung.com +# +# This program is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the +# Free Software Foundation; version 2 of the License +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the GNU General Public License for more details. +#=============================================================================== + +home="$( cd "$( dirname "$0" )" && pwd )" +. $home/config.conf + +set -e +#------------------------------------------------------------------------------- +images=$IMAGES:$TAG +container=$CONTAINER + +echo "IMAGES:"$images +echo "CONTAINER:"$container + +if [ ! -z "$PORTS" ] +then + for I in $PORTS; do + service_port=$I + if [ ! -z $(echo "$service_port" | grep ':') ] + then + if [ -z "$ports_cmd" ] + then + ports_cmd=$(echo "-p ${service_port} ") + else + ports_cmd=$(echo $ports_cmd"-p ${service_port} ") + fi + elif [ ! -z $(echo "$service_port" | grep '-') ] + then + d1=$(echo $service_port | cut -d '-' -f1) + d2=$(echo $service_port | cut -d '-' -f2) + instance=$((d2 - d1 + 1)) + #echo "instance:"$instance + count=0 + while [ $count -lt $instance ]; do + expose_port=$((d1 + count)) + if [ -z "$ports_cmd" ] + then + ports_cmd=$(echo "-p ${expose_port}:${expose_port} ") + else + ports_cmd=$(echo $ports_cmd"-p ${expose_port}:${expose_port} ") + fi + count=`expr $count + 1` + done + else + if [ -z "$ports_cmd" ] + then + ports_cmd=$(echo "-p ${service_port}:${service_port} ") + else + ports_cmd=$(echo $ports_cmd"-p ${service_port}:${service_port} ") + fi + fi + done +fi +echo "PORT:"$ports_cmd + +if [ ! -z "$ENVLIST" ] +then + envlist_cmd=$(echo "--env-file $ENVLIST") +fi +echo "ENV LIST:"$envlist_cmd + +if [ ! -z "$VOLUMES" ] +then + for vol in $VOLUMES; do + if [ -z "$volumes_cmd" ] + then + volumes_cmd=$(echo "-v /etc/localtime:/etc/localtime:ro -v $vol ") + else + volumes_cmd=$(echo $volumes_cmd "-v $vol ") + fi + done +fi +echo "VOLUMES:"$volumes_cmd +if [ ! -z "$HOSTNAME" ] +then + hostname_cmd=$(echo "-h $HOSTNAME") +fi +echo "HOST NAME:"$hostname_cmd + +if [ "$PRIVILEGED" = 'yes' ] +then + privileged_cmd=$(echo "--privileged") +fi +echo "PRIVILEGED:"$privileged_cmd + +if [ "$AUTOSTART" = 'always' ] +then + autostart_cmd=$(echo "--restart=always") +elif [ "$AUTOSTART" = 'on-failure^' ] +then + autostart_cmd=$(echo "--restart=on-failure:10") +fi +echo "AUTOSTART:"$autostart_cmd + +if [ ! -z "$LINK_IMAGES" ] +then + for link in $LINK_IMAGES; do + if [ -z "$links_cmd" ] + then + links_cmd=$(echo "--link $link ") + else + links_cmd=$(echo $links_cmd "--link $link ") + fi + done +fi +echo "LINKS:"$links_cmd + +if [ ! -z "$VOLUMES_IMAGES" ] +then + for volumes_images in $VOLUMES_IMAGES; do + if [ -z "$volumes_images_cmd" ] + then + volumes_images_cmd=$(echo "--volumes-from $volumes_images ") + else + volumes_images_cmd=$(echo $volumes_images_cmd "--volumes-from $volumes_images ") + fi + done +fi +echo "VOLUMES-FROM:"$volumes_images_cmd + +if [ ! -z "$ADD_HOSTS" ] +then + for hostserver in $ADD_HOSTS; do + if [ -z "$add_hosts_cmd" ] + then + add_hosts_cmd=$(echo "--add-host=$hostserver ") + else + add_hosts_cmd=$(echo $add_hosts_cmd "--add-host=$hostserver ") + fi + done +fi +echo "ADD_HOST:"$add_hosts_cmd + +if [ ! -z "$CAP_ADD" ] +then + for capadd in $CAP_ADD; do + if [ -z "$capadds_cmd" ] + then + capadds_cmd=$(echo "--cap-add=$capadd ") + else + capadds_cmd=$(echo $capadds_cmd "--cap-add=$capadd ") + fi + done +fi +echo "CAP_ADD:"$capadds_cmd + +#------------------------------------------------------------------------------- +install_docker(){ + echo "Install lxc-docker-1.4.1" + + if [ $(lsb_release -a | sed -n '/Description/p' | grep -c "Ubuntu 14.04") -eq 1 ]; + then + echo "Ubuntu 14.04" + if [ $(dpkg-query -W -f='${Status}' lxc-docker-1.4.1 2>/dev/null | grep -c "ok installed") -eq 0 ]; + then + echo "sudo get -qO- https://get.docker.io/gpg" | sh || true + echo "sudo apt-key add -" | sh || true + echo "sudo sh -c "'"echo deb http://get.docker.io/ubuntu docker main > /etc/apt/sources.list.d/docker.list"' | sh || true + echo "sudo apt-get update" | sh || true + echo "sudo apt-get install -y lxc-docker-1.4.1" | sh || true + else + echo $(docker --version) + fi + elif [ $(lsb_release -a | sed -n '/Description/p' | grep -c "Ubuntu 12.04") -eq 1 ]; + then + echo "Ubuntu 12.04" + if [ $(dpkg-query -W -f='${Status}' lxc-docker-1.4.1 2>/dev/null | grep -c "ok installed") -eq 0 ]; + then + echo "sudo apt-get update" | sh || true + echo "sudo apt-get install -y linux-image-generic-lts-raring linux-headers-generic-lts-raring" | sh || true + echo "sudo apt-get install --install-recommends linux-generic-lts-raring xserver-xorg-lts-raring libgl1-mesa-glx-lts-raring" | sh || true + echo "sudo apt-get update" | sh || true + echo "sudo apt-get install -y apt-transport-https" | sh || true + + echo "sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 36A1D7869245C8950F966E92D8576A8BA88D21E9" | sh || true + echo "sudo sh -c "'"echo deb https://get.docker.com/ubuntu docker main\ > /etc/apt/sources.list.d/docker.list"' | sh || true + echo "sudo apt-get update" | sh || true + echo "sudo apt-get install -y lxc-docker-1.4.1" | sh || true + else + echo $(docker --version) + fi + else + echo "It does not install lxc-docker-1.4.1" + fi + +} +#------------------------------------------------------------------------------- +attach(){ + echo "Attaching docker containers:" + docker exec -it $container script /dev/null -c /bin/bash || true +} +#------------------------------------------------------------------------------- +status(){ + echo "Status docker containers:" + docker ps | grep "$container" || true +} +#------------------------------------------------------------------------------- +stop(){ + echo "Stopping docker containers:" + docker stop $container || true + docker ps | grep "$container" || true +} +#------------------------------------------------------------------------------- +start(){ + echo "Starting ${container}:" + echo " docker run -d --name $container \ + $hostname_cmd \ + $privileged_cmd \ + $links_cmd \ + $ports_cmd \ + $envlist_cmd \ + $volumes_cmd \ + $volumes_images_cmd \ + $add_hosts_cmd \ + $capadds_cmd \ + $images + " + if [ ! -z "$links_cmd" ] + then + for link in $LINK_IMAGES; do + link_sh=$(echo "$link" | cut -d ':' -f1) + if [ -z "$(docker ps | grep "$link_sh" | awk '{print $NF}')" ] + then + echo "Please you must be run the" "$link_sh"" before the" "$container" + exit + fi + done + fi + for run_container in $(docker ps -a | grep "$container" | awk '{print $NF}'); do + if [ "$run_container" = "$container" ]; + then + docker start $container + docker ps | grep "$container" || true + exit + fi + done + docker run -d --name $container \ + $hostname_cmd \ + $privileged_cmd \ + $links_cmd \ + $ports_cmd \ + $envlist_cmd \ + $volumes_cmd \ + $volumes_images_cmd \ + $add_hosts_cmd \ + $capadds_cmd \ + $images + + docker ps | grep "$container" || true +} + +#------------------------------------------------------------------------------- +kill(){ + echo "Killing docker containers:" + docker kill $container || true +} +#------------------------------------------------------------------------------- +rm(){ + echo "Removing stopped containers:" + docker rm $container || true +} +#------------------------------------------------------------------------------- +logs(){ + echo "Show logs of a container" + docker logs $container || true +} +#------------------------------------------------------------------------------- +cp(){ + echo "Copy files/folders from a container's filesystem" + echo "docker cp $container:$1 $2 || true" + docker cp $container:$1 $2 || true +} +#------------------------------------------------------------------------------- +pull(){ + echo "Pull an image or a repository from a Docker registry server" + docker pull $images || true +} +#------------------------------------------------------------------------------- +inspect(){ + echo "Return low-level information on a containe" + docker inspect $container || true +} +#------------------------------------------------------------------------------- +top(){ + echo "Lookup the running processes of a container" + docker top $container || true +} +#------------------------------------------------------------------------------- +save(){ + echo "Save an image to a tar archive" + docker save -o $container"-"$TAG"-docker-image.tar.gz" $images || true + echo $(pwd | awk -F '/' '{print $NF}') + tar cvfzp ../$container"-"$TAG"-docker-script.tar.gz" ../$(pwd | awk -F '/' '{print $NF}') + echo "Save $container-$TAG" +} +#------------------------------------------------------------------------------- +load(){ + echo "Load an image from a tar archive" + docker load -i $container"-"$TAG"-docker-image.tar.gz" || true + echo "Load $container-$TAG" +} +#------------------------------------------------------------------------------- +help(){ + echo "help" + usage +} +#------------------------------------------------------------------------------- +usage (){ + echo "USAGE: $0" COMMAND + + echo -e "\nCommands:" + echo " install Install lxc-docker-1.4.1" + echo " start Start a stopped container" + echo " attach Attach to a running container" + echo " stop Stop a running container" + echo " status Status a running container" + echo " rm Remove this containers" + echo " restart stop, start a container" + echo " kill Kill a running container" + echo " logs Fetch the logs of a container" + echo " cp Copy files/folders from a container's filesystem to the host path" + echo " pull Pull an image or a repository from a Docker registry server" + echo " inspect Return low-level information on a containe" + echo " top Lookup the running processes of a container" + echo " save Save an image to a tar archive" + echo " load Load an image from a tar archive" + echo " help help" + exit 1 +} +#------------------------------------------------------------------------------- +if [ $# -eq 0 ] +then + usage +fi + +#------------------------------------------------------------------------------- +case "$1" in + install) + install_docker + ;; + start) + start + ;; + attach) + attach + ;; + status) + status + ;; + stop) + stop + ;; + restart) + stop + start + ;; + kill) + kill + rm + ;; + rm) + rm + ;; + logs) + logs + ;; + cp) + cp $2 $3 + ;; + pull) + pull + ;; + inspect) + inspect + ;; + top) + top + ;; + save) + save + ;; + load) + load + ;; + help) + help + ;; + *) + usage + ;; +esac +#=============================================================================== + |