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