alshabib | 48b63e1 | 2014-12-08 23:53:03 -0800 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # vm-setup.sh |
| 3 | # |
| 4 | # This script installs ONOS dependencies and installs a desktop environment on a Miniet VM. |
| 5 | |
| 6 | |
| 7 | export CURRENT_USER=distributed |
| 8 | export USER_HOME=/home/${CURRENT_USER} |
| 9 | |
alshabib | ffbf45a | 2014-12-09 10:00:47 -0800 | [diff] [blame^] | 10 | ECLIPSE_URL=http://download.eclipse.org/technology/epp/downloads/release/luna/R/eclipse-java-luna-R-linux-gtk-x86_64.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 | 1f9ac81 | 2014-12-09 00:23:45 -0800 | [diff] [blame] | 44 | EXPOSE 22 6633 80 |
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 | |
| 54 | git clone https://gerrit.onosproject.org/onos |
alshabib | 77b4f21 | 2014-12-09 00:30:54 -0800 | [diff] [blame] | 55 | cd onos |
alshabib | 247d211 | 2014-12-09 00:25:53 -0800 | [diff] [blame] | 56 | git checkout 1.0.0 |
alshabib | 77b4f21 | 2014-12-09 00:30:54 -0800 | [diff] [blame] | 57 | cd - |
alshabib | 48b63e1 | 2014-12-08 23:53:03 -0800 | [diff] [blame] | 58 | |
| 59 | echo ". ~/onos/tools/dev/bash_profile" >> ~/.bashrc |
| 60 | echo "export ONOS_USER=root" >> ~/.bashrc |
alshabib | 42beadc | 2014-12-09 00:01:26 -0800 | [diff] [blame] | 61 | echo "sudo docker run --name onos-1 -d -P onos/tutorial-dist > /dev/null 2>&1" >> ~/.bashrc |
| 62 | echo "sudo docker run --name onos-2 -d -P onos/tutorial-dist > /dev/null 2>&1" >> ~/.bashrc |
| 63 | echo "sudo docker run --name onos-3 -d -P onos/tutorial-dist > /dev/null 2>&1" >> ~/.bashrc |
| 64 | |
alshabib | ffbf45a | 2014-12-09 10:00:47 -0800 | [diff] [blame^] | 65 | |
alshabib | 42beadc | 2014-12-09 00:01:26 -0800 | [diff] [blame] | 66 | cat > onos/tools/test/cells/docker << EOF |
| 67 | export ONOS_NIC="172.17.0.*" |
alshabib | ffbf45a | 2014-12-09 10:00:47 -0800 | [diff] [blame^] | 68 | export OC1="\$(sudo docker inspect --format '{{ .NetworkSettings.IPAddress }}' onos-1)" |
| 69 | export OC2="\$(sudo docker inspect --format '{{ .NetworkSettings.IPAddress }}' onos-2)" |
| 70 | export OC3="\$(sudo docker inspect --format '{{ .NetworkSettings.IPAddress }}' onos-3)" |
alshabib | 42beadc | 2014-12-09 00:01:26 -0800 | [diff] [blame] | 71 | export OCN="localhost" |
| 72 | export OCI="${OC1}" |
| 73 | 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" |
| 74 | EOF |
| 75 | |
| 76 | echo "cell docker" >> ~/.bashrc |
alshabib | 48b63e1 | 2014-12-08 23:53:03 -0800 | [diff] [blame] | 77 | |
| 78 | sed -i -e s/sdn/root/ onos/tools/package/debian/onos.conf |
| 79 | |
| 80 | cd onos && mvn clean install && cd - |
alshabib | 42beadc | 2014-12-09 00:01:26 -0800 | [diff] [blame] | 81 | |
alshabib | 48b63e1 | 2014-12-08 23:53:03 -0800 | [diff] [blame] | 82 | |
| 83 | # -------------- Setup Wireshark dissector ---- |
| 84 | |
| 85 | wget -O openflow.lua "https://gerrit.onosproject.org/gitweb?p=onos-vm.git;a=blob_plain;hb=refs/heads/onos-tutorial;f=openflow.lua" |
| 86 | mkdir -p .wireshark/plugins |
| 87 | mv openflow.lua .wireshark/plugins |
| 88 | |
| 89 | |
| 90 | |
| 91 | # -------------- Setup Desktop ---------------- |
| 92 | |
| 93 | sudo apt-get install -y xorg lxde |
| 94 | |
| 95 | #TODO: add backgrounds folder |
| 96 | sudo mkdir -p /usr/share/backgrounds |
| 97 | #TODO: change background |
| 98 | # Remove wallpaper, change background color |
| 99 | sudo sed -i 's/wallpaper_mode=1/wallpaper_mode=0/g' /usr/share/lxde/pcmanfm/LXDE.conf |
| 100 | sudo sed -i 's/desktop_bg=#000000/desktop_bg=#104187/g' /usr/share/lxde/pcmanfm/LXDE.conf |
| 101 | |
| 102 | sudo sed -i 's/lang=1/lang=0/g' /etc/lxdm/default.conf |
| 103 | sudo sed -i 's/bottom_pane=1/bottom_pane=0/g' /etc/lxdm/default.conf |
| 104 | sudo sed -i 's/disable=0/disable=1/g' /etc/lxdm/default.conf |
| 105 | |
| 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 | # Automatically start LXDE on login |
| 111 | echo '[[ -z $DISPLAY && $XDG_VTNR -eq 1 ]] && exec startx' >> ~/.bashrc |
| 112 | |
| 113 | # Automatically log into the VM |
| 114 | #sudo sed -i 's/exec /sbin/getty -8 38400 tty1//g' /etc/init/tty1.conf |
| 115 | #sudo sed -i '$ d' /etc/init/tty1.conf |
| 116 | #echo 'exec /bin/login -f bob < /dev/tty1 > /dev/tty1 2>&1' | sudo tee -a /etc/init/tty1.conf |
| 117 | |
| 118 | # Disable screensaver |
| 119 | sudo sed -i '/screensaver/d' /etc/xdg/lxsession/LXDE/autostart |
| 120 | cat > ${USER_HOME}/.xsessionrc << EOF |
| 121 | # disable screensaver |
| 122 | xset s off |
| 123 | # disable dpms (standby) |
| 124 | xset -dpms |
| 125 | EOF |
| 126 | |
| 127 | # Change LXTerminal default colors |
| 128 | #sudo sed -i 's/bgcolor=#000000000000/bgcolor=#ffffffffffff/g' ${USER_HOME}/.config/lxterminal/lxterminal.conf |
| 129 | #sudo sed -i 's/fgcolor=#aaaaaaaaaaaa/fgcolor=#000000000000/g' ${USER_HOME}/.config/lxterminal/lxterminal.conf |
| 130 | sudo sed -i 's/bgcolor=#000000000000/bgcolor=#ffffffffffff/g' /usr/share/lxterminal/lxterminal.conf |
| 131 | sudo sed -i 's/fgcolor=#aaaaaaaaaaaa/fgcolor=#000000000000/g' /usr/share/lxterminal/lxterminal.conf |
| 132 | |
| 133 | DESKTOP=${USER_HOME}/Desktop |
| 134 | |
| 135 | mkdir -p ${DESKTOP} |
| 136 | |
alshabib | ffbf45a | 2014-12-09 10:00:47 -0800 | [diff] [blame^] | 137 | cat > ${DESKTOP}/Eclipse << EOF |
| 138 | [Desktop Entry] |
| 139 | Encoding=UTF-8 |
| 140 | Type=Application |
| 141 | Name=Eclipse |
| 142 | Name[en_US]=Eclipse |
| 143 | Icon=/opt/eclipse/icon.xpm |
| 144 | Exec=/usr/bin/eclipse |
| 145 | Comment[en_US]= |
| 146 | EOF |
| 147 | |
alshabib | 48b63e1 | 2014-12-08 23:53:03 -0800 | [diff] [blame] | 148 | cat > ${DESKTOP}/Mininet << EOF |
| 149 | [Desktop Entry] |
| 150 | Encoding=UTF-8 |
| 151 | Type=Application |
| 152 | Name=Mininet |
| 153 | Name[en_US]=Mininet |
| 154 | Icon=konsole |
| 155 | Exec=/usr/bin/lxterminal -e 'sudo mn --custom /home/tutorial1/onos/tools/test/topos/tower.py --topo tower --controller remote --mac' |
| 156 | Comment[en_US]= |
| 157 | EOF |
| 158 | |
| 159 | cat > ${DESKTOP}/Tutorial << EOF |
| 160 | [Desktop Entry] |
| 161 | Encoding=UTF-8 |
| 162 | Type=Application |
| 163 | Name=ONOS Tutorial |
| 164 | Name[en_US]=ONOS Tutorial |
| 165 | Icon=internet-web-browser |
| 166 | Exec=/usr/bin/chromium-browser https://wiki.onosproject.org/display/ONOS/Distributed+ONOS+Tutorial |
| 167 | Comment[en_US]= |
| 168 | EOF |
| 169 | |
| 170 | cat > ${DESKTOP}/GUI << EOF |
| 171 | [Desktop Entry] |
| 172 | Encoding=UTF-8 |
| 173 | Type=Application |
| 174 | Name=ONOS GUI |
| 175 | Name[en_US]=ONOS GUI |
| 176 | Icon=internet-web-browser |
| 177 | Exec=/usr/bin/chromium-browser http://localhost:8181/onos/ui/index.html#topo |
| 178 | Comment[en_US]= |
| 179 | EOF |
| 180 | |
| 181 | cat > ${DESKTOP}/Wireshark << EOF |
| 182 | [Desktop Entry] |
| 183 | Encoding=UTF-8 |
| 184 | Type=Application |
| 185 | Name=Wireshark |
| 186 | Name[en_US]=Wireshark |
| 187 | Icon=wireshark |
| 188 | Exec=/usr/bin/wireshark |
| 189 | Comment[en_US]= |
| 190 | EOF |
| 191 | |
| 192 | cat > ${DESKTOP}/Reset << EOF |
| 193 | [Desktop Entry] |
| 194 | Encoding=UTF-8 |
| 195 | Type=Application |
| 196 | Name=Reset |
| 197 | Name[en_US]=Reset |
| 198 | Icon=konsole |
| 199 | Exec=/usr/bin/lxterminal -t 'Resetting; please wait' -e 'sudo service onos restart' |
| 200 | Comment[en_US]= |
| 201 | EOF |
| 202 | |
| 203 | # ------------- Install Other Tools ------------- |
| 204 | sudo apt-get install -y wireshark |
| 205 | # Enable root-less wireshark and add mininet |
| 206 | echo "Enabling wireshark group" |
| 207 | echo "wireshark-common wireshark-common/install-setuid boolean true" | sudo debconf-set-selections |
| 208 | sudo dpkg-reconfigure -f noninteractive wireshark-common |
| 209 | sudo usermod -a -G wireshark mininet |
| 210 | sudo usermod -a -G wireshark tutorial1 |
| 211 | |
| 212 | |
| 213 | echo "Installing VirtualBox Guest Additions" |
| 214 | sudo apt-get install -y virtualbox-guest-x11 |
| 215 | |
alshabib | ffbf45a | 2014-12-09 10:00:47 -0800 | [diff] [blame^] | 216 | sudo apt-get install -y git-review |
| 217 | |
| 218 | wget -c -N -O /tmp/eclipse.tar.gz ${ECLIPSE_URL} |
| 219 | tar xzf /tmp/eclipse.tar.gz |
| 220 | sudo mv eclipse /opt |
| 221 | sudo ln -s /opt/eclipse/eclipse /usr/bin/eclipse |
| 222 | |
alshabib | 48b63e1 | 2014-12-08 23:53:03 -0800 | [diff] [blame] | 223 | # ------------- Zero Unused Blocks ------------- |
| 224 | #TODO investigate zerofree |
| 225 | echo "Zeroing unused blocks" |
| 226 | sync |
| 227 | dd if=/dev/zero of=tmp-zeros |
| 228 | sync |
| 229 | rm tmp-zeros |
| 230 | sync |