summaryrefslogtreecommitdiffstats
path: root/vagrant/bootstrap.ubuntu1404.sh
blob: 28dda9884f4ddd1dd23a68cf064cf0ade1800ef2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
# Args
VAGRANT_VM_NAME="$1"
VAGRANT_VBD_VM="$2"
VAGRANT_VPP_AGENT_ADDR="$3"
echo "---"
echo "  Running bootstrap.ubuntu1404.sh..."
echo "---"
echo "---"
echo "  VAGRANT_VM_NAME = '$VAGRANT_VM_NAME'"
echo "  VAGRANT_VBD_VM = '$VAGRANT_VBD_VM'"
echo "  VAGRANT_VPP_AGENT_ADDR = '$VAGRANT_VPP_AGENT_ADDR'"
echo "---"

# Directory and file definitions
HONEYCOMB_MOUNT="/honeycomb"
KARAF_PACKAGES_MOUNT="/karaf-packages"
M2_SETTINGS_XML="$HONEYCOMB_MOUNT/vagrant/settings.xml"
M2_MOUNT="/m2-repository"
VPP_MOUNT="/vpp"
VPP_BUILD_ROOT="$VPP_MOUNT/build-root"
VAGRANT_HOME="/home/vagrant"
VAGRANT_BASHRC="$VAGRANT_HOME/.bashrc"
VAGRANT_BASH_ALIASES="$VAGRANT_HOME/.bash_aliases"
VAGRANT_M2_DIR="$VAGRANT_HOME/.m2"
VAGRANT_M2_REPOSITORY="$VAGRANT_M2_DIR/repository"
HONEYCOMB_INSTALL_DIR="/opt/honeycomb"
FDIO_SNAPSHOT_URL="https://nexus.fd.io/content/repositories/fd.io.snapshot"
FDIO_DEV_URL="http://nexus.fd.io/content/repositories/fd.io.dev/"
APACHE_MAVEN_VER="apache-maven-3.3.9"
APACHE_MAVEN_TAR_GZ="$APACHE_MAVEN_VER-bin.tar.gz"
APACHE_MAVEN_URL="http://apache.go-parts.com/maven/maven-3/3.3.9/binaries/$APACHE_MAVEN_TAR_GZ"
APACHE_MAVEN_INSTALL_DIR="/usr/local/apache-maven"
GOOGLE_CHROME_DEB_PKG="google-chrome-stable_current_amd64.deb"
GOOGLE_CHROME_URL="https://dl.google.com/linux/direct/$GOOGLE_CHROME_DEB_PKG"

# Don't install VPP if this is an ODL VBD application VM
if [ "$VAGRANT_VBD_VM" != "is_vbd_vm" ] ; then
  echo "---"
  echo "  Configuring hugepages for VPP"
  echo "---"
  # Setup for hugepages using upstart so it persists across reboots
  echo "vm.nr_hugepages=1024" >> /etc/sysctl.d/20-hugepages.conf
  sysctl --system
  cat << EOF > /etc/init/hugepages.conf
start on runlevel [2345]

task

