blob: 7e105e356d73f4e478980ce4dcbcdf4b3dced2cd [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
160export ONOS_ROOT=/home/mininet/onos
Jonathan Hart59c036f2015-04-01 16:33:33 -0700161export M2_REPO=/home/mininet/.m2/repository
162export KARAF_TAR=/home/mininet/apache-karaf-3.0.2.tar.gz
Jonathan Hart6ccaec82015-04-01 14:43:40 -0700163. ${ONOS_ROOT}/tools/dev/bash_profile
164. ${ONOS_ROOT}/tools/build/envDefaults
165
166cell 3node
167onos-service --cell stop
168cell 1node
169onos-package
Jonathan Hart59c036f2015-04-01 16:33:33 -0700170onos-install -f '$OC1'
Jonathan Hart6ccaec82015-04-01 14:43:40 -0700171EOF
172
Jonathan Hart59c036f2015-04-01 16:33:33 -0700173sudo chmod 777 ${USER_HOME}/reset-to-1.sh
174
Jonathan Hart6ccaec82015-04-01 14:43:40 -0700175cat << EOF >> ${USER_HOME}/reset-to-3.sh
176#!/bin/bash
177export ONOS_ROOT=/home/mininet/onos
Jonathan Hart59c036f2015-04-01 16:33:33 -0700178export M2_REPO=/home/mininet/.m2/repository
179export KARAF_TAR=/home/mininet/apache-karaf-3.0.2.tar.gz
Jonathan Hart6ccaec82015-04-01 14:43:40 -0700180. ${ONOS_ROOT}/tools/dev/bash_profile
181. ${ONOS_ROOT}/tools/build/envDefaults
182
183cell 3node
184onos-service --cell stop
185onos-package
Jonathan Hart59c036f2015-04-01 16:33:33 -0700186onos-install -f '$OC1'
187onos-install -f '$OC2'
188onos-install -f '$OC3'
Jonathan Hart6ccaec82015-04-01 14:43:40 -0700189EOF
190
Jonathan Hart59c036f2015-04-01 16:33:33 -0700191sudo chmod 777 ${USER_HOME}/reset-to-3.sh
192
Jonathan Hartb1e22112015-03-31 16:42:03 -0700193# ------------- Set up each tutorial -------------
194
195create_user tutorial1 "Basic ONOS Tutorial"
Jonathan Hartf5a22f42015-03-31 17:44:40 -0700196
197URL='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 -0700198wget -O tutorial1-setup-lxc.sh $URL
Jonathan Harta6348c42015-03-31 18:38:44 -0700199sudo -u tutorial1 -H sh -c 'cp tutorial1-setup-lxc.sh ~/ && cd ~/ && sh tutorial1-setup-lxc.sh'
Jonathan Hart97b81212015-03-27 11:19:22 -0700200
Jonathan Hartd8609332015-04-01 11:16:33 -0700201create_user sdnip "SDN-IP Tutorial"
Jonathan Hart6ccaec82015-04-01 14:43:40 -0700202
203SDNIP_URL='https://gerrit.onosproject.org/gitweb?p=onos-vm.git;a=blob_plain;hb=refs/heads/new-onos-tutorial;f=sdnip-setup-lxc.sh'
204wget -O sdnip-setup-lxc.sh $SDNIP_URL
Jonathan Hart59c036f2015-04-01 16:33:33 -0700205sudo -u sdnip -H sh -c 'cp sdnip-setup-lxc.sh ~/ && cd ~/ && sh sdnip-setup-lxc.sh'
Jonathan Hart6ccaec82015-04-01 14:43:40 -0700206
Jonathan Hartd8609332015-04-01 11:16:33 -0700207create_user distributed "Distributed Tutorial"
Jonathan Hart59c036f2015-04-01 16:33:33 -0700208
209DIST_URL='https://gerrit.onosproject.org/gitweb?p=onos-vm.git;a=blob_plain;hb=refs/heads/new-onos-tutorial;f=dist-setup-lxc.sh'
210wget -O dist-setup-lxc.sh $DIST_URL
211sudo -u distributed -H sh -c 'cp dist-setup-lxc.sh ~/ && cd ~/ && sh dist-setup-lxc.sh'
212
Jonathan Hartd8609332015-04-01 11:16:33 -0700213create_user optical "Optical Tutorial"
214
Jonathan Hart59c036f2015-04-01 16:33:33 -0700215OPT_URL='https://gerrit.onosproject.org/gitweb?p=onos-vm.git;a=blob_plain;hb=refs/heads/new-onos-tutorial;f=opt-setup-lxc.sh'
216wget -O opt-setup.sh $OPT_URL
217sudo -u optical -H sh -c 'cp opt-setup-lxc.sh ~/ && cd ~/ && sh opt-setup-lxc.sh'
218
Jonathan Hart97b81212015-03-27 11:19:22 -0700219# ------------- Zero Unused Blocks -------------
220#TODO investigate zerofree
Jonathan Hart6ccaec82015-04-01 14:43:40 -0700221echo "Zeroing unused blocks"
222sync
223dd if=/dev/zero of=tmp-zeros
224sync
225rm tmp-zeros
226sync