Luca Prete | 8137ffc | 2016-08-16 11:53:45 -0700 | [diff] [blame^] | 1 | #!/bin/bash |
| 2 | # onos-setup.sh |
| 3 | # |
| 4 | # Runs as mininet user. |
| 5 | # |
| 6 | # This script sets up the desktop environment, installs ONOS in the LXC cluster, |
| 7 | # then creates a user for each tutorial and runs the tutorial setup script. |
| 8 | |
| 9 | function create_user { |
| 10 | local name=$1 |
| 11 | local description=$2 |
| 12 | |
| 13 | sudo /usr/sbin/useradd -c "$description" -d /home/$name -U -m -p $(openssl passwd -1 $name) -s /bin/bash $name |
| 14 | echo "$name ALL=(ALL) NOPASSWD:ALL" >> $name |
| 15 | sudo mv $name /etc/sudoers.d |
| 16 | sudo chown root:root /etc/sudoers.d/$name |
| 17 | sudo usermod -aG wireshark $name |
| 18 | |
| 19 | sudo usermod -aG mininet $name |
| 20 | |
| 21 | sudo mkdir /home/$name/.ssh |
| 22 | sudo chown $name:$name /home/$name/.ssh |
| 23 | sudo cp /home/mininet/.ssh/id_rsa /home/$name/.ssh/ |
| 24 | sudo chown $name:$name /home/$name/.ssh/id_rsa |
| 25 | |
| 26 | sudo -u $name sh -c "echo \"export ONOS_ROOT=/home/mininet/onos\" >> /home/$name/.bashrc" |
| 27 | sudo -u $name sh -c "echo \"export KARAF_ROOT=/home/mininet/apache-karaf-3.0.5\" >> /home/$name/.bashrc" |
| 28 | sudo -u $name sh -c "echo \"export M2_REPO=/home/mininet/.m2/repository\" >> /home/$name/.bashrc" |
| 29 | sudo -u $name sh -c "echo \". /home/mininet/onos/tools/dev/bash_profile\" >> /home/$name/.bashrc" |
| 30 | |
| 31 | sudo -u $name ssh -o "StrictHostKeyChecking no" sdn@10.0.3.11 ls |
| 32 | sudo -u $name ssh -o "StrictHostKeyChecking no" sdn@10.0.3.12 ls |
| 33 | sudo -u $name ssh -o "StrictHostKeyChecking no" sdn@10.0.3.13 ls |
| 34 | |
| 35 | sudo mkdir -p /home/$name/.wireshark/plugins |
| 36 | sudo cp /home/mininet/openflow.lua /home/$name/.wireshark/plugins |
| 37 | sudo chown -R $name:$name /home/$name/.wireshark |
| 38 | } |
| 39 | |
| 40 | # ------------- Set up desktop environment ------------- |
| 41 | |
| 42 | echo "Setting up desktop environment" |
| 43 | |
| 44 | # Remove kernel boot options that will prevent the gui from running |
| 45 | sudo sed -i s/text// /etc/default/grub |
| 46 | sudo sed -i s/ipv6.disable=1// /etc/default/grub |
| 47 | sudo update-grub |
| 48 | |
| 49 | sudo apt-get install -y xorg lxde systemd-shim |
| 50 | |
| 51 | #TODO: add backgrounds folder |
| 52 | sudo mkdir -p /usr/share/backgrounds |
| 53 | #TODO: change background |
| 54 | # Remove wallpaper, change background color |
| 55 | sudo sed -i 's/wallpaper_mode=1/wallpaper_mode=0/g' /usr/share/lxde/pcmanfm/LXDE.conf |
| 56 | sudo sed -i 's/desktop_bg=#000000/desktop_bg=#104187/g' /usr/share/lxde/pcmanfm/LXDE.conf |
| 57 | |
| 58 | sudo sed -i 's/lang=1/lang=0/g' /etc/lxdm/default.conf |
| 59 | sudo sed -i 's/bottom_pane=1/bottom_pane=0/g' /etc/lxdm/default.conf |
| 60 | sudo sed -i 's/disable=0/disable=1/g' /etc/lxdm/default.conf |
| 61 | |
| 62 | # Allow VM to be rebooted from GUI |
| 63 | echo "session required pam_systemd.so" | sudo tee --append /etc/pam.d/lxdm |
| 64 | |
| 65 | wget -O onos.png "https://gerrit.onosproject.org/gitweb?p=onos-vm.git;a=blob_plain;hb=refs/heads/onos-tutorial-1.6;f=onos.png" |
| 66 | sudo cp onos.png /usr/share/backgrounds/default.png |
| 67 | |
| 68 | # Change LXTerminal default colors |
| 69 | sudo sed -i 's/bgcolor=#000000000000/bgcolor=#ffffffffffff/g' /usr/share/lxterminal/lxterminal.conf |
| 70 | sudo sed -i 's/fgcolor=#aaaaaaaaaaaa/fgcolor=#000000000000/g' /usr/share/lxterminal/lxterminal.conf |
| 71 | |
| 72 | # Disable screensaver |
| 73 | sudo sed -i '/screensaver/d' /etc/xdg/lxsession/LXDE/autostart |
| 74 | cat > /home/mininet/.xsessionrc << EOF |
| 75 | # disable screensaver |
| 76 | xset s off |
| 77 | # disable dpms (standby) |
| 78 | xset -dpms |
| 79 | EOF |
| 80 | |
| 81 | echo "Enabling non-root wireshark" |
| 82 | echo "wireshark-common wireshark-common/install-setuid boolean true" | sudo debconf-set-selections |
| 83 | sudo dpkg-reconfigure -f noninteractive wireshark-common |
| 84 | |
| 85 | # Get the wireshark dissector handy |
| 86 | wget -O /home/mininet/openflow.lua "https://gerrit.onosproject.org/gitweb?p=onos-vm.git;a=blob_plain;hb=refs/heads/onos-tutorial-1.1;f=openflow.lua" |
| 87 | |
| 88 | # -------------- Install ONOS ---------------- |
| 89 | |
| 90 | echo "Installing ONOS" |
| 91 | |
| 92 | USER=mininet |
| 93 | USER_HOME=/home/${USER} |
| 94 | |
| 95 | cd ~ |
| 96 | |
| 97 | # Download a local karaf so we can use the bin directory |
| 98 | wget http://archive.apache.org/dist/karaf/3.0.5/apache-karaf-3.0.5.tar.gz |
| 99 | tar -xzf apache-karaf-3.0.5.tar.gz |
| 100 | |
| 101 | |
| 102 | git clone https://gerrit.onosproject.org/onos |
| 103 | cd onos && git checkout 1.6.0 && cd - |
| 104 | |
| 105 | mkdir -p ~/Downloads |
| 106 | |
| 107 | |
| 108 | echo "export ONOS_ROOT=${USER_HOME}/onos" >> ~/.bashrc |
| 109 | echo "export KARAF_ROOT=${USER_HOME}/apache-karaf-3.0.5" >> ~/.bashrc |
| 110 | echo ". ~/onos/tools/dev/bash_profile" >> ~/.bashrc |
| 111 | |
| 112 | export ONOS_ROOT=${USER_HOME}/onos |
| 113 | export KARAF_ROOT=${USER_HOME}/apache-karaf-3.0.5 |
| 114 | . ~/onos/tools/dev/bash_profile |
| 115 | |
| 116 | |
| 117 | echo $ONOS_ROOT |
| 118 | |
| 119 | cd $ONOS_ROOT && mvn clean install && mvn dependency:go-offline && cd - |
| 120 | |
| 121 | # Get the sample apps and build them for the right version |
| 122 | git clone https://gerrit.onosproject.org/onos-app-samples |
| 123 | cd onos-app-samples |
| 124 | git checkout 52da58b5991049025ce1b599c000357500b00aef |
| 125 | mvn versions:set -DnewVersion=1.2.1 versions:commit |
| 126 | mvn clean install |
| 127 | cd .. |
| 128 | |
| 129 | |
| 130 | cat << EOF >> onos/tools/test/cells/3node |
| 131 | export ONOS_NIC=10.0.3.* |
| 132 | export OC1="10.0.3.11" |
| 133 | export OC2="10.0.3.12" |
| 134 | export OC3="10.0.3.13" |
| 135 | export OCI="10.0.3.11" |
| 136 | export ONOS_APPS="drivers,openflow" |
| 137 | export ONOS_USER="sdn" |
| 138 | EOF |
| 139 | |
| 140 | cat << EOF >> onos/tools/test/cells/1node |
| 141 | export ONOS_NIC=10.0.3.* |
| 142 | export OC1="10.0.3.11" |
| 143 | export OCI="10.0.3.11" |
| 144 | export ONOS_APPS="drivers,openflow" |
| 145 | export ONOS_USER="sdn" |
| 146 | EOF |
| 147 | |
| 148 | cell 3node |
| 149 | |
| 150 | |
| 151 | onos-package |
| 152 | onos-group install -f |
| 153 | onos-wait-for-start $OC1 |
| 154 | onos-wait-for-start $OC2 |
| 155 | onos-wait-for-start $OC3 |
| 156 | |
| 157 | echo "ONOS install and startup complete" |
| 158 | |
| 159 | sleep 1 |
| 160 | onos-service --cell status |
| 161 | |
| 162 | # Prevent ONOS services from starting automatically |
| 163 | sudo sh -c "echo manual >> /var/lib/lxc/onos1/rootfs/etc/init/onos.override" |
| 164 | sudo sh -c "echo manual >> /var/lib/lxc/onos2/rootfs/etc/init/onos.override" |
| 165 | sudo sh -c "echo manual >> /var/lib/lxc/onos3/rootfs/etc/init/onos.override" |
| 166 | |
| 167 | # ------------- Create reset scripts ------------- |
| 168 | |
| 169 | cat << EOF >> ${USER_HOME}/reset-to-1.sh |
| 170 | #!/bin/bash |
| 171 | sudo rm -rf /tmp/* |
| 172 | export ONOS_ROOT=/home/mininet/onos |
| 173 | export M2_REPO=/home/mininet/.m2/repository |
| 174 | export KARAF_TAR=/home/mininet/apache-karaf-3.0.5.tar.gz |
| 175 | . ${ONOS_ROOT}/tools/dev/bash_profile |
| 176 | . ${ONOS_ROOT}/tools/build/envDefaults |
| 177 | |
| 178 | sudo mn -c |
| 179 | |
| 180 | cell 3node |
| 181 | onos-service --cell stop |
| 182 | cell 1node |
| 183 | |
| 184 | if [ -n "\$1" ]; then |
| 185 | export ONOS_APPS=\$ONOS_APPS,\$1 |
| 186 | fi |
| 187 | |
| 188 | onos-package |
| 189 | onos-install -f '$OC1' |
| 190 | EOF |
| 191 | |
| 192 | sudo chmod 777 ${USER_HOME}/reset-to-1.sh |
| 193 | |
| 194 | cat << EOF >> ${USER_HOME}/reset-to-3.sh |
| 195 | #!/bin/bash |
| 196 | sudo rm -rf /tmp/* |
| 197 | export ONOS_ROOT=/home/mininet/onos |
| 198 | export M2_REPO=/home/mininet/.m2/repository |
| 199 | export KARAF_TAR=/home/mininet/apache-karaf-3.0.5.tar.gz |
| 200 | . ${ONOS_ROOT}/tools/dev/bash_profile |
| 201 | . ${ONOS_ROOT}/tools/build/envDefaults |
| 202 | |
| 203 | sudo mn -c |
| 204 | |
| 205 | cell 3node |
| 206 | |
| 207 | if [ -n "\$1" ]; then |
| 208 | export ONOS_APPS=\$ONOS_APPS,\$1 |
| 209 | fi |
| 210 | |
| 211 | onos-service --cell stop |
| 212 | onos-package |
| 213 | onos-install -f '$OC1' |
| 214 | onos-install -f '$OC2' |
| 215 | onos-install -f '$OC3' |
| 216 | EOF |
| 217 | |
| 218 | sudo chmod 777 ${USER_HOME}/reset-to-3.sh |
| 219 | |
| 220 | sudo apt-get clean |
| 221 | sudo rm /etc/apt/apt.conf.d/02proxy |
| 222 | |
| 223 | # ------------- Set up each tutorial ------------- |
| 224 | |
| 225 | create_user tutorial1 "Basic ONOS Tutorial" |
| 226 | |
| 227 | URL='https://gerrit.onosproject.org/gitweb?p=onos-vm.git;a=blob_plain;hb=refs/heads/onos-tutorial-1.6;f=tutorial1-setup.sh' |
| 228 | wget -O tutorial1-setup.sh $URL |
| 229 | sudo -u tutorial1 -H sh -c 'cp tutorial1-setup.sh ~/ && cd ~/ && sh tutorial1-setup.sh' |
| 230 | |
| 231 | create_user sdnip "SDN-IP Tutorial" |
| 232 | |
| 233 | SDNIP_URL='https://gerrit.onosproject.org/gitweb?p=onos-vm.git;a=blob_plain;hb=refs/heads/onos-tutorial-1.6;f=sdnip-setup.sh' |
| 234 | wget -O sdnip-setup.sh $SDNIP_URL |
| 235 | sudo -u sdnip -H sh -c 'cp sdnip-setup.sh ~/ && cd ~/ && sh sdnip-setup.sh' |
| 236 | |
| 237 | create_user distributed "Distributed Tutorial" |
| 238 | |
| 239 | DIST_URL='https://gerrit.onosproject.org/gitweb?p=onos-vm.git;a=blob_plain;hb=refs/heads/onos-tutorial-1.6;f=dist-setup.sh' |
| 240 | wget -O dist-setup.sh $DIST_URL |
| 241 | sudo -u distributed -H sh -c 'cp dist-setup.sh ~/ && cd ~/ && sh dist-setup.sh' |
| 242 | |
| 243 | create_user optical "Optical Tutorial" |
| 244 | |
| 245 | OPT_URL='https://gerrit.onosproject.org/gitweb?p=onos-vm.git;a=blob_plain;hb=refs/heads/onos-tutorial-1.1;f=opt-setup.sh' |
| 246 | wget -O opt-setup.sh $OPT_URL |
| 247 | sudo -u optical -H sh -c 'cp opt-setup.sh ~/ && cd ~/ && sh opt-setup.sh' |
| 248 | |
| 249 | # ------------- Zero Unused Blocks ------------- |
| 250 | #TODO investigate zerofree |
| 251 | echo "Zeroing unused blocks" |
| 252 | sync |
| 253 | dd if=/dev/zero of=tmp-zeros |
| 254 | sync |
| 255 | rm tmp-zeros |
| 256 | sync |