blob: 8dde99d22bb263eb0287668f800596414ebadf6d [file] [log] [blame]
Luca Prete8137ffc2016-08-16 11:53:45 -07001#!/bin/bash
2# onos-setup.sh
3#
4# Runs as mininet user.
5#
6# This script sets up the desktop environment, installs ONOS in the LXC cluster,
7# then creates a user for each tutorial and runs the tutorial setup script.
8
9function create_user {
10 local name=$1
11 local description=$2
12
13 sudo /usr/sbin/useradd -c "$description" -d /home/$name -U -m -p $(openssl passwd -1 $name) -s /bin/bash $name
14 echo "$name ALL=(ALL) NOPASSWD:ALL" >> $name
15 sudo mv $name /etc/sudoers.d
16 sudo chown root:root /etc/sudoers.d/$name
17 sudo usermod -aG wireshark $name
18
19 sudo usermod -aG mininet $name
20
21 sudo mkdir /home/$name/.ssh
22 sudo chown $name:$name /home/$name/.ssh
23 sudo cp /home/mininet/.ssh/id_rsa /home/$name/.ssh/
24 sudo chown $name:$name /home/$name/.ssh/id_rsa
25
26 sudo -u $name sh -c "echo \"export ONOS_ROOT=/home/mininet/onos\" >> /home/$name/.bashrc"
27 sudo -u $name sh -c "echo \"export KARAF_ROOT=/home/mininet/apache-karaf-3.0.5\" >> /home/$name/.bashrc"
28 sudo -u $name sh -c "echo \"export M2_REPO=/home/mininet/.m2/repository\" >> /home/$name/.bashrc"
29 sudo -u $name sh -c "echo \". /home/mininet/onos/tools/dev/bash_profile\" >> /home/$name/.bashrc"
30
31 sudo -u $name ssh -o "StrictHostKeyChecking no" sdn@10.0.3.11 ls
32 sudo -u $name ssh -o "StrictHostKeyChecking no" sdn@10.0.3.12 ls
33 sudo -u $name ssh -o "StrictHostKeyChecking no" sdn@10.0.3.13 ls
34
35 sudo mkdir -p /home/$name/.wireshark/plugins
36 sudo cp /home/mininet/openflow.lua /home/$name/.wireshark/plugins
37 sudo chown -R $name:$name /home/$name/.wireshark
38}
39
40# ------------- Set up desktop environment -------------
41
42echo "Setting up desktop environment"
43
44# Remove kernel boot options that will prevent the gui from running
45sudo sed -i s/text// /etc/default/grub
46sudo sed -i s/ipv6.disable=1// /etc/default/grub
47sudo update-grub
48
49sudo apt-get install -y xorg lxde systemd-shim
50
51#TODO: add backgrounds folder
52sudo mkdir -p /usr/share/backgrounds
53#TODO: change background
54# Remove wallpaper, change background color
55sudo sed -i 's/wallpaper_mode=1/wallpaper_mode=0/g' /usr/share/lxde/pcmanfm/LXDE.conf
56sudo sed -i 's/desktop_bg=#000000/desktop_bg=#104187/g' /usr/share/lxde/pcmanfm/LXDE.conf
57
58sudo sed -i 's/lang=1/lang=0/g' /etc/lxdm/default.conf
59sudo sed -i 's/bottom_pane=1/bottom_pane=0/g' /etc/lxdm/default.conf
60sudo sed -i 's/disable=0/disable=1/g' /etc/lxdm/default.conf
61
62# Allow VM to be rebooted from GUI
63echo "session required pam_systemd.so" | sudo tee --append /etc/pam.d/lxdm
64
65wget -O onos.png "https://gerrit.onosproject.org/gitweb?p=onos-vm.git;a=blob_plain;hb=refs/heads/onos-tutorial-1.6;f=onos.png"
66sudo cp onos.png /usr/share/backgrounds/default.png
67
68# Change LXTerminal default colors
69sudo sed -i 's/bgcolor=#000000000000/bgcolor=#ffffffffffff/g' /usr/share/lxterminal/lxterminal.conf
70sudo sed -i 's/fgcolor=#aaaaaaaaaaaa/fgcolor=#000000000000/g' /usr/share/lxterminal/lxterminal.conf
71
72# Disable screensaver
73sudo sed -i '/screensaver/d' /etc/xdg/lxsession/LXDE/autostart
74cat > /home/mininet/.xsessionrc << EOF
75# disable screensaver
76xset s off
77# disable dpms (standby)
78xset -dpms
79EOF
80
81echo "Enabling non-root wireshark"
82echo "wireshark-common wireshark-common/install-setuid boolean true" | sudo debconf-set-selections
83sudo dpkg-reconfigure -f noninteractive wireshark-common
84
85# Get the wireshark dissector handy
86wget -O /home/mininet/openflow.lua "https://gerrit.onosproject.org/gitweb?p=onos-vm.git;a=blob_plain;hb=refs/heads/onos-tutorial-1.1;f=openflow.lua"
87
88# -------------- Install ONOS ----------------
89
90echo "Installing ONOS"
91
92USER=mininet
93USER_HOME=/home/${USER}
94
95cd ~
96
97# Download a local karaf so we can use the bin directory
98wget http://archive.apache.org/dist/karaf/3.0.5/apache-karaf-3.0.5.tar.gz
99tar -xzf apache-karaf-3.0.5.tar.gz
100
101
102git clone https://gerrit.onosproject.org/onos
103cd onos && git checkout 1.6.0 && cd -
104
105mkdir -p ~/Downloads
106
107
108echo "export ONOS_ROOT=${USER_HOME}/onos" >> ~/.bashrc
109echo "export KARAF_ROOT=${USER_HOME}/apache-karaf-3.0.5" >> ~/.bashrc
110echo ". ~/onos/tools/dev/bash_profile" >> ~/.bashrc
111
112export ONOS_ROOT=${USER_HOME}/onos
113export KARAF_ROOT=${USER_HOME}/apache-karaf-3.0.5
114. ~/onos/tools/dev/bash_profile
115
116
117echo $ONOS_ROOT
118
119cd $ONOS_ROOT && mvn clean install && mvn dependency:go-offline && cd -
120
121# Get the sample apps and build them for the right version
122git clone https://gerrit.onosproject.org/onos-app-samples
123cd onos-app-samples
124git checkout 52da58b5991049025ce1b599c000357500b00aef
125mvn versions:set -DnewVersion=1.2.1 versions:commit
126mvn clean install
127cd ..
128
129
130cat << EOF >> onos/tools/test/cells/3node
131export ONOS_NIC=10.0.3.*
132export OC1="10.0.3.11"
133export OC2="10.0.3.12"
134export OC3="10.0.3.13"
135export OCI="10.0.3.11"
136export ONOS_APPS="drivers,openflow"
137export ONOS_USER="sdn"
138EOF
139
140cat << EOF >> onos/tools/test/cells/1node
141export ONOS_NIC=10.0.3.*
142export OC1="10.0.3.11"
143export OCI="10.0.3.11"
144export ONOS_APPS="drivers,openflow"
145export ONOS_USER="sdn"
146EOF
147
148cell 3node
149
150
151onos-package
152onos-group install -f
153onos-wait-for-start $OC1
154onos-wait-for-start $OC2
155onos-wait-for-start $OC3
156
157echo "ONOS install and startup complete"
158
159sleep 1
160onos-service --cell status
161
162# Prevent ONOS services from starting automatically
163sudo sh -c "echo manual >> /var/lib/lxc/onos1/rootfs/etc/init/onos.override"
164sudo sh -c "echo manual >> /var/lib/lxc/onos2/rootfs/etc/init/onos.override"
165sudo sh -c "echo manual >> /var/lib/lxc/onos3/rootfs/etc/init/onos.override"
166
167# ------------- Create reset scripts -------------
168
169cat << EOF >> ${USER_HOME}/reset-to-1.sh
170#!/bin/bash
171sudo rm -rf /tmp/*
172export ONOS_ROOT=/home/mininet/onos
173export M2_REPO=/home/mininet/.m2/repository
174export KARAF_TAR=/home/mininet/apache-karaf-3.0.5.tar.gz
175. ${ONOS_ROOT}/tools/dev/bash_profile
176. ${ONOS_ROOT}/tools/build/envDefaults
177
178sudo mn -c
179
180cell 3node
181onos-service --cell stop
182cell 1node
183
184if [ -n "\$1" ]; then
185 export ONOS_APPS=\$ONOS_APPS,\$1
186fi
187
188onos-package
189onos-install -f '$OC1'
190EOF
191
192sudo chmod 777 ${USER_HOME}/reset-to-1.sh
193
194cat << EOF >> ${USER_HOME}/reset-to-3.sh
195#!/bin/bash
196sudo rm -rf /tmp/*
197export ONOS_ROOT=/home/mininet/onos
198export M2_REPO=/home/mininet/.m2/repository
199export KARAF_TAR=/home/mininet/apache-karaf-3.0.5.tar.gz
200. ${ONOS_ROOT}/tools/dev/bash_profile
201. ${ONOS_ROOT}/tools/build/envDefaults
202
203sudo mn -c
204
205cell 3node
206
207if [ -n "\$1" ]; then
208 export ONOS_APPS=\$ONOS_APPS,\$1
209fi
210
211onos-service --cell stop
212onos-package
213onos-install -f '$OC1'
214onos-install -f '$OC2'
215onos-install -f '$OC3'
216EOF
217
218sudo chmod 777 ${USER_HOME}/reset-to-3.sh
219
220sudo apt-get clean
221sudo rm /etc/apt/apt.conf.d/02proxy
222
223# ------------- Set up each tutorial -------------
224
225create_user tutorial1 "Basic ONOS Tutorial"
226
227URL='https://gerrit.onosproject.org/gitweb?p=onos-vm.git;a=blob_plain;hb=refs/heads/onos-tutorial-1.6;f=tutorial1-setup.sh'
228wget -O tutorial1-setup.sh $URL
229sudo -u tutorial1 -H sh -c 'cp tutorial1-setup.sh ~/ && cd ~/ && sh tutorial1-setup.sh'
230
231create_user sdnip "SDN-IP Tutorial"
232
233SDNIP_URL='https://gerrit.onosproject.org/gitweb?p=onos-vm.git;a=blob_plain;hb=refs/heads/onos-tutorial-1.6;f=sdnip-setup.sh'
234wget -O sdnip-setup.sh $SDNIP_URL
235sudo -u sdnip -H sh -c 'cp sdnip-setup.sh ~/ && cd ~/ && sh sdnip-setup.sh'
236
237create_user distributed "Distributed Tutorial"
238
239DIST_URL='https://gerrit.onosproject.org/gitweb?p=onos-vm.git;a=blob_plain;hb=refs/heads/onos-tutorial-1.6;f=dist-setup.sh'
240wget -O dist-setup.sh $DIST_URL
241sudo -u distributed -H sh -c 'cp dist-setup.sh ~/ && cd ~/ && sh dist-setup.sh'
242
243create_user optical "Optical Tutorial"
244
245OPT_URL='https://gerrit.onosproject.org/gitweb?p=onos-vm.git;a=blob_plain;hb=refs/heads/onos-tutorial-1.1;f=opt-setup.sh'
246wget -O opt-setup.sh $OPT_URL
247sudo -u optical -H sh -c 'cp opt-setup.sh ~/ && cd ~/ && sh opt-setup.sh'
248
249# ------------- Zero Unused Blocks -------------
250#TODO investigate zerofree
251echo "Zeroing unused blocks"
252sync
253dd if=/dev/zero of=tmp-zeros
254sync
255rm tmp-zeros
256sync