github.com/rita33cool1/iot-system-gateway@v0.0.0-20200911033302-e65bde238cc5/docker-engine/contrib/docker-machine-install-bundle.sh (about)

     1  #!/usr/bin/env bash
     2  #
     3  # This script installs the bundle to Docker Machine instances, for the purpose
     4  # of testing the latest Docker with Swarm mode enabled.
     5  # Do not use in production.
     6  #
     7  # Requirements (on host to run this script)
     8  #  - bash is installed
     9  #  - Docker Machine is installed
    10  #  - GNU tar is installed
    11  #
    12  # Requirements (on Docker machine instances)
    13  #  - Docker can be managed via one of  `systemctl`, `service`, or `/etc/init.d/docker`
    14  #
    15  set -e
    16  set -o pipefail
    17  
    18  errexit() {
    19      echo "$1"
    20      exit 1
    21  }
    22  
    23  BUNDLE="bundles/$(cat VERSION)"
    24  
    25  bundle_files(){
    26      # prefer dynbinary if exists
    27      for f in dockerd docker-proxy; do
    28  	if [ -d $BUNDLE/dynbinary-daemon ]; then
    29  	    echo $BUNDLE/dynbinary-daemon/$f
    30  	else
    31  	    echo $BUNDLE/binary-daemon/$f
    32  	fi
    33      done
    34      for f in docker-containerd docker-containerd-ctr docker-containerd-shim docker-init docker-runc; do
    35  	echo $BUNDLE/binary-daemon/$f
    36      done
    37      if [ -d $BUNDLE/dynbinary-client ]; then
    38  	echo $BUNDLE/dynbinary-client/docker
    39      else
    40  	echo $BUNDLE/binary-client/docker
    41      fi
    42  }
    43  
    44  control_docker(){
    45      m=$1; op=$2
    46      # NOTE: `docker-machine ssh $m sh -c "foo bar"` does not work
    47      #       (but `docker-machine ssh $m sh -c "foo\ bar"` works)
    48      #       Anyway we avoid using `sh -c` here for avoiding confusion
    49      cat <<EOF | docker-machine ssh $m sudo sh
    50  if command -v systemctl > /dev/null; then
    51    systemctl $op docker
    52  elif command -v service > /dev/null; then
    53    service docker $op
    54  elif [ -x /etc/init.d/docker ]; then
    55    /etc/init.d/docker $op
    56  else
    57    echo "not sure how to control the docker daemon"
    58    exit 1
    59  fi
    60  EOF
    61  }
    62  
    63  detect_prefix(){
    64      m=$1
    65      script='dirname $(dirname $(which dockerd))'
    66      echo $script | docker-machine ssh $m sh
    67  }
    68  
    69  install_to(){
    70      m=$1; shift; files=$@
    71      echo "$m: detecting docker"
    72      prefix=$(detect_prefix $m)
    73      echo "$m: detected docker on $prefix"
    74      echo "$m: stopping docker"
    75      control_docker $m stop
    76      echo "$m: installing docker"
    77      # NOTE: GNU tar is required because we use --transform here
    78      # TODO: compression (should not be default)
    79      tar ch --transform 's/.*\///' $files | docker-machine ssh $m sudo tar Cx $prefix/bin
    80      echo "$m: starting docker"
    81      control_docker $m start
    82      echo "$m: done"
    83  }
    84  
    85  check_prereq(){
    86      command -v docker-machine > /dev/null || errexit "docker-machine not installed"
    87      ( tar --version | grep GNU > /dev/null ) || errexit "GNU tar not installed"
    88  }
    89  
    90  case "$1" in
    91      "install")
    92  	shift; machines=$@
    93  	check_prereq
    94  	files=$(bundle_files)
    95  	echo "Files to be installed:"
    96  	for f in $files; do echo $f; done
    97  	pids=()
    98  	for m in $machines; do
    99  	    install_to $m $files &
   100  	    pids+=($!)
   101  	done
   102  	status=0
   103  	for pid in ${pids[@]}; do
   104  	    wait $pid || { status=$?; echo "background process $pid failed with exit status $status"; }
   105  	done
   106  	exit $status
   107  	;;
   108      *)
   109  	errexit "Usage: $0 install MACHINES"
   110  	;;
   111  esac