alshabib | 48b63e1 | 2014-12-08 23:53:03 -0800 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # vm-setup.sh |
| 3 | # |
Marc De Leenheer | 1e3d3a0 | 2015-01-12 20:13:54 -0800 | [diff] [blame] | 4 | # This script installs ONOS dependencies and installs a desktop environment on a Mininet VM. |
alshabib | 48b63e1 | 2014-12-08 23:53:03 -0800 | [diff] [blame] | 5 | |
| 6 | |
| 7 | export CURRENT_USER=distributed |
| 8 | export USER_HOME=/home/${CURRENT_USER} |
| 9 | |
alshabib | 4aa072d | 2014-12-10 20:59:34 -0800 | [diff] [blame] | 10 | IDEA_URL=http://download.jetbrains.com/idea/ideaIC-14.0.2.tar.gz |
alshabib | 48b63e1 | 2014-12-08 23:53:03 -0800 | [diff] [blame] | 11 | |
| 12 | # -------------- Setup keys ------------------- |
| 13 | |
| 14 | mkdir -p ~/.ssh |
alshabib | ffbf45a | 2014-12-09 10:00:47 -0800 | [diff] [blame] | 15 | ssh-keygen -t rsa -P "" -f .ssh/id_rsa |
| 16 | cp .ssh/id_rsa.pub .ssh/authorized_keys |
alshabib | 48b63e1 | 2014-12-08 23:53:03 -0800 | [diff] [blame] | 17 | |
| 18 | # -------------- Install Karaf ---------------- |
| 19 | |
| 20 | mkdir Applications |
| 21 | cd Applications |
| 22 | wget http://apache.osuosl.org/karaf/3.0.2/apache-karaf-3.0.2.zip |
| 23 | unzip apache-karaf-3.0.2.zip |
| 24 | cd - |
| 25 | |
alshabib | ffbf45a | 2014-12-09 10:00:47 -0800 | [diff] [blame] | 26 | mkdir Downloads |
| 27 | cp Applications/apache-karaf-3.0.2.zip Downloads/ |
| 28 | |
alshabib | 48b63e1 | 2014-12-08 23:53:03 -0800 | [diff] [blame] | 29 | #--------------- Setup Docker env ------------ |
| 30 | |
| 31 | mkdir -p docker/onos-tutorial |
| 32 | cd docker/onos-tutorial |
| 33 | cat > Dockerfile << EOF |
| 34 | FROM ubuntu-upstart:14.10 |
| 35 | MAINTAINER Ali Al-Shabibi <ali@onlab.us> |
| 36 | RUN apt-get update && apt-get install -y openjdk-8-jre openssh-server |
| 37 | RUN mkdir /var/run/sshd |
| 38 | RUN echo 'root:onosrocks' | chpasswd |
| 39 | RUN sed -i 's/PermitRootLogin without-password/PermitRootLogin yes/' /etc/ssh/sshd_config |
| 40 | # SSH login fix. Otherwise user is kicked off after login |
| 41 | RUN sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd |
| 42 | ENV NOTVISIBLE "in users profile" |
| 43 | RUN echo "export VISIBLE=now" >> /etc/profile |
alshabib | 3f0991a | 2014-12-09 13:36:53 -0800 | [diff] [blame] | 44 | EXPOSE 22 6633 8181 |
alshabib | 48b63e1 | 2014-12-08 23:53:03 -0800 | [diff] [blame] | 45 | CMD ["/sbin/init"] |
| 46 | EOF |
| 47 | |
| 48 | sudo docker build -t onos/tutorial-dist . |
| 49 | |
| 50 | cd - |
| 51 | |
| 52 | # -------------- Download ONOS ---------------- |
| 53 | |
alshabib | 0ecf4c4 | 2014-12-11 15:11:44 -0800 | [diff] [blame] | 54 | git clone https://github.com/bocon13/onos-byon.git |
alshabib | 48b63e1 | 2014-12-08 23:53:03 -0800 | [diff] [blame] | 55 | git clone https://gerrit.onosproject.org/onos |
alshabib | 77b4f21 | 2014-12-09 00:30:54 -0800 | [diff] [blame] | 56 | cd onos |
alshabib | 247d211 | 2014-12-09 00:25:53 -0800 | [diff] [blame] | 57 | git checkout 1.0.0 |
alshabib | 63ee832 | 2014-12-12 14:54:09 -0800 | [diff] [blame] | 58 | git config --global user.email "tutorial@localhost" |
| 59 | git config --global user.name "Mr. Tutorial" |
| 60 | git fetch https://gerrit.onosproject.org/onos refs/changes/07/2107/1 && git cherry-pick FETCH_HEAD |
alshabib | 77b4f21 | 2014-12-09 00:30:54 -0800 | [diff] [blame] | 61 | cd - |
alshabib | 48b63e1 | 2014-12-08 23:53:03 -0800 | [diff] [blame] | 62 | |
alshabib | 316fe24 | 2014-12-11 17:50:00 -0800 | [diff] [blame] | 63 | echo "export JAVA_HOME=''" |
alshabib | 48b63e1 | 2014-12-08 23:53:03 -0800 | [diff] [blame] | 64 | echo ". ~/onos/tools/dev/bash_profile" >> ~/.bashrc |
| 65 | echo "export ONOS_USER=root" >> ~/.bashrc |
alshabib | ffbf45a | 2014-12-09 10:00:47 -0800 | [diff] [blame] | 66 | |
alshabib | 7dcc33f | 2014-12-10 23:46:45 -0800 | [diff] [blame] | 67 | sed -i -e 's/open/xdg-open/' ~/onos/tools/test/bin/onos-gui |
| 68 | |
alshabib | 42beadc | 2014-12-09 00:01:26 -0800 | [diff] [blame] | 69 | cat > onos/tools/test/cells/docker << EOF |
| 70 | export ONOS_NIC="172.17.0.*" |
alshabib | ffbf45a | 2014-12-09 10:00:47 -0800 | [diff] [blame] | 71 | export OC1="\$(sudo docker inspect --format '{{ .NetworkSettings.IPAddress }}' onos-1)" |
| 72 | export OC2="\$(sudo docker inspect --format '{{ .NetworkSettings.IPAddress }}' onos-2)" |
| 73 | export OC3="\$(sudo docker inspect --format '{{ .NetworkSettings.IPAddress }}' onos-3)" |
alshabib | 42beadc | 2014-12-09 00:01:26 -0800 | [diff] [blame] | 74 | export OCN="localhost" |
alshabib | 1c53a80 | 2014-12-10 23:41:31 -0800 | [diff] [blame] | 75 | export OCI="\${OC1}" |
alshabib | 42beadc | 2014-12-09 00:01:26 -0800 | [diff] [blame] | 76 | export ONOS_FEATURES="webconsole,onos-api,onos-core,onos-cli,onos-rest,onos-gui,onos-openflow,onos-app-fwd,onos-app-proxyarp,onos-app-mobility" |
| 77 | EOF |
| 78 | |
alshabib | 5fe05c2 | 2014-12-12 14:14:53 -0800 | [diff] [blame] | 79 | echo "unset JAVA_HOME" >> ~/.bashrc |
alshabib | 7bfe154 | 2014-12-11 17:19:10 -0800 | [diff] [blame] | 80 | echo "sudo service onos stop > /dev/null 2>&1" >> ~/.bashrc |
alshabib | 1f5b85d | 2014-12-11 16:01:31 -0800 | [diff] [blame] | 81 | echo "cell docker > /dev/null 2>&1" >> ~/.bashrc |
alshabib | 48b63e1 | 2014-12-08 23:53:03 -0800 | [diff] [blame] | 82 | |
| 83 | sed -i -e s/sdn/root/ onos/tools/package/debian/onos.conf |
| 84 | |
| 85 | cd onos && mvn clean install && cd - |
alshabib | 42beadc | 2014-12-09 00:01:26 -0800 | [diff] [blame] | 86 | |
alshabib | d1a096f | 2014-12-10 23:34:04 -0800 | [diff] [blame] | 87 | #--------------- set up mininet script -------- |
| 88 | |
| 89 | cat > ~/startmn.sh << EOF |
| 90 | #!/bin/bash |
alshabib | 7bfe154 | 2014-12-11 17:19:10 -0800 | [diff] [blame] | 91 | sudo python ~/onos/tools/test/topos/sol.py \$OC1 \$OC2 \$OC3 |
alshabib | d1a096f | 2014-12-10 23:34:04 -0800 | [diff] [blame] | 92 | EOF |
| 93 | |
| 94 | chmod +x ~/startmn.sh |
alshabib | 48b63e1 | 2014-12-08 23:53:03 -0800 | [diff] [blame] | 95 | |
| 96 | # -------------- Setup Wireshark dissector ---- |
| 97 | |
| 98 | wget -O openflow.lua "https://gerrit.onosproject.org/gitweb?p=onos-vm.git;a=blob_plain;hb=refs/heads/onos-tutorial;f=openflow.lua" |
| 99 | mkdir -p .wireshark/plugins |
| 100 | mv openflow.lua .wireshark/plugins |
| 101 | |
| 102 | |
| 103 | |
| 104 | # -------------- Setup Desktop ---------------- |
| 105 | |
| 106 | sudo apt-get install -y xorg lxde |
| 107 | |
| 108 | #TODO: add backgrounds folder |
| 109 | sudo mkdir -p /usr/share/backgrounds |
| 110 | #TODO: change background |
| 111 | # Remove wallpaper, change background color |
| 112 | sudo sed -i 's/wallpaper_mode=1/wallpaper_mode=0/g' /usr/share/lxde/pcmanfm/LXDE.conf |
| 113 | sudo sed -i 's/desktop_bg=#000000/desktop_bg=#104187/g' /usr/share/lxde/pcmanfm/LXDE.conf |
| 114 | |
| 115 | sudo sed -i 's/lang=1/lang=0/g' /etc/lxdm/default.conf |
| 116 | sudo sed -i 's/bottom_pane=1/bottom_pane=0/g' /etc/lxdm/default.conf |
| 117 | sudo sed -i 's/disable=0/disable=1/g' /etc/lxdm/default.conf |
| 118 | |
| 119 | |
| 120 | wget -O onos.png "https://gerrit.onosproject.org/gitweb?p=onos-vm.git;a=blob_plain;hb=refs/heads/onos-tutorial;f=onos.png" |
| 121 | sudo cp onos.png /usr/share/backgrounds/default.png |
| 122 | |
| 123 | # Automatically start LXDE on login |
| 124 | echo '[[ -z $DISPLAY && $XDG_VTNR -eq 1 ]] && exec startx' >> ~/.bashrc |
| 125 | |
| 126 | # Automatically log into the VM |
| 127 | #sudo sed -i 's/exec /sbin/getty -8 38400 tty1//g' /etc/init/tty1.conf |
| 128 | #sudo sed -i '$ d' /etc/init/tty1.conf |
| 129 | #echo 'exec /bin/login -f bob < /dev/tty1 > /dev/tty1 2>&1' | sudo tee -a /etc/init/tty1.conf |
| 130 | |
| 131 | # Disable screensaver |
| 132 | sudo sed -i '/screensaver/d' /etc/xdg/lxsession/LXDE/autostart |
| 133 | cat > ${USER_HOME}/.xsessionrc << EOF |
| 134 | # disable screensaver |
| 135 | xset s off |
| 136 | # disable dpms (standby) |
| 137 | xset -dpms |
| 138 | EOF |
| 139 | |
| 140 | # Change LXTerminal default colors |
| 141 | #sudo sed -i 's/bgcolor=#000000000000/bgcolor=#ffffffffffff/g' ${USER_HOME}/.config/lxterminal/lxterminal.conf |
| 142 | #sudo sed -i 's/fgcolor=#aaaaaaaaaaaa/fgcolor=#000000000000/g' ${USER_HOME}/.config/lxterminal/lxterminal.conf |
| 143 | sudo sed -i 's/bgcolor=#000000000000/bgcolor=#ffffffffffff/g' /usr/share/lxterminal/lxterminal.conf |
| 144 | sudo sed -i 's/fgcolor=#aaaaaaaaaaaa/fgcolor=#000000000000/g' /usr/share/lxterminal/lxterminal.conf |
| 145 | |
| 146 | DESKTOP=${USER_HOME}/Desktop |
| 147 | |
| 148 | mkdir -p ${DESKTOP} |
| 149 | |
alshabib | 4aa072d | 2014-12-10 20:59:34 -0800 | [diff] [blame] | 150 | cat > ${DESKTOP}/IntelliJ << EOF |
alshabib | ffbf45a | 2014-12-09 10:00:47 -0800 | [diff] [blame] | 151 | [Desktop Entry] |
| 152 | Encoding=UTF-8 |
| 153 | Type=Application |
alshabib | 4aa072d | 2014-12-10 20:59:34 -0800 | [diff] [blame] | 154 | Name=IntelliJ |
| 155 | Name[en_US]=IntelliJ |
| 156 | Icon=/home/distributed/Applications/idea/bin/idea.png |
| 157 | Exec=/home/distributed/Applications/idea/bin/idea.sh |
alshabib | ffbf45a | 2014-12-09 10:00:47 -0800 | [diff] [blame] | 158 | Comment[en_US]= |
| 159 | EOF |
| 160 | |
alshabib | 48b63e1 | 2014-12-08 23:53:03 -0800 | [diff] [blame] | 161 | cat > ${DESKTOP}/Tutorial << EOF |
| 162 | [Desktop Entry] |
| 163 | Encoding=UTF-8 |
| 164 | Type=Application |
| 165 | Name=ONOS Tutorial |
| 166 | Name[en_US]=ONOS Tutorial |
| 167 | Icon=internet-web-browser |
| 168 | Exec=/usr/bin/chromium-browser https://wiki.onosproject.org/display/ONOS/Distributed+ONOS+Tutorial |
| 169 | Comment[en_US]= |
| 170 | EOF |
| 171 | |
alshabib | 48b63e1 | 2014-12-08 23:53:03 -0800 | [diff] [blame] | 172 | |
| 173 | cat > ${DESKTOP}/Wireshark << EOF |
| 174 | [Desktop Entry] |
| 175 | Encoding=UTF-8 |
| 176 | Type=Application |
| 177 | Name=Wireshark |
| 178 | Name[en_US]=Wireshark |
| 179 | Icon=wireshark |
| 180 | Exec=/usr/bin/wireshark |
| 181 | Comment[en_US]= |
| 182 | EOF |
| 183 | |
alshabib | 4c5231b | 2014-12-11 15:32:37 -0800 | [diff] [blame] | 184 | cat > ${DESKTOP}/Terminal << EOF |
| 185 | [Desktop Entry] |
| 186 | Encoding=UTF-8 |
| 187 | Name=LXTerminal |
| 188 | TryExec=lxterminal |
| 189 | Exec=lxterminal |
| 190 | Icon=lxterminal |
| 191 | Type=Application |
| 192 | Categories=GTK;Utility;TerminalEmulator; |
| 193 | EOF |
| 194 | |
alshabib | 48b63e1 | 2014-12-08 23:53:03 -0800 | [diff] [blame] | 195 | # ------------- Install Other Tools ------------- |
| 196 | sudo apt-get install -y wireshark |
| 197 | # Enable root-less wireshark and add mininet |
| 198 | echo "Enabling wireshark group" |
| 199 | echo "wireshark-common wireshark-common/install-setuid boolean true" | sudo debconf-set-selections |
| 200 | sudo dpkg-reconfigure -f noninteractive wireshark-common |
| 201 | sudo usermod -a -G wireshark mininet |
| 202 | sudo usermod -a -G wireshark tutorial1 |
| 203 | |
| 204 | |
| 205 | echo "Installing VirtualBox Guest Additions" |
| 206 | sudo apt-get install -y virtualbox-guest-x11 |
| 207 | |
alshabib | ffbf45a | 2014-12-09 10:00:47 -0800 | [diff] [blame] | 208 | sudo apt-get install -y git-review |
| 209 | |
alshabib | 4aa072d | 2014-12-10 20:59:34 -0800 | [diff] [blame] | 210 | cd ~/Applications |
| 211 | |
| 212 | wget -c -N -O /tmp/idea.tar.gz ${IDEA_URL} |
| 213 | tar xzf /tmp/idea.tar.gz |
| 214 | sudo mv idea-IC-139.659.2 idea |
| 215 | |
| 216 | cd - |
alshabib | ffbf45a | 2014-12-09 10:00:47 -0800 | [diff] [blame] | 217 | |
alshabib | 0ecf4c4 | 2014-12-11 15:11:44 -0800 | [diff] [blame] | 218 | sudo apt-get clean |
| 219 | |
alshabib | 48b63e1 | 2014-12-08 23:53:03 -0800 | [diff] [blame] | 220 | # ------------- Zero Unused Blocks ------------- |
| 221 | #TODO investigate zerofree |
| 222 | echo "Zeroing unused blocks" |
| 223 | sync |
| 224 | dd if=/dev/zero of=tmp-zeros |
| 225 | sync |
| 226 | rm tmp-zeros |
| 227 | sync |