blob: 97cbb1917b5dde8304bf58e922acb18df4fddc9e [file] [log] [blame]
alshabib48b63e12014-12-08 23:53:03 -08001#!/bin/bash
2# vm-setup.sh
3#
4# This script installs ONOS dependencies and installs a desktop environment on a Miniet VM.
5
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
alshabib1f5b85d2014-12-11 16:01:31 -080058git fetch https://gerrit.onosproject.org/onos refs/changes/07/2107/1 && git checkout FETCH_HEAD
alshabib77b4f212014-12-09 00:30:54 -080059cd -
alshabib48b63e12014-12-08 23:53:03 -080060
61echo ". ~/onos/tools/dev/bash_profile" >> ~/.bashrc
62echo "export ONOS_USER=root" >> ~/.bashrc
alshabibffbf45a2014-12-09 10:00:47 -080063
alshabib7dcc33f2014-12-10 23:46:45 -080064sed -i -e 's/open/xdg-open/' ~/onos/tools/test/bin/onos-gui
65
alshabib42beadc2014-12-09 00:01:26 -080066cat > onos/tools/test/cells/docker << EOF
67export ONOS_NIC="172.17.0.*"
alshabibffbf45a2014-12-09 10:00:47 -080068export OC1="\$(sudo docker inspect --format '{{ .NetworkSettings.IPAddress }}' onos-1)"
69export OC2="\$(sudo docker inspect --format '{{ .NetworkSettings.IPAddress }}' onos-2)"
70export OC3="\$(sudo docker inspect --format '{{ .NetworkSettings.IPAddress }}' onos-3)"
alshabib42beadc2014-12-09 00:01:26 -080071export OCN="localhost"
alshabib1c53a802014-12-10 23:41:31 -080072export OCI="\${OC1}"
alshabib42beadc2014-12-09 00:01:26 -080073export ONOS_FEATURES="webconsole,onos-api,onos-core,onos-cli,onos-rest,onos-gui,onos-openflow,onos-app-fwd,onos-app-proxyarp,onos-app-mobility"
74EOF
75
alshabib1f5b85d2014-12-11 16:01:31 -080076echo "cell docker > /dev/null 2>&1" >> ~/.bashrc
alshabib48b63e12014-12-08 23:53:03 -080077
78sed -i -e s/sdn/root/ onos/tools/package/debian/onos.conf
79
80cd onos && mvn clean install && cd -
alshabib42beadc2014-12-09 00:01:26 -080081
alshabibd1a096f2014-12-10 23:34:04 -080082#--------------- set up mininet script --------
83
84cat > ~/startmn.sh << EOF
85#!/bin/bash
86sudo python ~/onos/tools/test/topos/sol.py $OC1 $OC2 $OC3
87EOF
88
89chmod +x ~/startmn.sh
alshabib48b63e12014-12-08 23:53:03 -080090
91# -------------- Setup Wireshark dissector ----
92
93wget -O openflow.lua "https://gerrit.onosproject.org/gitweb?p=onos-vm.git;a=blob_plain;hb=refs/heads/onos-tutorial;f=openflow.lua"
94mkdir -p .wireshark/plugins
95mv openflow.lua .wireshark/plugins
96
97
98
99# -------------- Setup Desktop ----------------
100
101sudo apt-get install -y xorg lxde
102
103#TODO: add backgrounds folder
104sudo mkdir -p /usr/share/backgrounds
105#TODO: change background
106# Remove wallpaper, change background color
107sudo sed -i 's/wallpaper_mode=1/wallpaper_mode=0/g' /usr/share/lxde/pcmanfm/LXDE.conf
108sudo sed -i 's/desktop_bg=#000000/desktop_bg=#104187/g' /usr/share/lxde/pcmanfm/LXDE.conf
109
110sudo sed -i 's/lang=1/lang=0/g' /etc/lxdm/default.conf
111sudo sed -i 's/bottom_pane=1/bottom_pane=0/g' /etc/lxdm/default.conf
112sudo sed -i 's/disable=0/disable=1/g' /etc/lxdm/default.conf
113
114
115wget -O onos.png "https://gerrit.onosproject.org/gitweb?p=onos-vm.git;a=blob_plain;hb=refs/heads/onos-tutorial;f=onos.png"
116sudo cp onos.png /usr/share/backgrounds/default.png
117
118# Automatically start LXDE on login
119echo '[[ -z $DISPLAY && $XDG_VTNR -eq 1 ]] && exec startx' >> ~/.bashrc
120
121# Automatically log into the VM
122#sudo sed -i 's/exec /sbin/getty -8 38400 tty1//g' /etc/init/tty1.conf
123#sudo sed -i '$ d' /etc/init/tty1.conf
124#echo 'exec /bin/login -f bob < /dev/tty1 > /dev/tty1 2>&1' | sudo tee -a /etc/init/tty1.conf
125
126# Disable screensaver
127sudo sed -i '/screensaver/d' /etc/xdg/lxsession/LXDE/autostart
128cat > ${USER_HOME}/.xsessionrc << EOF
129# disable screensaver
130xset s off
131# disable dpms (standby)
132xset -dpms
133EOF
134
135# Change LXTerminal default colors
136#sudo sed -i 's/bgcolor=#000000000000/bgcolor=#ffffffffffff/g' ${USER_HOME}/.config/lxterminal/lxterminal.conf
137#sudo sed -i 's/fgcolor=#aaaaaaaaaaaa/fgcolor=#000000000000/g' ${USER_HOME}/.config/lxterminal/lxterminal.conf
138sudo sed -i 's/bgcolor=#000000000000/bgcolor=#ffffffffffff/g' /usr/share/lxterminal/lxterminal.conf
139sudo sed -i 's/fgcolor=#aaaaaaaaaaaa/fgcolor=#000000000000/g' /usr/share/lxterminal/lxterminal.conf
140
141DESKTOP=${USER_HOME}/Desktop
142
143mkdir -p ${DESKTOP}
144
alshabib4aa072d2014-12-10 20:59:34 -0800145cat > ${DESKTOP}/IntelliJ << EOF
alshabibffbf45a2014-12-09 10:00:47 -0800146[Desktop Entry]
147Encoding=UTF-8
148Type=Application
alshabib4aa072d2014-12-10 20:59:34 -0800149Name=IntelliJ
150Name[en_US]=IntelliJ
151Icon=/home/distributed/Applications/idea/bin/idea.png
152Exec=/home/distributed/Applications/idea/bin/idea.sh
alshabibffbf45a2014-12-09 10:00:47 -0800153Comment[en_US]=
154EOF
155
alshabib48b63e12014-12-08 23:53:03 -0800156cat > ${DESKTOP}/Tutorial << EOF
157[Desktop Entry]
158Encoding=UTF-8
159Type=Application
160Name=ONOS Tutorial
161Name[en_US]=ONOS Tutorial
162Icon=internet-web-browser
163Exec=/usr/bin/chromium-browser https://wiki.onosproject.org/display/ONOS/Distributed+ONOS+Tutorial
164Comment[en_US]=
165EOF
166
alshabib48b63e12014-12-08 23:53:03 -0800167
168cat > ${DESKTOP}/Wireshark << EOF
169[Desktop Entry]
170Encoding=UTF-8
171Type=Application
172Name=Wireshark
173Name[en_US]=Wireshark
174Icon=wireshark
175Exec=/usr/bin/wireshark
176Comment[en_US]=
177EOF
178
alshabib4c5231b2014-12-11 15:32:37 -0800179cat > ${DESKTOP}/Terminal << EOF
180[Desktop Entry]
181Encoding=UTF-8
182Name=LXTerminal
183TryExec=lxterminal
184Exec=lxterminal
185Icon=lxterminal
186Type=Application
187Categories=GTK;Utility;TerminalEmulator;
188EOF
189
alshabib48b63e12014-12-08 23:53:03 -0800190# ------------- Install Other Tools -------------
191sudo apt-get install -y wireshark
192# Enable root-less wireshark and add mininet
193echo "Enabling wireshark group"
194echo "wireshark-common wireshark-common/install-setuid boolean true" | sudo debconf-set-selections
195sudo dpkg-reconfigure -f noninteractive wireshark-common
196sudo usermod -a -G wireshark mininet
197sudo usermod -a -G wireshark tutorial1
198
199
200echo "Installing VirtualBox Guest Additions"
201sudo apt-get install -y virtualbox-guest-x11
202
alshabibffbf45a2014-12-09 10:00:47 -0800203sudo apt-get install -y git-review
204
alshabib4aa072d2014-12-10 20:59:34 -0800205cd ~/Applications
206
207wget -c -N -O /tmp/idea.tar.gz ${IDEA_URL}
208tar xzf /tmp/idea.tar.gz
209sudo mv idea-IC-139.659.2 idea
210
211cd -
alshabibffbf45a2014-12-09 10:00:47 -0800212
alshabib0ecf4c42014-12-11 15:11:44 -0800213sudo apt-get clean
214
alshabib48b63e12014-12-08 23:53:03 -0800215# ------------- Zero Unused Blocks -------------
216#TODO investigate zerofree
217echo "Zeroing unused blocks"
218sync
219dd if=/dev/zero of=tmp-zeros
220sync
221rm tmp-zeros
222sync