github.com/kchristidis/fabric@v1.0.4-0.20171028114726-837acd08cde1/devenv/setup.sh (about)

     1  #!/bin/bash
     2  #
     3  # Copyright IBM Corp. All Rights Reserved.
     4  #
     5  # SPDX-License-Identifier: Apache-2.0
     6  #
     7  
     8  
     9  set -e
    10  set -x
    11  
    12  DEVENV_REVISION=`(cd /hyperledger/devenv; git rev-parse --short HEAD)`
    13  
    14  # Install WARNING before we start provisioning so that it
    15  # will remain active.  We will remove the warning after
    16  # success
    17  SCRIPT_DIR="$(readlink -f "$(dirname "$0")")"
    18  cat "$SCRIPT_DIR/failure-motd.in" >> /etc/motd
    19  
    20  # Update the entire system to the latest releases
    21  apt-get update
    22  #apt-get dist-upgrade -y
    23  
    24  # Install some basic utilities
    25  apt-get install -y build-essential git make curl unzip g++ libtool
    26  
    27  # ----------------------------------------------------------------
    28  # Install Docker
    29  # ----------------------------------------------------------------
    30  
    31  # Storage backend logic
    32  case "${DOCKER_STORAGE_BACKEND}" in
    33    aufs|AUFS|"")
    34      DOCKER_STORAGE_BACKEND_STRING="aufs" ;;
    35    btrfs|BTRFS)
    36      # mkfs
    37      apt-get install -y btrfs-tools
    38      mkfs.btrfs -f /dev/sdb
    39      rm -Rf /var/lib/docker
    40      mkdir -p /var/lib/docker
    41      . <(sudo blkid -o udev /dev/sdb)
    42      echo "UUID=${ID_FS_UUID} /var/lib/docker btrfs defaults 0 0" >> /etc/fstab
    43      mount /var/lib/docker
    44  
    45      DOCKER_STORAGE_BACKEND_STRING="btrfs" ;;
    46    *) echo "Unknown storage backend ${DOCKER_STORAGE_BACKEND}"
    47       exit 1;;
    48  esac
    49  
    50  # Update system
    51  apt-get update -qq
    52  
    53  # Prep apt-get for docker install
    54  apt-get install -y apt-transport-https ca-certificates
    55  apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D
    56  
    57  # Add docker repository
    58  echo deb https://apt.dockerproject.org/repo ubuntu-xenial main > /etc/apt/sources.list.d/docker.list
    59  
    60  # Update system
    61  apt-get update -qq
    62  
    63  # Install docker
    64  apt-get install -y linux-image-extra-$(uname -r) apparmor docker-engine
    65  
    66  # Install docker-compose
    67  curl -L https://github.com/docker/compose/releases/download/1.8.1/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
    68  chmod +x /usr/local/bin/docker-compose
    69  
    70  # Configure docker
    71  DOCKER_OPTS="-s=${DOCKER_STORAGE_BACKEND_STRING} -r=true --api-cors-header='*' -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock ${DOCKER_OPTS}"
    72  sed -i.bak '/^DOCKER_OPTS=/{h;s|=.*|=\"'"${DOCKER_OPTS}"'\"|};${x;/^$/{s||DOCKER_OPTS=\"'"${DOCKER_OPTS}"'\"|;H};x}' /etc/default/docker
    73  
    74  service docker restart
    75  usermod -a -G docker ubuntu # Add ubuntu user to the docker group
    76  
    77  # Test docker
    78  docker run --rm busybox echo All good
    79  
    80  # ----------------------------------------------------------------
    81  # Install Golang
    82  # ----------------------------------------------------------------
    83  GO_VER=1.7.5
    84  GO_URL=https://storage.googleapis.com/golang/go${GO_VER}.linux-amd64.tar.gz
    85  
    86  # Set Go environment variables needed by other scripts
    87  export GOPATH="/opt/gopath"
    88  export GOROOT="/opt/go"
    89  PATH=$GOROOT/bin:$GOPATH/bin:$PATH
    90  
    91  cat <<EOF >/etc/profile.d/goroot.sh
    92  export GOROOT=$GOROOT
    93  export GOPATH=$GOPATH
    94  export PATH=\$PATH:$GOROOT/bin:$GOPATH/bin
    95  EOF
    96  
    97  mkdir -p $GOROOT
    98  
    99  curl -sL $GO_URL | (cd $GOROOT && tar --strip-components 1 -xz)
   100  
   101  # ----------------------------------------------------------------
   102  # Install NodeJS
   103  # ----------------------------------------------------------------
   104  NODE_VER=6.9.5
   105  NODE_URL=https://nodejs.org/dist/v$NODE_VER/node-v$NODE_VER-linux-x64.tar.gz
   106  
   107  curl -sL $NODE_URL | (cd /usr/local && tar --strip-components 1 -xz )
   108  
   109  # ----------------------------------------------------------------
   110  # Install Behave
   111  # ----------------------------------------------------------------
   112  /hyperledger/scripts/install_behave.sh
   113  
   114  # ----------------------------------------------------------------
   115  # Install Java
   116  # ----------------------------------------------------------------
   117  apt-get install -y openjdk-8-jdk maven
   118  
   119  wget https://services.gradle.org/distributions/gradle-2.12-bin.zip -P /tmp --quiet
   120  unzip -q /tmp/gradle-2.12-bin.zip -d /opt && rm /tmp/gradle-2.12-bin.zip
   121  ln -s /opt/gradle-2.12/bin/gradle /usr/bin
   122  
   123  # ----------------------------------------------------------------
   124  # Misc tasks
   125  # ----------------------------------------------------------------
   126  
   127  # Create directory for the DB
   128  sudo mkdir -p /var/hyperledger
   129  sudo chown -R ubuntu:ubuntu /var/hyperledger
   130  
   131  # clean any previous builds as they may have image/.dummy files without
   132  # the backing docker images (since we are, by definition, rebuilding the
   133  # filesystem) and then ensure we have a fresh set of our go-tools.
   134  # NOTE: This must be done before the chown below
   135  cd $GOPATH/src/github.com/hyperledger/fabric
   136  make clean gotools
   137  
   138  # Ensure permissions are set for GOPATH
   139  sudo chown -R ubuntu:ubuntu $GOPATH
   140  
   141  # Update limits.conf to increase nofiles for LevelDB and network connections
   142  sudo cp /hyperledger/devenv/limits.conf /etc/security/limits.conf
   143  
   144  # Configure vagrant specific environment
   145  cat <<EOF >/etc/profile.d/vagrant-devenv.sh
   146  # Expose the devenv/tools in the $PATH
   147  export PATH=\$PATH:/hyperledger/devenv/tools:/hyperledger/build/bin
   148  export VAGRANT=1
   149  export CGO_CFLAGS=" "
   150  EOF
   151  
   152  # Set our shell prompt to something less ugly than the default from packer
   153  # Also make it so that it cd's the user to the fabric dir upon logging in
   154  cat <<EOF >> /home/ubuntu/.bashrc
   155  PS1="\u@hyperledger-devenv:$DEVENV_REVISION:\w$ "
   156  cd $GOPATH/src/github.com/hyperledger/fabric/
   157  EOF
   158  
   159  # finally, remove our warning so the user knows this was successful
   160  rm /etc/motd