blob: 2a85853e4917b66ff5cc10b58d5eb8ba8e16ce22 [file] [log] [blame]
Jonathan Hart7b6cfef2015-03-27 10:09:38 -07001#!/bin/bash
2# onos-setup-lxc.sh
3#
4# This script sets up the VM ready to run ONOS and tutorials, including installing an LXC cluster
5# for ONOS to run in.
6
Jonathan Hartb1e22112015-03-31 16:42:03 -07007function create_user {
8 local name=$1
9 local description=$2
10
11 sudo /usr/sbin/useradd -c "$description" -d /home/$name -U -m -p $(openssl passwd -1 $name) -s /bin/bash $name
12 echo "$name ALL=(ALL) NOPASSWD:ALL" >> $name
13 sudo mv $name /etc/sudoers.d
14 sudo chown root:root /etc/sudoers.d/$name
15 sudo usermod -aG wireshark $name
16
17 sudo mkdir /home/$name/.ssh
18 sudo chown $name:$name /home/$name/.ssh
19 sudo cp /home/mininet/.ssh/id_rsa /home/$name/.ssh/
20 sudo chown $name:$name /home/$name/.ssh/id_rsa
21
22 sudo -u $name sh -c "echo \"export ONOS_ROOT=/home/mininet/onos\" >> /home/$name/.bashrc"
Jonathan Hartd8609332015-04-01 11:16:33 -070023 sudo -u $name sh -c "echo \"export KARAF_ROOT=/home/mininet/apache-karaf-3.0.2\" >> /home/$name/.bashrc"
24 sudo -u $name sh -c "echo \"export M2_REPO=/home/mininet/.m2/repository\" >> /home/$name/.bashrc"
Jonathan Hartb1e22112015-03-31 16:42:03 -070025 sudo -u $name sh -c "echo \". /home/mininet/onos/tools/dev/bash_profile\" >> /home/$name/.bashrc"
26
27 sudo -u $name ssh -o "StrictHostKeyChecking no" sdn@10.0.3.11 ls
28 sudo -u $name ssh -o "StrictHostKeyChecking no" sdn@10.0.3.12 ls
29 sudo -u $name ssh -o "StrictHostKeyChecking no" sdn@10.0.3.13 ls
Jonathan Hart6ccaec82015-04-01 14:43:40 -070030
31 sudo mkdir -p /home/$name/.wireshark/plugins
32 sudo cp /home/mininet/openflow.lua /home/$name/.wireshark/plugins
33 sudo chown -R $name:$name /home/$name/.wireshark
Jonathan Hartb1e22112015-03-31 16:42:03 -070034}
35
Jonathan Hartb1e22112015-03-31 16:42:03 -070036# ------------- Set up desktop environment -------------
37
Jonathan Hartd8609332015-04-01 11:16:33 -070038echo "Setting up desktop environment"
39
Jonathan Hartb1e22112015-03-31 16:42:03 -070040# Remove kernel boot options that will prevent the gui from running
41sudo sed -i s/text// /etc/default/grub
42sudo sed -i s/ipv6.disable=1// /etc/default/grub
43sudo update-grub
44
45sudo apt-get install -y xorg lxde systemd-shim
46
47#TODO: add backgrounds folder
48sudo mkdir -p /usr/share/backgrounds
49#TODO: change background
50# Remove wallpaper, change background color
51sudo sed -i 's/wallpaper_mode=1/wallpaper_mode=0/g' /usr/share/lxde/pcmanfm/LXDE.conf
52sudo sed -i 's/desktop_bg=#000000/desktop_bg=#104187/g' /usr/share/lxde/pcmanfm/LXDE.conf
53
54sudo sed -i 's/lang=1/lang=0/g' /etc/lxdm/default.conf
55sudo sed -i 's/bottom_pane=1/bottom_pane=0/g' /etc/lxdm/default.conf
56sudo sed -i 's/disable=0/disable=1/g' /etc/lxdm/default.conf
57
58# Allow VM to be rebooted from GUI
59echo "session required pam_systemd.so" | sudo tee --append /etc/pam.d/lxdm
60
61wget -O onos.png "https://gerrit.onosproject.org/gitweb?p=onos-vm.git;a=blob_plain;hb=refs/heads/onos-tutorial;f=onos.png"
62sudo cp onos.png /usr/share/backgrounds/default.png
63
64# Change LXTerminal default colors
65sudo sed -i 's/bgcolor=#000000000000/bgcolor=#ffffffffffff/g' /usr/share/lxterminal/lxterminal.conf
66sudo sed -i 's/fgcolor=#aaaaaaaaaaaa/fgcolor=#000000000000/g' /usr/share/lxterminal/lxterminal.conf
67
68# Disable screensaver
69sudo sed -i '/screensaver/d' /etc/xdg/lxsession/LXDE/autostart
70cat > /home/mininet/.xsessionrc << EOF
71# disable screensaver
72xset s off
73# disable dpms (standby)
74xset -dpms
75EOF
76
Jonathan Hartd8609332015-04-01 11:16:33 -070077echo "Enabling non-root wireshark"
78echo "wireshark-common wireshark-common/install-setuid boolean true" | sudo debconf-set-selections
79sudo dpkg-reconfigure -f noninteractive wireshark-common
Jonathan Hartf5a22f42015-03-31 17:44:40 -070080
Jonathan Hart6ccaec82015-04-01 14:43:40 -070081# Get the wireshark dissector handy
82wget -O /home/mininet/openflow.lua "https://gerrit.onosproject.org/gitweb?p=onos-vm.git;a=blob_plain;hb=refs/heads/new-onos-tutorial;f=openflow.lua"
83
Jonathan Hartf5a22f42015-03-31 17:44:40 -070084# -------------- Install ONOS ----------------
85
Jonathan Hartd8609332015-04-01 11:16:33 -070086echo "Installing ONOS"
87
Jonathan Hartf5a22f42015-03-31 17:44:40 -070088USER=mininet
89USER_HOME=/home/${USER}
90
Jonathan Hartf5a22f42015-03-31 17:44:40 -070091cd ~
Jonathan Hartd8609332015-04-01 11:16:33 -070092
93# Download a local karaf so we can use the bin directory
94wget http://archive.apache.org/dist/karaf/3.0.2/apache-karaf-3.0.2.tar.gz
95tar -xzf apache-karaf-3.0.2.tar.gz
96
97
Jonathan Hartf5a22f42015-03-31 17:44:40 -070098git clone https://gerrit.onosproject.org/onos
99cd onos && git checkout onos-1.1 && cd -
100
101mkdir -p ~/Downloads
102
Jonathan Hartf5a22f42015-03-31 17:44:40 -0700103
104echo "export ONOS_ROOT=${USER_HOME}/onos" >> ~/.bashrc
Jonathan Hartd8609332015-04-01 11:16:33 -0700105echo "export KARAF_ROOT=${USER_HOME}/apache-karaf-3.0.2" >> ~/.bashrc
Jonathan Hartf5a22f42015-03-31 17:44:40 -0700106echo ". ~/onos/tools/dev/bash_profile" >> ~/.bashrc
107
108export ONOS_ROOT=${USER_HOME}/onos
Jonathan Hartd8609332015-04-01 11:16:33 -0700109export KARAF_ROOT=${USER_HOME}/apache-karaf-3.0.2
Jonathan Hartf5a22f42015-03-31 17:44:40 -0700110. ~/onos/tools/dev/bash_profile
111
Jonathan Hartf5a22f42015-03-31 17:44:40 -0700112
113echo $ONOS_ROOT
114
115echo $JAVA_HOME
116export JAVA_HOME=""
117cd $ONOS_ROOT && mvn clean install && mvn dependency:go-offline && cd -
118
119cat << EOF >> onos/tools/test/cells/3node
120export ONOS_NIC=10.0.3.*
121export OC1="10.0.3.11"
122export OC2="10.0.3.12"
123export OC3="10.0.3.13"
Jonathan Hart59c036f2015-04-01 16:33:33 -0700124export OCI="10.0.3.11"
Jonathan Hartf5a22f42015-03-31 17:44:40 -0700125export ONOS_FEATURES="webconsole,onos-rest,onos-gui,onos-api,onos-core,onos-cli,onos-openflow"
126export ONOS_USER="sdn"
127EOF
128
129cat << EOF >> onos/tools/test/cells/1node
130export ONOS_NIC=10.0.3.*
131export OC1="10.0.3.11"
Jonathan Hart59c036f2015-04-01 16:33:33 -0700132export OCI="10.0.3.11"
Jonathan Hartf5a22f42015-03-31 17:44:40 -0700133export ONOS_FEATURES="webconsole,onos-rest,onos-gui,onos-api,onos-core,onos-cli,onos-openflow"
134export ONOS_USER="sdn"
135EOF
136
137cell 3node
138
Jonathan Hartf5a22f42015-03-31 17:44:40 -0700139
140onos-package
141onos-group install -f
142onos-wait-for-start $OC1
143onos-wait-for-start $OC2
144onos-wait-for-start $OC3
145
Jonathan Hartd8609332015-04-01 11:16:33 -0700146echo "ONOS install and startup complete"
147
148sleep 1
Jonathan Hartf5a22f42015-03-31 17:44:40 -0700149onos-service --cell status
150
Jonathan Hartd8609332015-04-01 11:16:33 -0700151# Prevent ONOS services from starting automatically
152sudo sh -c "echo manual >> /var/lib/lxc/onos1/rootfs/etc/init/onos.override"
153sudo sh -c "echo manual >> /var/lib/lxc/onos2/rootfs/etc/init/onos.override"
154sudo sh -c "echo manual >> /var/lib/lxc/onos3/rootfs/etc/init/onos.override"
Jonathan Hartf5a22f42015-03-31 17:44:40 -0700155
Jonathan Hart6ccaec82015-04-01 14:43:40 -0700156# ------------- Create reset scripts -------------
157
158cat << EOF >> ${USER_HOME}/reset-to-1.sh
159#!/bin/bash
Jonathan Hart6b051d92015-04-01 17:04:35 -0700160sudo rm -rf /tmp/*
Jonathan Hart6ccaec82015-04-01 14:43:40 -0700161export ONOS_ROOT=/home/mininet/onos
Jonathan Hart59c036f2015-04-01 16:33:33 -0700162export M2_REPO=/home/mininet/.m2/repository
163export KARAF_TAR=/home/mininet/apache-karaf-3.0.2.tar.gz
Jonathan Hart6ccaec82015-04-01 14:43:40 -0700164. ${ONOS_ROOT}/tools/dev/bash_profile
165. ${ONOS_ROOT}/tools/build/envDefaults
166
Jonathan Hartf16c1222015-04-01 19:38:49 -0700167sudo mn -c
168
Jonathan Hart6ccaec82015-04-01 14:43:40 -0700169cell 3node
170onos-service --cell stop
171cell 1node
172onos-package
Jonathan Hart59c036f2015-04-01 16:33:33 -0700173onos-install -f '$OC1'
Jonathan Hart6ccaec82015-04-01 14:43:40 -0700174EOF
175
Jonathan Hart59c036f2015-04-01 16:33:33 -0700176sudo chmod 777 ${USER_HOME}/reset-to-1.sh
177
Jonathan Hart6ccaec82015-04-01 14:43:40 -0700178cat << EOF >> ${USER_HOME}/reset-to-3.sh
179#!/bin/bash
Jonathan Hart6b051d92015-04-01 17:04:35 -0700180sudo rm -rf /tmp/*
Jonathan Hart6ccaec82015-04-01 14:43:40 -0700181export ONOS_ROOT=/home/mininet/onos
Jonathan Hart59c036f2015-04-01 16:33:33 -0700182export M2_REPO=/home/mininet/.m2/repository
183export KARAF_TAR=/home/mininet/apache-karaf-3.0.2.tar.gz
Jonathan Hart6ccaec82015-04-01 14:43:40 -0700184. ${ONOS_ROOT}/tools/dev/bash_profile
185. ${ONOS_ROOT}/tools/build/envDefaults
186
Jonathan Hartf16c1222015-04-01 19:38:49 -0700187sudo mn -c
188
Jonathan Hart6ccaec82015-04-01 14:43:40 -0700189cell 3node
190onos-service --cell stop
191onos-package
Jonathan Hart59c036f2015-04-01 16:33:33 -0700192onos-install -f '$OC1'
193onos-install -f '$OC2'
194onos-install -f '$OC3'
Jonathan Hart6ccaec82015-04-01 14:43:40 -0700195EOF
196
Jonathan Hart59c036f2015-04-01 16:33:33 -0700197sudo chmod 777 ${USER_HOME}/reset-to-3.sh
198
Jonathan Hartb1e22112015-03-31 16:42:03 -0700199# ------------- Set up each tutorial -------------
200
201create_user tutorial1 "Basic ONOS Tutorial"
Jonathan Hartf5a22f42015-03-31 17:44:40 -0700202
203URL='https://gerrit.onosproject.org/gitweb?p=onos-vm.git;a=blob_plain;hb=refs/heads/new-onos-tutorial;f=tutorial1-setup-lxc.sh'
Jonathan Hartb1e22112015-03-31 16:42:03 -0700204wget -O tutorial1-setup-lxc.sh $URL
Jonathan Harta6348c42015-03-31 18:38:44 -0700205sudo -u tutorial1 -H sh -c 'cp tutorial1-setup-lxc.sh ~/ && cd ~/ && sh tutorial1-setup-lxc.sh'
Jonathan Hart97b81212015-03-27 11:19:22 -0700206
Jonathan Hartd8609332015-04-01 11:16:33 -0700207create_user sdnip "SDN-IP Tutorial"
Jonathan Hart6ccaec82015-04-01 14:43:40 -0700208
209SDNIP_URL='https://gerrit.onosproject.org/gitweb?p=onos-vm.git;a=blob_plain;hb=refs/heads/new-onos-tutorial;f=sdnip-setup-lxc.sh'
210wget -O sdnip-setup-lxc.sh $SDNIP_URL
Jonathan Hart59c036f2015-04-01 16:33:33 -0700211sudo -u sdnip -H sh -c 'cp sdnip-setup-lxc.sh ~/ && cd ~/ && sh sdnip-setup-lxc.sh'
Jonathan Hart6ccaec82015-04-01 14:43:40 -0700212
Jonathan Hartd8609332015-04-01 11:16:33 -0700213create_user distributed "Distributed Tutorial"
Jonathan Hart59c036f2015-04-01 16:33:33 -0700214
215DIST_URL='https://gerrit.onosproject.org/gitweb?p=onos-vm.git;a=blob_plain;hb=refs/heads/new-onos-tutorial;f=dist-setup-lxc.sh'
216wget -O dist-setup-lxc.sh $DIST_URL
217sudo -u distributed -H sh -c 'cp dist-setup-lxc.sh ~/ && cd ~/ && sh dist-setup-lxc.sh'
218
Jonathan Hartd8609332015-04-01 11:16:33 -0700219create_user optical "Optical Tutorial"
220
Jonathan Hart59c036f2015-04-01 16:33:33 -0700221OPT_URL='https://gerrit.onosproject.org/gitweb?p=onos-vm.git;a=blob_plain;hb=refs/heads/new-onos-tutorial;f=opt-setup-lxc.sh'
Jonathan Hartf16c1222015-04-01 19:38:49 -0700222wget -O opt-setup-lxc.sh $OPT_URL
Jonathan Hart59c036f2015-04-01 16:33:33 -0700223sudo -u optical -H sh -c 'cp opt-setup-lxc.sh ~/ && cd ~/ && sh opt-setup-lxc.sh'
224
Jonathan Hart97b81212015-03-27 11:19:22 -0700225# ------------- Zero Unused Blocks -------------
226#TODO investigate zerofree
Jonathan Hart6ccaec82015-04-01 14:43:40 -0700227echo "Zeroing unused blocks"
228sync
229dd if=/dev/zero of=tmp-zeros
230sync
231rm tmp-zeros
232sync