blob: 0ff805555159409e1dc9c08a95e781d0883b18f2 [file] [log] [blame]
alshabib48b63e12014-12-08 23:53:03 -08001#!/bin/bash
2# vm-setup.sh
3#
Marc De Leenheer1e3d3a02015-01-12 20:13:54 -08004# This script installs ONOS dependencies and installs a desktop environment on a Mininet VM.
alshabib48b63e12014-12-08 23:53:03 -08005
6
7export CURRENT_USER=distributed
8export USER_HOME=/home/${CURRENT_USER}
9
alshabib4aa072d2014-12-10 20:59:34 -080010IDEA_URL=http://download.jetbrains.com/idea/ideaIC-14.0.2.tar.gz
alshabib48b63e12014-12-08 23:53:03 -080011
12# -------------- Setup keys -------------------
13
14mkdir -p ~/.ssh
alshabibffbf45a2014-12-09 10:00:47 -080015ssh-keygen -t rsa -P "" -f .ssh/id_rsa
16cp .ssh/id_rsa.pub .ssh/authorized_keys
alshabib48b63e12014-12-08 23:53:03 -080017
18# -------------- Install Karaf ----------------
19
20mkdir Applications
21cd Applications
22wget http://apache.osuosl.org/karaf/3.0.2/apache-karaf-3.0.2.zip
23unzip apache-karaf-3.0.2.zip
24cd -
25
alshabibffbf45a2014-12-09 10:00:47 -080026mkdir Downloads
27cp Applications/apache-karaf-3.0.2.zip Downloads/
28
alshabib48b63e12014-12-08 23:53:03 -080029#--------------- Setup Docker env ------------
30
31mkdir -p docker/onos-tutorial
32cd docker/onos-tutorial
33cat > Dockerfile << EOF
34FROM ubuntu-upstart:14.10
35MAINTAINER Ali Al-Shabibi <ali@onlab.us>
36RUN apt-get update && apt-get install -y openjdk-8-jre openssh-server
37RUN mkdir /var/run/sshd
38RUN echo 'root:onosrocks' | chpasswd
39RUN sed -i 's/PermitRootLogin without-password/PermitRootLogin yes/' /etc/ssh/sshd_config
40# SSH login fix. Otherwise user is kicked off after login
41RUN sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd
42ENV NOTVISIBLE "in users profile"
43RUN echo "export VISIBLE=now" >> /etc/profile
alshabib3f0991a2014-12-09 13:36:53 -080044EXPOSE 22 6633 8181
alshabib48b63e12014-12-08 23:53:03 -080045CMD ["/sbin/init"]
46EOF
47
48sudo docker build -t onos/tutorial-dist .
49
50cd -
51
52# -------------- Download ONOS ----------------
53
alshabib0ecf4c42014-12-11 15:11:44 -080054git clone https://github.com/bocon13/onos-byon.git
alshabib48b63e12014-12-08 23:53:03 -080055git clone https://gerrit.onosproject.org/onos
alshabib77b4f212014-12-09 00:30:54 -080056cd onos
alshabib247d2112014-12-09 00:25:53 -080057git checkout 1.0.0
alshabib63ee8322014-12-12 14:54:09 -080058git config --global user.email "tutorial@localhost"
59git config --global user.name "Mr. Tutorial"
60git fetch https://gerrit.onosproject.org/onos refs/changes/07/2107/1 && git cherry-pick FETCH_HEAD
alshabib77b4f212014-12-09 00:30:54 -080061cd -
alshabib48b63e12014-12-08 23:53:03 -080062
alshabib316fe242014-12-11 17:50:00 -080063echo "export JAVA_HOME=''"
alshabib48b63e12014-12-08 23:53:03 -080064echo ". ~/onos/tools/dev/bash_profile" >> ~/.bashrc
65echo "export ONOS_USER=root" >> ~/.bashrc
alshabibffbf45a2014-12-09 10:00:47 -080066
alshabib7dcc33f2014-12-10 23:46:45 -080067sed -i -e 's/open/xdg-open/' ~/onos/tools/test/bin/onos-gui
68
alshabib42beadc2014-12-09 00:01:26 -080069cat > onos/tools/test/cells/docker << EOF
70export ONOS_NIC="172.17.0.*"
alshabibffbf45a2014-12-09 10:00:47 -080071export OC1="\$(sudo docker inspect --format '{{ .NetworkSettings.IPAddress }}' onos-1)"
72export OC2="\$(sudo docker inspect --format '{{ .NetworkSettings.IPAddress }}' onos-2)"
73export OC3="\$(sudo docker inspect --format '{{ .NetworkSettings.IPAddress }}' onos-3)"
alshabib42beadc2014-12-09 00:01:26 -080074export OCN="localhost"
alshabib1c53a802014-12-10 23:41:31 -080075export OCI="\${OC1}"
alshabib42beadc2014-12-09 00:01:26 -080076export ONOS_FEATURES="webconsole,onos-api,onos-core,onos-cli,onos-rest,onos-gui,onos-openflow,onos-app-fwd,onos-app-proxyarp,onos-app-mobility"
77EOF
78
alshabib5fe05c22014-12-12 14:14:53 -080079echo "unset JAVA_HOME" >> ~/.bashrc
alshabib7bfe1542014-12-11 17:19:10 -080080echo "sudo service onos stop > /dev/null 2>&1" >> ~/.bashrc
alshabib1f5b85d2014-12-11 16:01:31 -080081echo "cell docker > /dev/null 2>&1" >> ~/.bashrc
alshabib48b63e12014-12-08 23:53:03 -080082
83sed -i -e s/sdn/root/ onos/tools/package/debian/onos.conf
84
85cd onos && mvn clean install && cd -
alshabib42beadc2014-12-09 00:01:26 -080086
alshabibd1a096f2014-12-10 23:34:04 -080087#--------------- set up mininet script --------
88
89cat > ~/startmn.sh << EOF
90#!/bin/bash
alshabib7bfe1542014-12-11 17:19:10 -080091sudo python ~/onos/tools/test/topos/sol.py \$OC1 \$OC2 \$OC3
alshabibd1a096f2014-12-10 23:34:04 -080092EOF
93
94chmod +x ~/startmn.sh
alshabib48b63e12014-12-08 23:53:03 -080095
96# -------------- Setup Wireshark dissector ----
97
98wget -O openflow.lua "https://gerrit.onosproject.org/gitweb?p=onos-vm.git;a=blob_plain;hb=refs/heads/onos-tutorial;f=openflow.lua"
99mkdir -p .wireshark/plugins
100mv openflow.lua .wireshark/plugins
101
102
103
104# -------------- Setup Desktop ----------------
105
106sudo apt-get install -y xorg lxde
107
108#TODO: add backgrounds folder
109sudo mkdir -p /usr/share/backgrounds
110#TODO: change background
111# Remove wallpaper, change background color
112sudo sed -i 's/wallpaper_mode=1/wallpaper_mode=0/g' /usr/share/lxde/pcmanfm/LXDE.conf
113sudo sed -i 's/desktop_bg=#000000/desktop_bg=#104187/g' /usr/share/lxde/pcmanfm/LXDE.conf
114
115sudo sed -i 's/lang=1/lang=0/g' /etc/lxdm/default.conf
116sudo sed -i 's/bottom_pane=1/bottom_pane=0/g' /etc/lxdm/default.conf
117sudo sed -i 's/disable=0/disable=1/g' /etc/lxdm/default.conf
118
119
120wget -O onos.png "https://gerrit.onosproject.org/gitweb?p=onos-vm.git;a=blob_plain;hb=refs/heads/onos-tutorial;f=onos.png"
121sudo cp onos.png /usr/share/backgrounds/default.png
122
123# Automatically start LXDE on login
124echo '[[ -z $DISPLAY && $XDG_VTNR -eq 1 ]] && exec startx' >> ~/.bashrc
125
126# Automatically log into the VM
127#sudo sed -i 's/exec /sbin/getty -8 38400 tty1//g' /etc/init/tty1.conf
128#sudo sed -i '$ d' /etc/init/tty1.conf
129#echo 'exec /bin/login -f bob < /dev/tty1 > /dev/tty1 2>&1' | sudo tee -a /etc/init/tty1.conf
130
131# Disable screensaver
132sudo sed -i '/screensaver/d' /etc/xdg/lxsession/LXDE/autostart
133cat > ${USER_HOME}/.xsessionrc << EOF
134# disable screensaver
135xset s off
136# disable dpms (standby)
137xset -dpms
138EOF
139
140# Change LXTerminal default colors
141#sudo sed -i 's/bgcolor=#000000000000/bgcolor=#ffffffffffff/g' ${USER_HOME}/.config/lxterminal/lxterminal.conf
142#sudo sed -i 's/fgcolor=#aaaaaaaaaaaa/fgcolor=#000000000000/g' ${USER_HOME}/.config/lxterminal/lxterminal.conf
143sudo sed -i 's/bgcolor=#000000000000/bgcolor=#ffffffffffff/g' /usr/share/lxterminal/lxterminal.conf
144sudo sed -i 's/fgcolor=#aaaaaaaaaaaa/fgcolor=#000000000000/g' /usr/share/lxterminal/lxterminal.conf
145
146DESKTOP=${USER_HOME}/Desktop
147
148mkdir -p ${DESKTOP}
149
alshabib4aa072d2014-12-10 20:59:34 -0800150cat > ${DESKTOP}/IntelliJ << EOF
alshabibffbf45a2014-12-09 10:00:47 -0800151[Desktop Entry]
152Encoding=UTF-8
153Type=Application
alshabib4aa072d2014-12-10 20:59:34 -0800154Name=IntelliJ
155Name[en_US]=IntelliJ
156Icon=/home/distributed/Applications/idea/bin/idea.png
157Exec=/home/distributed/Applications/idea/bin/idea.sh
alshabibffbf45a2014-12-09 10:00:47 -0800158Comment[en_US]=
159EOF
160
alshabib48b63e12014-12-08 23:53:03 -0800161cat > ${DESKTOP}/Tutorial << EOF
162[Desktop Entry]
163Encoding=UTF-8
164Type=Application
165Name=ONOS Tutorial
166Name[en_US]=ONOS Tutorial
167Icon=internet-web-browser
168Exec=/usr/bin/chromium-browser https://wiki.onosproject.org/display/ONOS/Distributed+ONOS+Tutorial
169Comment[en_US]=
170EOF
171
alshabib48b63e12014-12-08 23:53:03 -0800172
173cat > ${DESKTOP}/Wireshark << EOF
174[Desktop Entry]
175Encoding=UTF-8
176Type=Application
177Name=Wireshark
178Name[en_US]=Wireshark
179Icon=wireshark
180Exec=/usr/bin/wireshark
181Comment[en_US]=
182EOF
183
alshabib4c5231b2014-12-11 15:32:37 -0800184cat > ${DESKTOP}/Terminal << EOF
185[Desktop Entry]
186Encoding=UTF-8
187Name=LXTerminal
188TryExec=lxterminal
189Exec=lxterminal
190Icon=lxterminal
191Type=Application
192Categories=GTK;Utility;TerminalEmulator;
193EOF
194
alshabib48b63e12014-12-08 23:53:03 -0800195# ------------- Install Other Tools -------------
196sudo apt-get install -y wireshark
197# Enable root-less wireshark and add mininet
198echo "Enabling wireshark group"
199echo "wireshark-common wireshark-common/install-setuid boolean true" | sudo debconf-set-selections
200sudo dpkg-reconfigure -f noninteractive wireshark-common
201sudo usermod -a -G wireshark mininet
202sudo usermod -a -G wireshark tutorial1
203
204
205echo "Installing VirtualBox Guest Additions"
206sudo apt-get install -y virtualbox-guest-x11
207
alshabibffbf45a2014-12-09 10:00:47 -0800208sudo apt-get install -y git-review
209
alshabib4aa072d2014-12-10 20:59:34 -0800210cd ~/Applications
211
212wget -c -N -O /tmp/idea.tar.gz ${IDEA_URL}
213tar xzf /tmp/idea.tar.gz
214sudo mv idea-IC-139.659.2 idea
215
216cd -
alshabibffbf45a2014-12-09 10:00:47 -0800217
alshabib0ecf4c42014-12-11 15:11:44 -0800218sudo apt-get clean
219
alshabib48b63e12014-12-08 23:53:03 -0800220# ------------- Zero Unused Blocks -------------
221#TODO investigate zerofree
222echo "Zeroing unused blocks"
223sync
224dd if=/dev/zero of=tmp-zeros
225sync
226rm tmp-zeros
227sync