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 | |
| 10 | |
| 11 | # -------------- Setup keys ------------------- |
| 12 | |
| 13 | mkdir -p ~/.ssh |
| 14 | ssh-keygen -t dsa -P "" -f .ssh/id_dsa |
| 15 | cp .ssh/id_dsa.pub .ssh/authorized_keys |
| 16 | |
| 17 | # -------------- Install Karaf ---------------- |
| 18 | |
| 19 | mkdir Applications |
| 20 | cd Applications |
| 21 | wget http://apache.osuosl.org/karaf/3.0.2/apache-karaf-3.0.2.zip |
| 22 | unzip apache-karaf-3.0.2.zip |
| 23 | cd - |
| 24 | |
| 25 | #--------------- Setup Docker env ------------ |
| 26 | |
| 27 | mkdir -p docker/onos-tutorial |
| 28 | cd docker/onos-tutorial |
| 29 | cat > Dockerfile << EOF |
| 30 | FROM ubuntu-upstart:14.10 |
| 31 | MAINTAINER Ali Al-Shabibi <ali@onlab.us> |
| 32 | RUN apt-get update && apt-get install -y openjdk-8-jre openssh-server |
| 33 | RUN mkdir /var/run/sshd |
| 34 | RUN echo 'root:onosrocks' | chpasswd |
| 35 | RUN sed -i 's/PermitRootLogin without-password/PermitRootLogin yes/' /etc/ssh/sshd_config |
| 36 | # SSH login fix. Otherwise user is kicked off after login |
| 37 | RUN sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd |
| 38 | ENV NOTVISIBLE "in users profile" |
| 39 | RUN echo "export VISIBLE=now" >> /etc/profile |
| 40 | EXPOSE 22 6633 |
| 41 | CMD ["/sbin/init"] |
| 42 | EOF |
| 43 | |
| 44 | sudo docker build -t onos/tutorial-dist . |
| 45 | |
| 46 | cd - |
| 47 | |
| 48 | # -------------- Download ONOS ---------------- |
| 49 | |
| 50 | git clone https://gerrit.onosproject.org/onos |
| 51 | |
| 52 | echo ". ~/onos/tools/dev/bash_profile" >> ~/.bashrc |
| 53 | echo "export ONOS_USER=root" >> ~/.bashrc |
alshabib | 42beadc | 2014-12-09 00:01:26 -0800 | [diff] [blame^] | 54 | echo "sudo docker run --name onos-1 -d -P onos/tutorial-dist > /dev/null 2>&1" >> ~/.bashrc |
| 55 | echo "sudo docker run --name onos-2 -d -P onos/tutorial-dist > /dev/null 2>&1" >> ~/.bashrc |
| 56 | echo "sudo docker run --name onos-3 -d -P onos/tutorial-dist > /dev/null 2>&1" >> ~/.bashrc |
| 57 | |
| 58 | cat > onos/tools/test/cells/docker << EOF |
| 59 | export ONOS_NIC="172.17.0.*" |
| 60 | export OC1=`sudo docker inspect --format '{{ .NetworkSettings.IPAddress }}' "onos-1"` |
| 61 | export OC2=`sudo docker inspect --format '{{ .NetworkSettings.IPAddress }}' "onos-2"` |
| 62 | export OC3=`sudo docker inspect --format '{{ .NetworkSettings.IPAddress }}' "onos-3"` |
| 63 | export OCN="localhost" |
| 64 | export OCI="${OC1}" |
| 65 | 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" |
| 66 | EOF |
| 67 | |
| 68 | echo "cell docker" >> ~/.bashrc |
alshabib | 48b63e1 | 2014-12-08 23:53:03 -0800 | [diff] [blame] | 69 | |
| 70 | sed -i -e s/sdn/root/ onos/tools/package/debian/onos.conf |
| 71 | |
| 72 | cd onos && mvn clean install && cd - |
alshabib | 42beadc | 2014-12-09 00:01:26 -0800 | [diff] [blame^] | 73 | onos-package |
| 74 | |
alshabib | 48b63e1 | 2014-12-08 23:53:03 -0800 | [diff] [blame] | 75 | |
| 76 | # -------------- Setup Wireshark dissector ---- |
| 77 | |
| 78 | wget -O openflow.lua "https://gerrit.onosproject.org/gitweb?p=onos-vm.git;a=blob_plain;hb=refs/heads/onos-tutorial;f=openflow.lua" |
| 79 | mkdir -p .wireshark/plugins |
| 80 | mv openflow.lua .wireshark/plugins |
| 81 | |
| 82 | |
| 83 | |
| 84 | # -------------- Setup Desktop ---------------- |
| 85 | |
| 86 | sudo apt-get install -y xorg lxde |
| 87 | |
| 88 | #TODO: add backgrounds folder |
| 89 | sudo mkdir -p /usr/share/backgrounds |
| 90 | #TODO: change background |
| 91 | # Remove wallpaper, change background color |
| 92 | sudo sed -i 's/wallpaper_mode=1/wallpaper_mode=0/g' /usr/share/lxde/pcmanfm/LXDE.conf |
| 93 | sudo sed -i 's/desktop_bg=#000000/desktop_bg=#104187/g' /usr/share/lxde/pcmanfm/LXDE.conf |
| 94 | |
| 95 | sudo sed -i 's/lang=1/lang=0/g' /etc/lxdm/default.conf |
| 96 | sudo sed -i 's/bottom_pane=1/bottom_pane=0/g' /etc/lxdm/default.conf |
| 97 | sudo sed -i 's/disable=0/disable=1/g' /etc/lxdm/default.conf |
| 98 | |
| 99 | |
| 100 | wget -O onos.png "https://gerrit.onosproject.org/gitweb?p=onos-vm.git;a=blob_plain;hb=refs/heads/onos-tutorial;f=onos.png" |
| 101 | sudo cp onos.png /usr/share/backgrounds/default.png |
| 102 | |
| 103 | # Automatically start LXDE on login |
| 104 | echo '[[ -z $DISPLAY && $XDG_VTNR -eq 1 ]] && exec startx' >> ~/.bashrc |
| 105 | |
| 106 | # Automatically log into the VM |
| 107 | #sudo sed -i 's/exec /sbin/getty -8 38400 tty1//g' /etc/init/tty1.conf |
| 108 | #sudo sed -i '$ d' /etc/init/tty1.conf |
| 109 | #echo 'exec /bin/login -f bob < /dev/tty1 > /dev/tty1 2>&1' | sudo tee -a /etc/init/tty1.conf |
| 110 | |
| 111 | # Disable screensaver |
| 112 | sudo sed -i '/screensaver/d' /etc/xdg/lxsession/LXDE/autostart |
| 113 | cat > ${USER_HOME}/.xsessionrc << EOF |
| 114 | # disable screensaver |
| 115 | xset s off |
| 116 | # disable dpms (standby) |
| 117 | xset -dpms |
| 118 | EOF |
| 119 | |
| 120 | # Change LXTerminal default colors |
| 121 | #sudo sed -i 's/bgcolor=#000000000000/bgcolor=#ffffffffffff/g' ${USER_HOME}/.config/lxterminal/lxterminal.conf |
| 122 | #sudo sed -i 's/fgcolor=#aaaaaaaaaaaa/fgcolor=#000000000000/g' ${USER_HOME}/.config/lxterminal/lxterminal.conf |
| 123 | sudo sed -i 's/bgcolor=#000000000000/bgcolor=#ffffffffffff/g' /usr/share/lxterminal/lxterminal.conf |
| 124 | sudo sed -i 's/fgcolor=#aaaaaaaaaaaa/fgcolor=#000000000000/g' /usr/share/lxterminal/lxterminal.conf |
| 125 | |
| 126 | DESKTOP=${USER_HOME}/Desktop |
| 127 | |
| 128 | mkdir -p ${DESKTOP} |
| 129 | |
| 130 | cat > ${DESKTOP}/Mininet << EOF |
| 131 | [Desktop Entry] |
| 132 | Encoding=UTF-8 |
| 133 | Type=Application |
| 134 | Name=Mininet |
| 135 | Name[en_US]=Mininet |
| 136 | Icon=konsole |
| 137 | Exec=/usr/bin/lxterminal -e 'sudo mn --custom /home/tutorial1/onos/tools/test/topos/tower.py --topo tower --controller remote --mac' |
| 138 | Comment[en_US]= |
| 139 | EOF |
| 140 | |
| 141 | cat > ${DESKTOP}/Tutorial << EOF |
| 142 | [Desktop Entry] |
| 143 | Encoding=UTF-8 |
| 144 | Type=Application |
| 145 | Name=ONOS Tutorial |
| 146 | Name[en_US]=ONOS Tutorial |
| 147 | Icon=internet-web-browser |
| 148 | Exec=/usr/bin/chromium-browser https://wiki.onosproject.org/display/ONOS/Distributed+ONOS+Tutorial |
| 149 | Comment[en_US]= |
| 150 | EOF |
| 151 | |
| 152 | cat > ${DESKTOP}/GUI << EOF |
| 153 | [Desktop Entry] |
| 154 | Encoding=UTF-8 |
| 155 | Type=Application |
| 156 | Name=ONOS GUI |
| 157 | Name[en_US]=ONOS GUI |
| 158 | Icon=internet-web-browser |
| 159 | Exec=/usr/bin/chromium-browser http://localhost:8181/onos/ui/index.html#topo |
| 160 | Comment[en_US]= |
| 161 | EOF |
| 162 | |
| 163 | cat > ${DESKTOP}/Wireshark << EOF |
| 164 | [Desktop Entry] |
| 165 | Encoding=UTF-8 |
| 166 | Type=Application |
| 167 | Name=Wireshark |
| 168 | Name[en_US]=Wireshark |
| 169 | Icon=wireshark |
| 170 | Exec=/usr/bin/wireshark |
| 171 | Comment[en_US]= |
| 172 | EOF |
| 173 | |
| 174 | cat > ${DESKTOP}/Reset << EOF |
| 175 | [Desktop Entry] |
| 176 | Encoding=UTF-8 |
| 177 | Type=Application |
| 178 | Name=Reset |
| 179 | Name[en_US]=Reset |
| 180 | Icon=konsole |
| 181 | Exec=/usr/bin/lxterminal -t 'Resetting; please wait' -e 'sudo service onos restart' |
| 182 | Comment[en_US]= |
| 183 | EOF |
| 184 | |
| 185 | # ------------- Install Other Tools ------------- |
| 186 | sudo apt-get install -y wireshark |
| 187 | # Enable root-less wireshark and add mininet |
| 188 | echo "Enabling wireshark group" |
| 189 | echo "wireshark-common wireshark-common/install-setuid boolean true" | sudo debconf-set-selections |
| 190 | sudo dpkg-reconfigure -f noninteractive wireshark-common |
| 191 | sudo usermod -a -G wireshark mininet |
| 192 | sudo usermod -a -G wireshark tutorial1 |
| 193 | |
| 194 | |
| 195 | echo "Installing VirtualBox Guest Additions" |
| 196 | sudo apt-get install -y virtualbox-guest-x11 |
| 197 | |
| 198 | # ------------- Zero Unused Blocks ------------- |
| 199 | #TODO investigate zerofree |
| 200 | echo "Zeroing unused blocks" |
| 201 | sync |
| 202 | dd if=/dev/zero of=tmp-zeros |
| 203 | sync |
| 204 | rm tmp-zeros |
| 205 | sync |