blob: a6e983c65bee5b5807b8decb8db96e4feaadf3a1 [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
alshabib316fe242014-12-11 17:50:00 -080061echo "export JAVA_HOME=''"
alshabib48b63e12014-12-08 23:53:03 -080062echo ". ~/onos/tools/dev/bash_profile" >> ~/.bashrc
63echo "export ONOS_USER=root" >> ~/.bashrc
alshabibffbf45a2014-12-09 10:00:47 -080064
alshabib7dcc33f2014-12-10 23:46:45 -080065sed -i -e 's/open/xdg-open/' ~/onos/tools/test/bin/onos-gui
66
alshabib42beadc2014-12-09 00:01:26 -080067cat > onos/tools/test/cells/docker << EOF
68export ONOS_NIC="172.17.0.*"
alshabibffbf45a2014-12-09 10:00:47 -080069export OC1="\$(sudo docker inspect --format '{{ .NetworkSettings.IPAddress }}' onos-1)"
70export OC2="\$(sudo docker inspect --format '{{ .NetworkSettings.IPAddress }}' onos-2)"
71export OC3="\$(sudo docker inspect --format '{{ .NetworkSettings.IPAddress }}' onos-3)"
alshabib42beadc2014-12-09 00:01:26 -080072export OCN="localhost"
alshabib1c53a802014-12-10 23:41:31 -080073export OCI="\${OC1}"
alshabib42beadc2014-12-09 00:01:26 -080074export ONOS_FEATURES="webconsole,onos-api,onos-core,onos-cli,onos-rest,onos-gui,onos-openflow,onos-app-fwd,onos-app-proxyarp,onos-app-mobility"
75EOF
76
alshabib7bfe1542014-12-11 17:19:10 -080077echo "sudo service onos stop > /dev/null 2>&1" >> ~/.bashrc
alshabib1f5b85d2014-12-11 16:01:31 -080078echo "cell docker > /dev/null 2>&1" >> ~/.bashrc
alshabib48b63e12014-12-08 23:53:03 -080079
80sed -i -e s/sdn/root/ onos/tools/package/debian/onos.conf
81
82cd onos && mvn clean install && cd -
alshabib42beadc2014-12-09 00:01:26 -080083
alshabibd1a096f2014-12-10 23:34:04 -080084#--------------- set up mininet script --------
85
86cat > ~/startmn.sh << EOF
87#!/bin/bash
alshabib7bfe1542014-12-11 17:19:10 -080088sudo python ~/onos/tools/test/topos/sol.py \$OC1 \$OC2 \$OC3
alshabibd1a096f2014-12-10 23:34:04 -080089EOF
90
91chmod +x ~/startmn.sh
alshabib48b63e12014-12-08 23:53:03 -080092
93# -------------- Setup Wireshark dissector ----
94
95wget -O openflow.lua "https://gerrit.onosproject.org/gitweb?p=onos-vm.git;a=blob_plain;hb=refs/heads/onos-tutorial;f=openflow.lua"
96mkdir -p .wireshark/plugins
97mv openflow.lua .wireshark/plugins
98
99
100
101# -------------- Setup Desktop ----------------
102
103sudo apt-get install -y xorg lxde
104
105#TODO: add backgrounds folder
106sudo mkdir -p /usr/share/backgrounds
107#TODO: change background
108# Remove wallpaper, change background color
109sudo sed -i 's/wallpaper_mode=1/wallpaper_mode=0/g' /usr/share/lxde/pcmanfm/LXDE.conf
110sudo sed -i 's/desktop_bg=#000000/desktop_bg=#104187/g' /usr/share/lxde/pcmanfm/LXDE.conf
111
112sudo sed -i 's/lang=1/lang=0/g' /etc/lxdm/default.conf
113sudo sed -i 's/bottom_pane=1/bottom_pane=0/g' /etc/lxdm/default.conf
114sudo sed -i 's/disable=0/disable=1/g' /etc/lxdm/default.conf
115
116
117wget -O onos.png "https://gerrit.onosproject.org/gitweb?p=onos-vm.git;a=blob_plain;hb=refs/heads/onos-tutorial;f=onos.png"
118sudo cp onos.png /usr/share/backgrounds/default.png
119
120# Automatically start LXDE on login
121echo '[[ -z $DISPLAY && $XDG_VTNR -eq 1 ]] && exec startx' >> ~/.bashrc
122
123# Automatically log into the VM
124#sudo sed -i 's/exec /sbin/getty -8 38400 tty1//g' /etc/init/tty1.conf
125#sudo sed -i '$ d' /etc/init/tty1.conf
126#echo 'exec /bin/login -f bob < /dev/tty1 > /dev/tty1 2>&1' | sudo tee -a /etc/init/tty1.conf
127
128# Disable screensaver
129sudo sed -i '/screensaver/d' /etc/xdg/lxsession/LXDE/autostart
130cat > ${USER_HOME}/.xsessionrc << EOF
131# disable screensaver
132xset s off
133# disable dpms (standby)
134xset -dpms
135EOF
136
137# Change LXTerminal default colors
138#sudo sed -i 's/bgcolor=#000000000000/bgcolor=#ffffffffffff/g' ${USER_HOME}/.config/lxterminal/lxterminal.conf
139#sudo sed -i 's/fgcolor=#aaaaaaaaaaaa/fgcolor=#000000000000/g' ${USER_HOME}/.config/lxterminal/lxterminal.conf
140sudo sed -i 's/bgcolor=#000000000000/bgcolor=#ffffffffffff/g' /usr/share/lxterminal/lxterminal.conf
141sudo sed -i 's/fgcolor=#aaaaaaaaaaaa/fgcolor=#000000000000/g' /usr/share/lxterminal/lxterminal.conf
142
143DESKTOP=${USER_HOME}/Desktop
144
145mkdir -p ${DESKTOP}
146
alshabib4aa072d2014-12-10 20:59:34 -0800147cat > ${DESKTOP}/IntelliJ << EOF
alshabibffbf45a2014-12-09 10:00:47 -0800148[Desktop Entry]
149Encoding=UTF-8
150Type=Application
alshabib4aa072d2014-12-10 20:59:34 -0800151Name=IntelliJ
152Name[en_US]=IntelliJ
153Icon=/home/distributed/Applications/idea/bin/idea.png
154Exec=/home/distributed/Applications/idea/bin/idea.sh
alshabibffbf45a2014-12-09 10:00:47 -0800155Comment[en_US]=
156EOF
157
alshabib48b63e12014-12-08 23:53:03 -0800158cat > ${DESKTOP}/Tutorial << EOF
159[Desktop Entry]
160Encoding=UTF-8
161Type=Application
162Name=ONOS Tutorial
163Name[en_US]=ONOS Tutorial
164Icon=internet-web-browser
165Exec=/usr/bin/chromium-browser https://wiki.onosproject.org/display/ONOS/Distributed+ONOS+Tutorial
166Comment[en_US]=
167EOF
168
alshabib48b63e12014-12-08 23:53:03 -0800169
170cat > ${DESKTOP}/Wireshark << EOF
171[Desktop Entry]
172Encoding=UTF-8
173Type=Application
174Name=Wireshark
175Name[en_US]=Wireshark
176Icon=wireshark
177Exec=/usr/bin/wireshark
178Comment[en_US]=
179EOF
180
alshabib4c5231b2014-12-11 15:32:37 -0800181cat > ${DESKTOP}/Terminal << EOF
182[Desktop Entry]
183Encoding=UTF-8
184Name=LXTerminal
185TryExec=lxterminal
186Exec=lxterminal
187Icon=lxterminal
188Type=Application
189Categories=GTK;Utility;TerminalEmulator;
190EOF
191
alshabib48b63e12014-12-08 23:53:03 -0800192# ------------- Install Other Tools -------------
193sudo apt-get install -y wireshark
194# Enable root-less wireshark and add mininet
195echo "Enabling wireshark group"
196echo "wireshark-common wireshark-common/install-setuid boolean true" | sudo debconf-set-selections
197sudo dpkg-reconfigure -f noninteractive wireshark-common
198sudo usermod -a -G wireshark mininet
199sudo usermod -a -G wireshark tutorial1
200
201
202echo "Installing VirtualBox Guest Additions"
203sudo apt-get install -y virtualbox-guest-x11
204
alshabibffbf45a2014-12-09 10:00:47 -0800205sudo apt-get install -y git-review
206
alshabib4aa072d2014-12-10 20:59:34 -0800207cd ~/Applications
208
209wget -c -N -O /tmp/idea.tar.gz ${IDEA_URL}
210tar xzf /tmp/idea.tar.gz
211sudo mv idea-IC-139.659.2 idea
212
213cd -
alshabibffbf45a2014-12-09 10:00:47 -0800214
alshabib0ecf4c42014-12-11 15:11:44 -0800215sudo apt-get clean
216
alshabib48b63e12014-12-08 23:53:03 -0800217# ------------- Zero Unused Blocks -------------
218#TODO investigate zerofree
219echo "Zeroing unused blocks"
220sync
221dd if=/dev/zero of=tmp-zeros
222sync
223rm tmp-zeros
224sync