github.com/leonlxy/hyperledger@v1.0.0-alpha.0.20170427033203-34922035d248/devenv/setup.sh (about)

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