blob: 82954a18e26f37cd044b9919b117c927adf00d43 [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
54
55sed -i -e s/sdn/root/ onos/tools/package/debian/onos.conf
56
57cd onos && mvn clean install && cd -
58
59# -------------- Setup Wireshark dissector ----
60
61wget -O openflow.lua "https://gerrit.onosproject.org/gitweb?p=onos-vm.git;a=blob_plain;hb=refs/heads/onos-tutorial;f=openflow.lua"
62mkdir -p .wireshark/plugins
63mv openflow.lua .wireshark/plugins
64
65
66
67# -------------- Setup Desktop ----------------
68
69sudo apt-get install -y xorg lxde
70
71#TODO: add backgrounds folder
72sudo mkdir -p /usr/share/backgrounds
73#TODO: change background
74# Remove wallpaper, change background color
75sudo sed -i 's/wallpaper_mode=1/wallpaper_mode=0/g' /usr/share/lxde/pcmanfm/LXDE.conf
76sudo sed -i 's/desktop_bg=#000000/desktop_bg=#104187/g' /usr/share/lxde/pcmanfm/LXDE.conf
77
78sudo sed -i 's/lang=1/lang=0/g' /etc/lxdm/default.conf
79sudo sed -i 's/bottom_pane=1/bottom_pane=0/g' /etc/lxdm/default.conf
80sudo sed -i 's/disable=0/disable=1/g' /etc/lxdm/default.conf
81
82
83wget -O onos.png "https://gerrit.onosproject.org/gitweb?p=onos-vm.git;a=blob_plain;hb=refs/heads/onos-tutorial;f=onos.png"
84sudo cp onos.png /usr/share/backgrounds/default.png
85
86# Automatically start LXDE on login
87echo '[[ -z $DISPLAY && $XDG_VTNR -eq 1 ]] && exec startx' >> ~/.bashrc
88
89# Automatically log into the VM
90#sudo sed -i 's/exec /sbin/getty -8 38400 tty1//g' /etc/init/tty1.conf
91#sudo sed -i '$ d' /etc/init/tty1.conf
92#echo 'exec /bin/login -f bob < /dev/tty1 > /dev/tty1 2>&1' | sudo tee -a /etc/init/tty1.conf
93
94# Disable screensaver
95sudo sed -i '/screensaver/d' /etc/xdg/lxsession/LXDE/autostart
96cat > ${USER_HOME}/.xsessionrc << EOF
97# disable screensaver
98xset s off
99# disable dpms (standby)
100xset -dpms
101EOF
102
103# Change LXTerminal default colors
104#sudo sed -i 's/bgcolor=#000000000000/bgcolor=#ffffffffffff/g' ${USER_HOME}/.config/lxterminal/lxterminal.conf
105#sudo sed -i 's/fgcolor=#aaaaaaaaaaaa/fgcolor=#000000000000/g' ${USER_HOME}/.config/lxterminal/lxterminal.conf
106sudo sed -i 's/bgcolor=#000000000000/bgcolor=#ffffffffffff/g' /usr/share/lxterminal/lxterminal.conf
107sudo sed -i 's/fgcolor=#aaaaaaaaaaaa/fgcolor=#000000000000/g' /usr/share/lxterminal/lxterminal.conf
108
109DESKTOP=${USER_HOME}/Desktop
110
111mkdir -p ${DESKTOP}
112
113cat > ${DESKTOP}/Mininet << EOF
114[Desktop Entry]
115Encoding=UTF-8
116Type=Application
117Name=Mininet
118Name[en_US]=Mininet
119Icon=konsole
120Exec=/usr/bin/lxterminal -e 'sudo mn --custom /home/tutorial1/onos/tools/test/topos/tower.py --topo tower --controller remote --mac'
121Comment[en_US]=
122EOF
123
124cat > ${DESKTOP}/Tutorial << EOF
125[Desktop Entry]
126Encoding=UTF-8
127Type=Application
128Name=ONOS Tutorial
129Name[en_US]=ONOS Tutorial
130Icon=internet-web-browser
131Exec=/usr/bin/chromium-browser https://wiki.onosproject.org/display/ONOS/Distributed+ONOS+Tutorial
132Comment[en_US]=
133EOF
134
135cat > ${DESKTOP}/GUI << EOF
136[Desktop Entry]
137Encoding=UTF-8
138Type=Application
139Name=ONOS GUI
140Name[en_US]=ONOS GUI
141Icon=internet-web-browser
142Exec=/usr/bin/chromium-browser http://localhost:8181/onos/ui/index.html#topo
143Comment[en_US]=
144EOF
145
146cat > ${DESKTOP}/Wireshark << EOF
147[Desktop Entry]
148Encoding=UTF-8
149Type=Application
150Name=Wireshark
151Name[en_US]=Wireshark
152Icon=wireshark
153Exec=/usr/bin/wireshark
154Comment[en_US]=
155EOF
156
157cat > ${DESKTOP}/Reset << EOF
158[Desktop Entry]
159Encoding=UTF-8
160Type=Application
161Name=Reset
162Name[en_US]=Reset
163Icon=konsole
164Exec=/usr/bin/lxterminal -t 'Resetting; please wait' -e 'sudo service onos restart'
165Comment[en_US]=
166EOF
167
168# ------------- Install Other Tools -------------
169sudo apt-get install -y wireshark
170# Enable root-less wireshark and add mininet
171echo "Enabling wireshark group"
172echo "wireshark-common wireshark-common/install-setuid boolean true" | sudo debconf-set-selections
173sudo dpkg-reconfigure -f noninteractive wireshark-common
174sudo usermod -a -G wireshark mininet
175sudo usermod -a -G wireshark tutorial1
176
177
178echo "Installing VirtualBox Guest Additions"
179sudo apt-get install -y virtualbox-guest-x11
180
181# ------------- Zero Unused Blocks -------------
182#TODO investigate zerofree
183echo "Zeroing unused blocks"
184sync
185dd if=/dev/zero of=tmp-zeros
186sync
187rm tmp-zeros
188sync