blob: 0c72b6361c97f7bcd623fc75e8a953198cc090ba [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"
23 sudo -u $name sh -c "echo \". /home/mininet/onos/tools/dev/bash_profile\" >> /home/$name/.bashrc"
24
25 sudo -u $name ssh -o "StrictHostKeyChecking no" sdn@10.0.3.11 ls
26 sudo -u $name ssh -o "StrictHostKeyChecking no" sdn@10.0.3.12 ls
27 sudo -u $name ssh -o "StrictHostKeyChecking no" sdn@10.0.3.13 ls
28}
29
Jonathan Hart7b6cfef2015-03-27 10:09:38 -070030# -------------- Install ONOS ----------------
31
32USER=mininet
33USER_HOME=/home/${USER}
34
35echo `whoami`
36
37cd ~
38git clone https://gerrit.onosproject.org/onos
Jonathan Hartb1e22112015-03-31 16:42:03 -070039cd onos && git checkout onos-1.1 && cd -
Jonathan Hart7b6cfef2015-03-27 10:09:38 -070040
Jonathan Hartb1e22112015-03-31 16:42:03 -070041mkdir -p ~/Downloads
42
43echo "export ONOS_ROOT=${USER_HOME}/onos" >> ~/.bashrc
44echo ". ~/onos/tools/dev/bash_profile" >> ~/.bashrc
Jonathan Hart7b6cfef2015-03-27 10:09:38 -070045
46export ONOS_ROOT=${USER_HOME}/onos
47. ~/onos/tools/dev/bash_profile
48
49echo $ONOS_ROOT
50
51echo $JAVA_HOME
52export JAVA_HOME=""
53cd $ONOS_ROOT && mvn clean install && mvn dependency:go-offline && cd -
54
Jonathan Hartb1e22112015-03-31 16:42:03 -070055cat << EOF >> onos/tools/test/cells/3node
Jonathan Hart7b6cfef2015-03-27 10:09:38 -070056export ONOS_NIC=10.0.3.*
57export OC1="10.0.3.11"
Jonathan Hartdd7016a2015-03-31 09:31:58 -070058export OC2="10.0.3.12"
59export OC3="10.0.3.13"
Jonathan Hart7b6cfef2015-03-27 10:09:38 -070060export OCI="${OC1}"
61export ONOS_FEATURES="webconsole,onos-rest,onos-gui,onos-api,onos-core,onos-cli,onos-openflow"
62export ONOS_USER="sdn"
63EOF
64
Jonathan Hartb1e22112015-03-31 16:42:03 -070065cat << EOF >> onos/tools/test/cells/1node
66export ONOS_NIC=10.0.3.*
67export OC1="10.0.3.11"
68export OCI="${OC1}"
69export ONOS_FEATURES="webconsole,onos-rest,onos-gui,onos-api,onos-core,onos-cli,onos-openflow"
70export ONOS_USER="sdn"
71EOF
72
73cell 3node
Jonathan Hart7b6cfef2015-03-27 10:09:38 -070074
75onos-package
76onos-group install -f
77onos-wait-for-start $OC1
78onos-wait-for-start $OC2
79onos-wait-for-start $OC3
80
81sleep 20
Jonathan Hartb1e22112015-03-31 16:42:03 -070082onos-service --cell status
83
84# ------------- Set up desktop environment -------------
85
86# Remove kernel boot options that will prevent the gui from running
87sudo sed -i s/text// /etc/default/grub
88sudo sed -i s/ipv6.disable=1// /etc/default/grub
89sudo update-grub
90
91sudo apt-get install -y xorg lxde systemd-shim
92
93#TODO: add backgrounds folder
94sudo mkdir -p /usr/share/backgrounds
95#TODO: change background
96# Remove wallpaper, change background color
97sudo sed -i 's/wallpaper_mode=1/wallpaper_mode=0/g' /usr/share/lxde/pcmanfm/LXDE.conf
98sudo sed -i 's/desktop_bg=#000000/desktop_bg=#104187/g' /usr/share/lxde/pcmanfm/LXDE.conf
99
100sudo sed -i 's/lang=1/lang=0/g' /etc/lxdm/default.conf
101sudo sed -i 's/bottom_pane=1/bottom_pane=0/g' /etc/lxdm/default.conf
102sudo sed -i 's/disable=0/disable=1/g' /etc/lxdm/default.conf
103
104# Allow VM to be rebooted from GUI
105echo "session required pam_systemd.so" | sudo tee --append /etc/pam.d/lxdm
106
107wget -O onos.png "https://gerrit.onosproject.org/gitweb?p=onos-vm.git;a=blob_plain;hb=refs/heads/onos-tutorial;f=onos.png"
108sudo cp onos.png /usr/share/backgrounds/default.png
109
110# Change LXTerminal default colors
111sudo sed -i 's/bgcolor=#000000000000/bgcolor=#ffffffffffff/g' /usr/share/lxterminal/lxterminal.conf
112sudo sed -i 's/fgcolor=#aaaaaaaaaaaa/fgcolor=#000000000000/g' /usr/share/lxterminal/lxterminal.conf
113
114# Disable screensaver
115sudo sed -i '/screensaver/d' /etc/xdg/lxsession/LXDE/autostart
116cat > /home/mininet/.xsessionrc << EOF
117# disable screensaver
118xset s off
119# disable dpms (standby)
120xset -dpms
121EOF
122
123# ------------- Set up each tutorial -------------
124
125create_user tutorial1 "Basic ONOS Tutorial"
126wget -O tutorial1-setup-lxc.sh $URL
127sudo -u ${CURRENT_USER} -H sh -c 'cp tutorial1-setup-lxc.sh ~/ && cd ~/ && sh tutorial1-setup-lxc.sh'
Jonathan Hart97b81212015-03-27 11:19:22 -0700128
129# ------------- Zero Unused Blocks -------------
130#TODO investigate zerofree
Jonathan Hartc3f5a142015-03-30 16:42:37 -0700131#echo "Zeroing unused blocks"
132#sync
133#dd if=/dev/zero of=tmp-zeros
134#sync
135#rm tmp-zeros
136#sync