blob: 5eab889a65644c21052278453a2e4e544d7905b4 [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
10
11# -------------- Setup keys -------------------
12
13mkdir -p ~/.ssh
14ssh-keygen -t dsa -P "" -f .ssh/id_dsa
15cp .ssh/id_dsa.pub .ssh/authorized_keys
16
17# -------------- Install Karaf ----------------
18
19mkdir Applications
20cd Applications
21wget http://apache.osuosl.org/karaf/3.0.2/apache-karaf-3.0.2.zip
22unzip apache-karaf-3.0.2.zip
23cd -
24
25#--------------- Setup Docker env ------------
26
27mkdir -p docker/onos-tutorial
28cd docker/onos-tutorial
29cat > Dockerfile << EOF
30FROM ubuntu-upstart:14.10
31MAINTAINER Ali Al-Shabibi <ali@onlab.us>
32RUN apt-get update && apt-get install -y openjdk-8-jre openssh-server
33RUN mkdir /var/run/sshd
34RUN echo 'root:onosrocks' | chpasswd
35RUN sed -i 's/PermitRootLogin without-password/PermitRootLogin yes/' /etc/ssh/sshd_config
36# SSH login fix. Otherwise user is kicked off after login
37RUN sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd
38ENV NOTVISIBLE "in users profile"
39RUN echo "export VISIBLE=now" >> /etc/profile
40EXPOSE 22 6633
41CMD ["/sbin/init"]
42EOF
43
44sudo docker build -t onos/tutorial-dist .
45
46cd -
47
48# -------------- Download ONOS ----------------
49
50git clone https://gerrit.onosproject.org/onos
51
52echo ". ~/onos/tools/dev/bash_profile" >> ~/.bashrc
53echo "export ONOS_USER=root" >> ~/.bashrc
alshabib42beadc2014-12-09 00:01:26 -080054echo "sudo docker run --name onos-1 -d -P onos/tutorial-dist > /dev/null 2>&1" >> ~/.bashrc
55echo "sudo docker run --name onos-2 -d -P onos/tutorial-dist > /dev/null 2>&1" >> ~/.bashrc
56echo "sudo docker run --name onos-3 -d -P onos/tutorial-dist > /dev/null 2>&1" >> ~/.bashrc
57
58cat > onos/tools/test/cells/docker << EOF
59export ONOS_NIC="172.17.0.*"
60export OC1=`sudo docker inspect --format '{{ .NetworkSettings.IPAddress }}' "onos-1"`
61export OC2=`sudo docker inspect --format '{{ .NetworkSettings.IPAddress }}' "onos-2"`
62export OC3=`sudo docker inspect --format '{{ .NetworkSettings.IPAddress }}' "onos-3"`
63export OCN="localhost"
64export OCI="${OC1}"
65export ONOS_FEATURES="webconsole,onos-api,onos-core,onos-cli,onos-rest,onos-gui,onos-openflow,onos-app-fwd,onos-app-proxyarp,onos-app-mobility"
66EOF
67
68echo "cell docker" >> ~/.bashrc
alshabib48b63e12014-12-08 23:53:03 -080069
70sed -i -e s/sdn/root/ onos/tools/package/debian/onos.conf
71
72cd onos && mvn clean install && cd -
alshabib42beadc2014-12-09 00:01:26 -080073onos-package
74
alshabib48b63e12014-12-08 23:53:03 -080075
76# -------------- Setup Wireshark dissector ----
77
78wget -O openflow.lua "https://gerrit.onosproject.org/gitweb?p=onos-vm.git;a=blob_plain;hb=refs/heads/onos-tutorial;f=openflow.lua"
79mkdir -p .wireshark/plugins
80mv openflow.lua .wireshark/plugins
81
82
83
84# -------------- Setup Desktop ----------------
85
86sudo apt-get install -y xorg lxde
87
88#TODO: add backgrounds folder
89sudo mkdir -p /usr/share/backgrounds
90#TODO: change background
91# Remove wallpaper, change background color
92sudo sed -i 's/wallpaper_mode=1/wallpaper_mode=0/g' /usr/share/lxde/pcmanfm/LXDE.conf
93sudo sed -i 's/desktop_bg=#000000/desktop_bg=#104187/g' /usr/share/lxde/pcmanfm/LXDE.conf
94
95sudo sed -i 's/lang=1/lang=0/g' /etc/lxdm/default.conf
96sudo sed -i 's/bottom_pane=1/bottom_pane=0/g' /etc/lxdm/default.conf
97sudo sed -i 's/disable=0/disable=1/g' /etc/lxdm/default.conf
98
99
100wget -O onos.png "https://gerrit.onosproject.org/gitweb?p=onos-vm.git;a=blob_plain;hb=refs/heads/onos-tutorial;f=onos.png"
101sudo cp onos.png /usr/share/backgrounds/default.png
102
103# Automatically start LXDE on login
104echo '[[ -z $DISPLAY && $XDG_VTNR -eq 1 ]] && exec startx' >> ~/.bashrc
105
106# Automatically log into the VM
107#sudo sed -i 's/exec /sbin/getty -8 38400 tty1//g' /etc/init/tty1.conf
108#sudo sed -i '$ d' /etc/init/tty1.conf
109#echo 'exec /bin/login -f bob < /dev/tty1 > /dev/tty1 2>&1' | sudo tee -a /etc/init/tty1.conf
110
111# Disable screensaver
112sudo sed -i '/screensaver/d' /etc/xdg/lxsession/LXDE/autostart
113cat > ${USER_HOME}/.xsessionrc << EOF
114# disable screensaver
115xset s off
116# disable dpms (standby)
117xset -dpms
118EOF
119
120# Change LXTerminal default colors
121#sudo sed -i 's/bgcolor=#000000000000/bgcolor=#ffffffffffff/g' ${USER_HOME}/.config/lxterminal/lxterminal.conf
122#sudo sed -i 's/fgcolor=#aaaaaaaaaaaa/fgcolor=#000000000000/g' ${USER_HOME}/.config/lxterminal/lxterminal.conf
123sudo sed -i 's/bgcolor=#000000000000/bgcolor=#ffffffffffff/g' /usr/share/lxterminal/lxterminal.conf
124sudo sed -i 's/fgcolor=#aaaaaaaaaaaa/fgcolor=#000000000000/g' /usr/share/lxterminal/lxterminal.conf
125
126DESKTOP=${USER_HOME}/Desktop
127
128mkdir -p ${DESKTOP}
129
130cat > ${DESKTOP}/Mininet << EOF
131[Desktop Entry]
132Encoding=UTF-8
133Type=Application
134Name=Mininet
135Name[en_US]=Mininet
136Icon=konsole
137Exec=/usr/bin/lxterminal -e 'sudo mn --custom /home/tutorial1/onos/tools/test/topos/tower.py --topo tower --controller remote --mac'
138Comment[en_US]=
139EOF
140
141cat > ${DESKTOP}/Tutorial << EOF
142[Desktop Entry]
143Encoding=UTF-8
144Type=Application
145Name=ONOS Tutorial
146Name[en_US]=ONOS Tutorial
147Icon=internet-web-browser
148Exec=/usr/bin/chromium-browser https://wiki.onosproject.org/display/ONOS/Distributed+ONOS+Tutorial
149Comment[en_US]=
150EOF
151
152cat > ${DESKTOP}/GUI << EOF
153[Desktop Entry]
154Encoding=UTF-8
155Type=Application
156Name=ONOS GUI
157Name[en_US]=ONOS GUI
158Icon=internet-web-browser
159Exec=/usr/bin/chromium-browser http://localhost:8181/onos/ui/index.html#topo
160Comment[en_US]=
161EOF
162
163cat > ${DESKTOP}/Wireshark << EOF
164[Desktop Entry]
165Encoding=UTF-8
166Type=Application
167Name=Wireshark
168Name[en_US]=Wireshark
169Icon=wireshark
170Exec=/usr/bin/wireshark
171Comment[en_US]=
172EOF
173
174cat > ${DESKTOP}/Reset << EOF
175[Desktop Entry]
176Encoding=UTF-8
177Type=Application
178Name=Reset
179Name[en_US]=Reset
180Icon=konsole
181Exec=/usr/bin/lxterminal -t 'Resetting; please wait' -e 'sudo service onos restart'
182Comment[en_US]=
183EOF
184
185# ------------- Install Other Tools -------------
186sudo apt-get install -y wireshark
187# Enable root-less wireshark and add mininet
188echo "Enabling wireshark group"
189echo "wireshark-common wireshark-common/install-setuid boolean true" | sudo debconf-set-selections
190sudo dpkg-reconfigure -f noninteractive wireshark-common
191sudo usermod -a -G wireshark mininet
192sudo usermod -a -G wireshark tutorial1
193
194
195echo "Installing VirtualBox Guest Additions"
196sudo apt-get install -y virtualbox-guest-x11
197
198# ------------- Zero Unused Blocks -------------
199#TODO investigate zerofree
200echo "Zeroing unused blocks"
201sync
202dd if=/dev/zero of=tmp-zeros
203sync
204rm tmp-zeros
205sync