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 |
| 54 | |
| 55 | sed -i -e s/sdn/root/ onos/tools/package/debian/onos.conf |
| 56 | |
| 57 | cd onos && mvn clean install && cd - |
| 58 | |
| 59 | # -------------- Setup Wireshark dissector ---- |
| 60 | |
| 61 | wget -O openflow.lua "https://gerrit.onosproject.org/gitweb?p=onos-vm.git;a=blob_plain;hb=refs/heads/onos-tutorial;f=openflow.lua" |
| 62 | mkdir -p .wireshark/plugins |
| 63 | mv openflow.lua .wireshark/plugins |
| 64 | |
| 65 | |
| 66 | |
| 67 | # -------------- Setup Desktop ---------------- |
| 68 | |
| 69 | sudo apt-get install -y xorg lxde |
| 70 | |
| 71 | #TODO: add backgrounds folder |
| 72 | sudo mkdir -p /usr/share/backgrounds |
| 73 | #TODO: change background |
| 74 | # Remove wallpaper, change background color |
| 75 | sudo sed -i 's/wallpaper_mode=1/wallpaper_mode=0/g' /usr/share/lxde/pcmanfm/LXDE.conf |
| 76 | sudo sed -i 's/desktop_bg=#000000/desktop_bg=#104187/g' /usr/share/lxde/pcmanfm/LXDE.conf |
| 77 | |
| 78 | sudo sed -i 's/lang=1/lang=0/g' /etc/lxdm/default.conf |
| 79 | sudo sed -i 's/bottom_pane=1/bottom_pane=0/g' /etc/lxdm/default.conf |
| 80 | sudo sed -i 's/disable=0/disable=1/g' /etc/lxdm/default.conf |
| 81 | |
| 82 | |
| 83 | wget -O onos.png "https://gerrit.onosproject.org/gitweb?p=onos-vm.git;a=blob_plain;hb=refs/heads/onos-tutorial;f=onos.png" |
| 84 | sudo cp onos.png /usr/share/backgrounds/default.png |
| 85 | |
| 86 | # Automatically start LXDE on login |
| 87 | echo '[[ -z $DISPLAY && $XDG_VTNR -eq 1 ]] && exec startx' >> ~/.bashrc |
| 88 | |
| 89 | # Automatically log into the VM |
| 90 | #sudo sed -i 's/exec /sbin/getty -8 38400 tty1//g' /etc/init/tty1.conf |
| 91 | #sudo sed -i '$ d' /etc/init/tty1.conf |
| 92 | #echo 'exec /bin/login -f bob < /dev/tty1 > /dev/tty1 2>&1' | sudo tee -a /etc/init/tty1.conf |
| 93 | |
| 94 | # Disable screensaver |
| 95 | sudo sed -i '/screensaver/d' /etc/xdg/lxsession/LXDE/autostart |
| 96 | cat > ${USER_HOME}/.xsessionrc << EOF |
| 97 | # disable screensaver |
| 98 | xset s off |
| 99 | # disable dpms (standby) |
| 100 | xset -dpms |
| 101 | EOF |
| 102 | |
| 103 | # Change LXTerminal default colors |
| 104 | #sudo sed -i 's/bgcolor=#000000000000/bgcolor=#ffffffffffff/g' ${USER_HOME}/.config/lxterminal/lxterminal.conf |
| 105 | #sudo sed -i 's/fgcolor=#aaaaaaaaaaaa/fgcolor=#000000000000/g' ${USER_HOME}/.config/lxterminal/lxterminal.conf |
| 106 | sudo sed -i 's/bgcolor=#000000000000/bgcolor=#ffffffffffff/g' /usr/share/lxterminal/lxterminal.conf |
| 107 | sudo sed -i 's/fgcolor=#aaaaaaaaaaaa/fgcolor=#000000000000/g' /usr/share/lxterminal/lxterminal.conf |
| 108 | |
| 109 | DESKTOP=${USER_HOME}/Desktop |
| 110 | |
| 111 | mkdir -p ${DESKTOP} |
| 112 | |
| 113 | cat > ${DESKTOP}/Mininet << EOF |
| 114 | [Desktop Entry] |
| 115 | Encoding=UTF-8 |
| 116 | Type=Application |
| 117 | Name=Mininet |
| 118 | Name[en_US]=Mininet |
| 119 | Icon=konsole |
| 120 | Exec=/usr/bin/lxterminal -e 'sudo mn --custom /home/tutorial1/onos/tools/test/topos/tower.py --topo tower --controller remote --mac' |
| 121 | Comment[en_US]= |
| 122 | EOF |
| 123 | |
| 124 | cat > ${DESKTOP}/Tutorial << EOF |
| 125 | [Desktop Entry] |
| 126 | Encoding=UTF-8 |
| 127 | Type=Application |
| 128 | Name=ONOS Tutorial |
| 129 | Name[en_US]=ONOS Tutorial |
| 130 | Icon=internet-web-browser |
| 131 | Exec=/usr/bin/chromium-browser https://wiki.onosproject.org/display/ONOS/Distributed+ONOS+Tutorial |
| 132 | Comment[en_US]= |
| 133 | EOF |
| 134 | |
| 135 | cat > ${DESKTOP}/GUI << EOF |
| 136 | [Desktop Entry] |
| 137 | Encoding=UTF-8 |
| 138 | Type=Application |
| 139 | Name=ONOS GUI |
| 140 | Name[en_US]=ONOS GUI |
| 141 | Icon=internet-web-browser |
| 142 | Exec=/usr/bin/chromium-browser http://localhost:8181/onos/ui/index.html#topo |
| 143 | Comment[en_US]= |
| 144 | EOF |
| 145 | |
| 146 | cat > ${DESKTOP}/Wireshark << EOF |
| 147 | [Desktop Entry] |
| 148 | Encoding=UTF-8 |
| 149 | Type=Application |
| 150 | Name=Wireshark |
| 151 | Name[en_US]=Wireshark |
| 152 | Icon=wireshark |
| 153 | Exec=/usr/bin/wireshark |
| 154 | Comment[en_US]= |
| 155 | EOF |
| 156 | |
| 157 | cat > ${DESKTOP}/Reset << EOF |
| 158 | [Desktop Entry] |
| 159 | Encoding=UTF-8 |
| 160 | Type=Application |
| 161 | Name=Reset |
| 162 | Name[en_US]=Reset |
| 163 | Icon=konsole |
| 164 | Exec=/usr/bin/lxterminal -t 'Resetting; please wait' -e 'sudo service onos restart' |
| 165 | Comment[en_US]= |
| 166 | EOF |
| 167 | |
| 168 | # ------------- Install Other Tools ------------- |
| 169 | sudo apt-get install -y wireshark |
| 170 | # Enable root-less wireshark and add mininet |
| 171 | echo "Enabling wireshark group" |
| 172 | echo "wireshark-common wireshark-common/install-setuid boolean true" | sudo debconf-set-selections |
| 173 | sudo dpkg-reconfigure -f noninteractive wireshark-common |
| 174 | sudo usermod -a -G wireshark mininet |
| 175 | sudo usermod -a -G wireshark tutorial1 |
| 176 | |
| 177 | |
| 178 | echo "Installing VirtualBox Guest Additions" |
| 179 | sudo apt-get install -y virtualbox-guest-x11 |
| 180 | |
| 181 | # ------------- Zero Unused Blocks ------------- |
| 182 | #TODO investigate zerofree |
| 183 | echo "Zeroing unused blocks" |
| 184 | sync |
| 185 | dd if=/dev/zero of=tmp-zeros |
| 186 | sync |
| 187 | rm tmp-zeros |
| 188 | sync |