blob: ee4abc34d0a9d8961e65de541a4eb34eb231eebb [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
54git clone https://gerrit.onosproject.org/onos
alshabib77b4f212014-12-09 00:30:54 -080055cd onos
alshabib247d2112014-12-09 00:25:53 -080056git checkout 1.0.0
alshabib77b4f212014-12-09 00:30:54 -080057cd -
alshabib48b63e12014-12-08 23:53:03 -080058
59echo ". ~/onos/tools/dev/bash_profile" >> ~/.bashrc
60echo "export ONOS_USER=root" >> ~/.bashrc
alshabibffbf45a2014-12-09 10:00:47 -080061
alshabib42beadc2014-12-09 00:01:26 -080062cat > onos/tools/test/cells/docker << EOF
63export ONOS_NIC="172.17.0.*"
alshabibffbf45a2014-12-09 10:00:47 -080064export OC1="\$(sudo docker inspect --format '{{ .NetworkSettings.IPAddress }}' onos-1)"
65export OC2="\$(sudo docker inspect --format '{{ .NetworkSettings.IPAddress }}' onos-2)"
66export OC3="\$(sudo docker inspect --format '{{ .NetworkSettings.IPAddress }}' onos-3)"
alshabib42beadc2014-12-09 00:01:26 -080067export OCN="localhost"
68export OCI="${OC1}"
69export ONOS_FEATURES="webconsole,onos-api,onos-core,onos-cli,onos-rest,onos-gui,onos-openflow,onos-app-fwd,onos-app-proxyarp,onos-app-mobility"
70EOF
71
alshabib4aa072d2014-12-10 20:59:34 -080072echo "cell docker > /dev/null 2&>1" >> ~/.bashrc
alshabib48b63e12014-12-08 23:53:03 -080073
74sed -i -e s/sdn/root/ onos/tools/package/debian/onos.conf
75
76cd onos && mvn clean install && cd -
alshabib42beadc2014-12-09 00:01:26 -080077
alshabibd1a096f2014-12-10 23:34:04 -080078#--------------- set up mininet script --------
79
80cat > ~/startmn.sh << EOF
81#!/bin/bash
82sudo python ~/onos/tools/test/topos/sol.py $OC1 $OC2 $OC3
83EOF
84
85chmod +x ~/startmn.sh
alshabib48b63e12014-12-08 23:53:03 -080086
87# -------------- Setup Wireshark dissector ----
88
89wget -O openflow.lua "https://gerrit.onosproject.org/gitweb?p=onos-vm.git;a=blob_plain;hb=refs/heads/onos-tutorial;f=openflow.lua"
90mkdir -p .wireshark/plugins
91mv openflow.lua .wireshark/plugins
92
93
94
95# -------------- Setup Desktop ----------------
96
97sudo apt-get install -y xorg lxde
98
99#TODO: add backgrounds folder
100sudo mkdir -p /usr/share/backgrounds
101#TODO: change background
102# Remove wallpaper, change background color
103sudo sed -i 's/wallpaper_mode=1/wallpaper_mode=0/g' /usr/share/lxde/pcmanfm/LXDE.conf
104sudo sed -i 's/desktop_bg=#000000/desktop_bg=#104187/g' /usr/share/lxde/pcmanfm/LXDE.conf
105
106sudo sed -i 's/lang=1/lang=0/g' /etc/lxdm/default.conf
107sudo sed -i 's/bottom_pane=1/bottom_pane=0/g' /etc/lxdm/default.conf
108sudo sed -i 's/disable=0/disable=1/g' /etc/lxdm/default.conf
109
110
111wget -O onos.png "https://gerrit.onosproject.org/gitweb?p=onos-vm.git;a=blob_plain;hb=refs/heads/onos-tutorial;f=onos.png"
112sudo cp onos.png /usr/share/backgrounds/default.png
113
114# Automatically start LXDE on login
115echo '[[ -z $DISPLAY && $XDG_VTNR -eq 1 ]] && exec startx' >> ~/.bashrc
116
117# Automatically log into the VM
118#sudo sed -i 's/exec /sbin/getty -8 38400 tty1//g' /etc/init/tty1.conf
119#sudo sed -i '$ d' /etc/init/tty1.conf
120#echo 'exec /bin/login -f bob < /dev/tty1 > /dev/tty1 2>&1' | sudo tee -a /etc/init/tty1.conf
121
122# Disable screensaver
123sudo sed -i '/screensaver/d' /etc/xdg/lxsession/LXDE/autostart
124cat > ${USER_HOME}/.xsessionrc << EOF
125# disable screensaver
126xset s off
127# disable dpms (standby)
128xset -dpms
129EOF
130
131# Change LXTerminal default colors
132#sudo sed -i 's/bgcolor=#000000000000/bgcolor=#ffffffffffff/g' ${USER_HOME}/.config/lxterminal/lxterminal.conf
133#sudo sed -i 's/fgcolor=#aaaaaaaaaaaa/fgcolor=#000000000000/g' ${USER_HOME}/.config/lxterminal/lxterminal.conf
134sudo sed -i 's/bgcolor=#000000000000/bgcolor=#ffffffffffff/g' /usr/share/lxterminal/lxterminal.conf
135sudo sed -i 's/fgcolor=#aaaaaaaaaaaa/fgcolor=#000000000000/g' /usr/share/lxterminal/lxterminal.conf
136
137DESKTOP=${USER_HOME}/Desktop
138
139mkdir -p ${DESKTOP}
140
alshabib4aa072d2014-12-10 20:59:34 -0800141cat > ${DESKTOP}/IntelliJ << EOF
alshabibffbf45a2014-12-09 10:00:47 -0800142[Desktop Entry]
143Encoding=UTF-8
144Type=Application
alshabib4aa072d2014-12-10 20:59:34 -0800145Name=IntelliJ
146Name[en_US]=IntelliJ
147Icon=/home/distributed/Applications/idea/bin/idea.png
148Exec=/home/distributed/Applications/idea/bin/idea.sh
alshabibffbf45a2014-12-09 10:00:47 -0800149Comment[en_US]=
150EOF
151
alshabib48b63e12014-12-08 23:53:03 -0800152cat > ${DESKTOP}/Tutorial << EOF
153[Desktop Entry]
154Encoding=UTF-8
155Type=Application
156Name=ONOS Tutorial
157Name[en_US]=ONOS Tutorial
158Icon=internet-web-browser
159Exec=/usr/bin/chromium-browser https://wiki.onosproject.org/display/ONOS/Distributed+ONOS+Tutorial
160Comment[en_US]=
161EOF
162
alshabib48b63e12014-12-08 23:53:03 -0800163
164cat > ${DESKTOP}/Wireshark << EOF
165[Desktop Entry]
166Encoding=UTF-8
167Type=Application
168Name=Wireshark
169Name[en_US]=Wireshark
170Icon=wireshark
171Exec=/usr/bin/wireshark
172Comment[en_US]=
173EOF
174
alshabib48b63e12014-12-08 23:53:03 -0800175# ------------- Install Other Tools -------------
176sudo apt-get install -y wireshark
177# Enable root-less wireshark and add mininet
178echo "Enabling wireshark group"
179echo "wireshark-common wireshark-common/install-setuid boolean true" | sudo debconf-set-selections
180sudo dpkg-reconfigure -f noninteractive wireshark-common
181sudo usermod -a -G wireshark mininet
182sudo usermod -a -G wireshark tutorial1
183
184
185echo "Installing VirtualBox Guest Additions"
186sudo apt-get install -y virtualbox-guest-x11
187
alshabibffbf45a2014-12-09 10:00:47 -0800188sudo apt-get install -y git-review
189
alshabib4aa072d2014-12-10 20:59:34 -0800190cd ~/Applications
191
192wget -c -N -O /tmp/idea.tar.gz ${IDEA_URL}
193tar xzf /tmp/idea.tar.gz
194sudo mv idea-IC-139.659.2 idea
195
196cd -
alshabibffbf45a2014-12-09 10:00:47 -0800197
alshabib48b63e12014-12-08 23:53:03 -0800198# ------------- Zero Unused Blocks -------------
199#TODO investigate zerofree
200echo "Zeroing unused blocks"
201sync
202dd if=/dev/zero of=tmp-zeros
203sync
204rm tmp-zeros
205sync