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