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