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