blob: e5471a0d70213acc4167063b3cb53f720da7daa2 [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
30}
31
Jonathan Hartb1e22112015-03-31 16:42:03 -070032# ------------- Set up desktop environment -------------
33
Jonathan Hartd8609332015-04-01 11:16:33 -070034echo "Setting up desktop environment"
35
Jonathan Hartb1e22112015-03-31 16:42:03 -070036# Remove kernel boot options that will prevent the gui from running
37sudo sed -i s/text// /etc/default/grub
38sudo sed -i s/ipv6.disable=1// /etc/default/grub
39sudo update-grub
40
41sudo apt-get install -y xorg lxde systemd-shim
42
43#TODO: add backgrounds folder
44sudo mkdir -p /usr/share/backgrounds
45#TODO: change background
46# Remove wallpaper, change background color
47sudo sed -i 's/wallpaper_mode=1/wallpaper_mode=0/g' /usr/share/lxde/pcmanfm/LXDE.conf
48sudo sed -i 's/desktop_bg=#000000/desktop_bg=#104187/g' /usr/share/lxde/pcmanfm/LXDE.conf
49
50sudo sed -i 's/lang=1/lang=0/g' /etc/lxdm/default.conf
51sudo sed -i 's/bottom_pane=1/bottom_pane=0/g' /etc/lxdm/default.conf
52sudo sed -i 's/disable=0/disable=1/g' /etc/lxdm/default.conf
53
54# Allow VM to be rebooted from GUI
55echo "session required pam_systemd.so" | sudo tee --append /etc/pam.d/lxdm
56
57wget -O onos.png "https://gerrit.onosproject.org/gitweb?p=onos-vm.git;a=blob_plain;hb=refs/heads/onos-tutorial;f=onos.png"
58sudo cp onos.png /usr/share/backgrounds/default.png
59
60# Change LXTerminal default colors
61sudo sed -i 's/bgcolor=#000000000000/bgcolor=#ffffffffffff/g' /usr/share/lxterminal/lxterminal.conf
62sudo sed -i 's/fgcolor=#aaaaaaaaaaaa/fgcolor=#000000000000/g' /usr/share/lxterminal/lxterminal.conf
63
64# Disable screensaver
65sudo sed -i '/screensaver/d' /etc/xdg/lxsession/LXDE/autostart
66cat > /home/mininet/.xsessionrc << EOF
67# disable screensaver
68xset s off
69# disable dpms (standby)
70xset -dpms
71EOF
72
Jonathan Hartd8609332015-04-01 11:16:33 -070073echo "Enabling non-root wireshark"
74echo "wireshark-common wireshark-common/install-setuid boolean true" | sudo debconf-set-selections
75sudo dpkg-reconfigure -f noninteractive wireshark-common
Jonathan Hartf5a22f42015-03-31 17:44:40 -070076
77# -------------- Install ONOS ----------------
78
Jonathan Hartd8609332015-04-01 11:16:33 -070079echo "Installing ONOS"
80
Jonathan Hartf5a22f42015-03-31 17:44:40 -070081USER=mininet
82USER_HOME=/home/${USER}
83
Jonathan Hartf5a22f42015-03-31 17:44:40 -070084cd ~
Jonathan Hartd8609332015-04-01 11:16:33 -070085
86# Download a local karaf so we can use the bin directory
87wget http://archive.apache.org/dist/karaf/3.0.2/apache-karaf-3.0.2.tar.gz
88tar -xzf apache-karaf-3.0.2.tar.gz
89
90
Jonathan Hartf5a22f42015-03-31 17:44:40 -070091git clone https://gerrit.onosproject.org/onos
92cd onos && git checkout onos-1.1 && cd -
93
94mkdir -p ~/Downloads
95
Jonathan Hartf5a22f42015-03-31 17:44:40 -070096
97echo "export ONOS_ROOT=${USER_HOME}/onos" >> ~/.bashrc
Jonathan Hartd8609332015-04-01 11:16:33 -070098echo "export KARAF_ROOT=${USER_HOME}/apache-karaf-3.0.2" >> ~/.bashrc
Jonathan Hartf5a22f42015-03-31 17:44:40 -070099echo ". ~/onos/tools/dev/bash_profile" >> ~/.bashrc
100
101export ONOS_ROOT=${USER_HOME}/onos
Jonathan Hartd8609332015-04-01 11:16:33 -0700102export KARAF_ROOT=${USER_HOME}/apache-karaf-3.0.2
Jonathan Hartf5a22f42015-03-31 17:44:40 -0700103. ~/onos/tools/dev/bash_profile
104
Jonathan Hartf5a22f42015-03-31 17:44:40 -0700105
106echo $ONOS_ROOT
107
108echo $JAVA_HOME
109export JAVA_HOME=""
110cd $ONOS_ROOT && mvn clean install && mvn dependency:go-offline && cd -
111
112cat << EOF >> onos/tools/test/cells/3node
113export ONOS_NIC=10.0.3.*
114export OC1="10.0.3.11"
115export OC2="10.0.3.12"
116export OC3="10.0.3.13"
117export OCI="${OC1}"
118export ONOS_FEATURES="webconsole,onos-rest,onos-gui,onos-api,onos-core,onos-cli,onos-openflow"
119export ONOS_USER="sdn"
120EOF
121
122cat << EOF >> onos/tools/test/cells/1node
123export ONOS_NIC=10.0.3.*
124export OC1="10.0.3.11"
125export OCI="${OC1}"
126export ONOS_FEATURES="webconsole,onos-rest,onos-gui,onos-api,onos-core,onos-cli,onos-openflow"
127export ONOS_USER="sdn"
128EOF
129
130cell 3node
131
Jonathan Hartf5a22f42015-03-31 17:44:40 -0700132
133onos-package
134onos-group install -f
135onos-wait-for-start $OC1
136onos-wait-for-start $OC2
137onos-wait-for-start $OC3
138
Jonathan Hartd8609332015-04-01 11:16:33 -0700139echo "ONOS install and startup complete"
140
141sleep 1
Jonathan Hartf5a22f42015-03-31 17:44:40 -0700142onos-service --cell status
143
Jonathan Hartd8609332015-04-01 11:16:33 -0700144# Prevent ONOS services from starting automatically
145sudo sh -c "echo manual >> /var/lib/lxc/onos1/rootfs/etc/init/onos.override"
146sudo sh -c "echo manual >> /var/lib/lxc/onos2/rootfs/etc/init/onos.override"
147sudo sh -c "echo manual >> /var/lib/lxc/onos3/rootfs/etc/init/onos.override"
Jonathan Hartf5a22f42015-03-31 17:44:40 -0700148
Jonathan Hartb1e22112015-03-31 16:42:03 -0700149# ------------- Set up each tutorial -------------
150
151create_user tutorial1 "Basic ONOS Tutorial"
Jonathan Hartf5a22f42015-03-31 17:44:40 -0700152
153URL='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 -0700154wget -O tutorial1-setup-lxc.sh $URL
Jonathan Harta6348c42015-03-31 18:38:44 -0700155sudo -u tutorial1 -H sh -c 'cp tutorial1-setup-lxc.sh ~/ && cd ~/ && sh tutorial1-setup-lxc.sh'
Jonathan Hart97b81212015-03-27 11:19:22 -0700156
Jonathan Hartd8609332015-04-01 11:16:33 -0700157create_user sdnip "SDN-IP Tutorial"
158create_user distributed "Distributed Tutorial"
159create_user optical "Optical Tutorial"
160
Jonathan Hart97b81212015-03-27 11:19:22 -0700161# ------------- Zero Unused Blocks -------------
162#TODO investigate zerofree
Jonathan Hartc3f5a142015-03-30 16:42:37 -0700163#echo "Zeroing unused blocks"
164#sync
165#dd if=/dev/zero of=tmp-zeros
166#sync
167#rm tmp-zeros
168#sync