script
    mkdir -p /run/hugepages/kvm || true
    rm -f /run/hugepages/kvm/* || true
    rm -f /dev/shm/* || true
    mount -t hugetlbfs nodev /run/hugepages/kvm
end script
EOF
  # Allocate hugepages.conf right now.  Verify that
  # all hugepages have been allocated.  If the VM
  # runs out of resources, the messages below will
  # identify the issue.  Front and Center!
  nr_hugepages=$(cat /proc/sys/vm/nr_hugepages)
  while [ "$nr_hugepages" != "1024" ] ; do
    echo "---"
    echo -n "  Allocating hugepages... "
    start hugepages
    nr_hugepages=$(cat /proc/sys/vm/nr_hugepages)
    echo "  nr_hugepages = $nr_hugepages"
    echo "---"
  done
fi

# Set prompt to include VM name if provided.
sudo -H -u vagrant perl -i -pe 's/@\\h/@\\\h\$VM_NAME/g' $VAGRANT_BASHRC
sudo -H -u vagrant touch $VAGRANT_BASH_ALIASES
if [ "$VAGRANT_VM_NAME" != "" ] && [ "$(grep VM_NAME $VAGRANT_BASH_ALIASES)" = "" ] ; then 
    echo -e "\n# Include VM Name in prompt\nexport VM_NAME=\"($VAGRANT_VM_NAME)\"" >> $VAGRANT_BASH_ALIASES
fi

# Fix grub-pc on Virtualbox with Ubuntu
export DEBIAN_FRONTEND=noninteractive

# Add fd.io apt repo in case its needed
echo "deb $FDIO_DEV_URL ./" > /etc/apt/sources.list.d/99fd.io.list

# Standard update + upgrade dance
echo "---"
echo "  Update and install ubuntu packages for development environment"
echo "---"
apt-get update
apt-get upgrade -y

# Install build tools
apt-get install -y build-essential autoconf automake bison libssl-dev ccache libtool git dkms debhelper emacs libganglia1-dev libapr1-dev libconfuse-dev git-review

# Install uio
apt-get install -y linux-image-extra-`uname -r`

# Install jdk and maven
echo "---"
echo "  Installing openjdk"
echo "---"
apt-get install -y openjdk-8-jdk
mkdir -p $APACHE_MAVEN_INSTALL_DIR
if [ -d "$KARAF_PACKAGES_MOUNT" ] ; then
  APACHE_MAVEN_TARBALL="$KARAF_PACKAGES_MOUNT/$APACHE_MAVEN_TAR_GZ"
  if [ ! -f "$APACHE_MAVEN_TARBALL" ] ; then
    echo "---"
    echo "  Downloading $APACHE_MAVEN_TAR_GZ and caching it in $KARAF_PACKAGES_MOUNT"
    echo "---"
    cd $KARAF_PACKAGES_MOUNT
    wget -q $APACHE_MAVEN_URL
    cd 
  fi
else
  echo "---"
  echo "  Downloading $APACHE_MAVEN_TAR_GZ in $APACHE_MAVEN_INSTALL_DIR"
  echo "---"
  cd $APACHE_MAVEN_INSTALL_DIR
  wget -q $APACHE_MAVEN_URL
  APACHE_MAVEN_TARBALL="$APACHE_MAVEN_INSTALL_DIR/$APACHE_MAVEN_TAR_GZ"
  cd
fi
echo "---"
echo "  Installing $APACHE_MAVEN_TARBALL in $APACHE_MAVEN_INSTALL_DIR"
echo "---"
tar -xzf $APACHE_MAVEN_TARBALL -C $APACHE_MAVEN_INSTALL_DIR
update-alternatives --install /usr/bin/mvn mvn $APACHE_MAVEN_INSTALL_DIR/$APACHE_MAVEN_VER/bin/mvn 1
update-alternatives --config mvn

# Set up Maven
sudo -H -u vagrant mkdir -p $VAGRANT_M2_DIR
sudo -H -u vagrant cp $M2_SETTINGS_XML $VAGRANT_M2_DIR
if [ "$(grep M2_HOME $VAGRANT_BASH_ALIASES)" = "" ] ; then
    cat << EOF >> $VAGRANT_BASH_ALIASES

# Maven Environment variables
export M2_HOME=/usr/local/apache-maven/apache-maven-3.3.9
export MAVEN_OPTS="-Xms256m -Xmx512m" # Very important to put the "m" on the end
export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
EOF
    chown vagrant:vagrant $VAGRANT_BASH_ALIASES
fi
source $VAGRANT_BASH_ALIASES
# Use the external Maven M2 repository as a seed if available.
if [ -d "/m2-repository" ] ; then
  sudo -H -u vagrant sed -i -e 's,/home/vagrant/.m2/repository,/m2-repository,g' /home/vagrant/.m2/settings.xml
  VAGRANT_M2_REPOSITORY="/m2-repository"
fi

# Don't install VPP and ODL Honeycomb Agent if this is an ODL VBD application VM
if [ "$VAGRANT_VBD_VM" != "is_vbd_vm" ] ; then
  # Look for karaf packages
  if [ -d "$KARAF_PACKAGES_MOUNT" ] ; then
    V3PO_TARBALL="$(find $KARAF_PACKAGES_MOUNT -name v3po-karaf*.tar.gz | sort | tail -1)"
    if [ ! -f "$V3PO_TARBALL" ] ; then
      echo "---"
      echo "  Fetching latest V3PO tarball from $FDIO_SNAPSHOT_URL"
      echo "---"
      sudo -H -u vagrant mvn dependency:get -DremoteRepositories=$FDIO_SNAPSHOT_URL -DgroupId=io.fd.honeycomb.v3po -DartifactId=v3po-karaf -Dversion=1.0.0-SNAPSHOT -Dpackaging=tar.gz -Dtransitive=false
      M2_TB_DIR="$VAGRANT_M2_REPOSITORY/io/fd/honeycomb/v3po/v3po-karaf/1.0.0-SNAPSHOT"
      V3PO_TARBALL="$(find $M2_TB_DIR -name v3po-karaf*.tar.gz | grep -v v3po-karaf-1.0.0-SNAPSHOT | sort | tail -1)"
      echo "---"
      echo "  Copying V3PO tarball ($(basename $V3PO_TARBALL)) to $KARAF_PACKAGES_MOUNT"
      echo "---"
      [ -f "$V3PO_TARBALL" ] && cp -p $V3PO_TARBALL $KARAF_PACKAGES_MOUNT
      V3PO_TARBALL="$(find $KARAF_PACKAGES_MOUNT -name v3po-karaf*.tar.gz | sort | tail -1)"
    fi
  else
    V3PO_TARBALL="$HONEYCOMB_MOUNT/v3po/karaf/target/v3po-karaf*.tar.gz"
  fi

  # Disable all ethernet interfaces other than the default route
  # interface so VPP will use those interfaces.  The VPP auto-blacklist
  # algorithm prevents the use of any physical interface contained in the
  # routing table (i.e. "route --inet --inet6") preventing the theft of
  # the management ethernet interface by VPP from the kernel.
  for intf in $(ls /sys/class/net) ; do
    if [ "$VAGRANT_VPP_AGENT_ADDR" != "" ] && [ "$(ifconfig $intf | grep $VAGRANT_VPP_AGENT_ADDR)" != "" ] ; then
      continue;
    fi
    if [ -d "/sys/class/net/$intf/device" ] && [ "$(route --inet --inet6 | grep default | grep $intf)" == "" ] ; then
        ifconfig $intf down
    fi
  done

  # Install VPP
  if [ -d "$VPP_MOUNT" ] ; then
    # Fix the silly notion that /bin/sh should point to dash by pointing it to bash
    sudo update-alternatives --install /bin/sh sh /bin/bash 100

    # Build and install VPP if necessary
    if [ -d "$VPP_BUILD_ROOT" ] ; then
      if [ "$(ls $VPP_BUILD_ROOT/*.deb)" = "" ] ; then
        echo "---"
        echo "  Building VPP"
        echo "---"
        # Bootstrap vpp
        cd $VPP_BUILD_ROOT
        sudo -H -u vagrant ./bootstrap.sh
        # Build vpp
        sudo -H -u vagrant make V=0 PLATFORM=vpp TAG=vpp_debug install-deb
      fi
      # Install debian packages
      echo "---"
      echo "  Installing VPP from $VPP_BUILD_ROOT"
      echo "---"
      dpkg -i $VPP_BUILD_ROOT/*.deb
    fi
  else
    echo "---"
    echo "  Installing VPP from nexus.fd.io"
    echo "---"
    apt-get install vpp vpp-dpdk-dev vpp-dpdk-dkms vpp-dev vpp-dbg -y --force-yes
  fi
  # Start VPP if it is installed.
  if [ "$(dpkg -l | grep vpp)" != "" ] ; then
    echo "---"
    echo "  Starting VPP"
    echo "---"
    start vpp
  fi

  # Build Honeycomb if necessary
  if [ ! -f "$V3PO_TARBALL" ] ; then
    echo "---"
    echo "  Building Honeycomb..."
    echo "---"
    cd $HONEYCOMB_MOUNT
    sudo -H -u vagrant mvn clean install -DskipTests
    V3PO_TARBALL="$(find $HONEYCOMB_MOUNT/v3po/karaf/target/ -name v3po-karaf*.tar.gz | sort | tail -1)"
  fi

  # Install honeycomb agent (v3po) if available.
  if [ -f "$V3PO_TARBALL" ] ; then
    V3PO_TARBALL_DIR="$(tar tvf $V3PO_TARBALL | head -1 | awk '{ print $6 }' | cut -d / -f 1)"
    V3PO_KARAF_DIR="$HONEYCOMB_INSTALL_DIR/$V3PO_TARBALL_DIR"
    echo "---"
    echo "  Installing Honeycomb VPP agent in $V3PO_KARAF_DIR from $V3PO_TARBALL"
    echo "---"
    [ ! -d "$HONEYCOMB_INSTALL_DIR" ] && mkdir -p $HONEYCOMB_INSTALL_DIR
    [ -d "$V3PO_KARAF_DIR" ] && rm -rf $V3PO_KARAF_DIR
    tar xzf $V3PO_TARBALL -C $HONEYCOMB_INSTALL_DIR
    $V3PO_KARAF_DIR/bin/start
    echo -e "\n\n# Add V3PO karaf bin directory to PATH\nexport PATH=\$PATH:$V3PO_KARAF_DIR/bin" >> $VAGRANT_BASH_ALIASES
  else
    echo "---"
    echo "  WARNING: V3PO Tarball is not available: $V3PO_TARBALL"
    echo "---"
  fi

# ODL VBD application VM specific installation components
else
  if [ -d "$KARAF_PACKAGES_MOUNT" ] ; then
    VBD_TARBALL="$(find $KARAF_PACKAGES_MOUNT -name vbd-karaf*.tar.gz | sort | tail -1)"
    if [ ! -f "$VBD_TARBALL" ] ; then
      echo "---"
      echo "  Fetching latest VBD tarball from $FDIO_SNAPSHOT_URL"
      echo "---"
      sudo -H -u vagrant mvn dependency:get -DremoteRepositories=$FDIO_SNAPSHOT_URL -DgroupId=io.fd.honeycomb.vbd -DartifactId=vbd-karaf -Dversion=1.0.0-SNAPSHOT -Dpackaging=tar.gz -Dtransitive=false
      M2_TB_DIR="$VAGRANT_M2_REPOSITORY/io/fd/honeycomb/vbd/vbd-karaf/1.0.0-SNAPSHOT"
      VBD_TARBALL="$(find $M2_TB_DIR -name vbd-karaf*.tar.gz | grep -v vbd-karaf-1.0.0-SNAPSHOT | sort | tail -1)"
      echo "---"
      echo "  Copying VBD tarball ($(basename $VBD_TARBALL)) to $KARAF_PACKAGES_MOUNT"
      echo "---"
      [ -f "$VBD_TARBALL" ] && cp -p $VBD_TARBALL $KARAF_PACKAGES_MOUNT
      VBD_TARBALL="$(find $KARAF_PACKAGES_MOUNT -name vbd-karaf*.tar.gz | sort | tail -1)"
    fi
  else
    VBD_TARBALL="$(find $HONEYCOMB_MOUNT/vbd/karaf/target/ -name vbd-karaf*.tar.gz | sort | tail -1)"
  fi

  # Build Honeycomb if necessary
  if [ ! -f "$VBD_TARBALL" ] ; then
    echo "---"
    echo "  Building Honeycomb..."
    echo "---"
    cd $HONEYCOMB_MOUNT
    sudo -H -u vagrant mvn clean install -DskipTests
    VBD_TARBALL="$HONEYCOMB_MOUNT/vbd/karaf/target/vbd-karaf*.tar.gz"
  fi
  # Install ODL Virtual Bridge Domain App if available.
  if [ -f "$VBD_TARBALL" ] ; then
    VBD_TARBALL_DIR="$(tar tvf $VBD_TARBALL | head -1 | awk '{ print $6 }' | cut -d / -f 1)"
    VBD_KARAF_DIR="$HONEYCOMB_INSTALL_DIR/$VBD_TARBALL_DIR"
    echo "---"
    echo "  Installing ODL Virtual Bridge Domain application in $HONEYCOMB_INSTALL_DIR/$VBD_SNAPSHOT"
    echo "---"
    [ ! -d "$HONEYCOMB_INSTALL_DIR" ] && mkdir -p $HONEYCOMB_INSTALL_DIR
    [ -d "$VBD_KARAF_DIR" ] && rm -rf $VBD_KARAF_DIR
    tar xzf $VBD_TARBALL -C $HONEYCOMB_INSTALL_DIR
    $VBD_KARAF_DIR/bin/start
    echo -e "\n\n# Add VBD karaf bin directory to PATH\nexport PATH=\$PATH:$VBD_KARAF_DIR/bin" >> $VAGRANT_BASH_ALIASES
  else
    echo "---"
    echo "  WARNING: VBD tarball is not available: $VBD_TARBALL"
    echo "---"
  fi

  # Install google chrome browser for ODL YANGUI
  echo "---"
  echo "  Installing google-chrome"
  echo "---"
  cd /opt
  wget -q $GOOGLE_CHROME_URL
  sudo dpkg -i $GOOGLE_CHROME_DEB_PKG
  sudo apt-get install -fy
fi

echo "---"
echo "  ========================="
echo "  VM Installation Complete!"
echo "  ========================="
echo "---"