blob: c196bbe86ec926e9963e63d0f72f6a272a47ca60 [file] [log] [blame]
#!/bin/bash
# vm-setup.sh
#
# This script installs ONOS dependencies and installs a desktop environment on a Miniet VM.
export CURRENT_USER=distributed
export USER_HOME=/home/${CURRENT_USER}
IDEA_URL=http://download.jetbrains.com/idea/ideaIC-14.0.2.tar.gz
# -------------- Setup keys -------------------
mkdir -p ~/.ssh
ssh-keygen -t rsa -P "" -f .ssh/id_rsa
cp .ssh/id_rsa.pub .ssh/authorized_keys
# -------------- Install Karaf ----------------
mkdir Applications
cd Applications
wget http://apache.osuosl.org/karaf/3.0.2/apache-karaf-3.0.2.zip
unzip apache-karaf-3.0.2.zip
cd -
mkdir Downloads
cp Applications/apache-karaf-3.0.2.zip Downloads/
#--------------- Setup Docker env ------------
mkdir -p docker/onos-tutorial
cd docker/onos-tutorial
cat > Dockerfile << EOF
FROM ubuntu-upstart:14.10
MAINTAINER Ali Al-Shabibi <ali@onlab.us>
RUN apt-get update && apt-get install -y openjdk-8-jre openssh-server
RUN mkdir /var/run/sshd
RUN echo 'root:onosrocks' | chpasswd
RUN sed -i 's/PermitRootLogin without-password/PermitRootLogin yes/' /etc/ssh/sshd_config
# SSH login fix. Otherwise user is kicked off after login
RUN sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd
ENV NOTVISIBLE "in users profile"
RUN echo "export VISIBLE=now" >> /etc/profile
EXPOSE 22 6633 8181
CMD ["/sbin/init"]
EOF
sudo docker build -t onos/tutorial-dist .
cd -
# -------------- Download ONOS ----------------
git clone https://github.com/bocon13/onos-byon.git
git clone https://gerrit.onosproject.org/onos
cd onos
git checkout 1.0.0
git fetch https://gerrit.onosproject.org/onos refs/changes/07/2107/1 && git checkout FETCH_HEAD
cd -
echo "export JAVA_HOME=''"
echo ". ~/onos/tools/dev/bash_profile" >> ~/.bashrc
echo "export ONOS_USER=root" >> ~/.bashrc
sed -i -e 's/open/xdg-open/' ~/onos/tools/test/bin/onos-gui
cat > onos/tools/test/cells/docker << EOF
export ONOS_NIC="172.17.0.*"
export OC1="\$(sudo docker inspect --format '{{ .NetworkSettings.IPAddress }}' onos-1)"
export OC2="\$(sudo docker inspect --format '{{ .NetworkSettings.IPAddress }}' onos-2)"
export OC3="\$(sudo docker inspect --format '{{ .NetworkSettings.IPAddress }}' onos-3)"
export OCN="localhost"
export OCI="\${OC1}"
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"
EOF
echo "unset JAVA_HOME" >> ~/.bashrc
echo "sudo service onos stop > /dev/null 2>&1" >> ~/.bashrc
echo "cell docker > /dev/null 2>&1" >> ~/.bashrc
sed -i -e s/sdn/root/ onos/tools/package/debian/onos.conf
cd onos && mvn clean install && cd -
#--------------- set up mininet script --------
cat > ~/startmn.sh << EOF
#!/bin/bash
sudo python ~/onos/tools/test/topos/sol.py \$OC1 \$OC2 \$OC3
EOF
chmod +x ~/startmn.sh
# -------------- Setup Wireshark dissector ----
wget -O openflow.lua "https://gerrit.onosproject.org/gitweb?p=onos-vm.git;a=blob_plain;hb=refs/heads/onos-tutorial;f=openflow.lua"
mkdir -p .wireshark/plugins
mv openflow.lua .wireshark/plugins
# -------------- Setup Desktop ----------------
sudo apt-get install -y xorg lxde
#TODO: add backgrounds folder
sudo mkdir -p /usr/share/backgrounds
#TODO: change background
# Remove wallpaper, change background color
sudo sed -i 's/wallpaper_mode=1/wallpaper_mode=0/g' /usr/share/lxde/pcmanfm/LXDE.conf
sudo sed -i 's/desktop_bg=#000000/desktop_bg=#104187/g' /usr/share/lxde/pcmanfm/LXDE.conf
sudo sed -i 's/lang=1/lang=0/g' /etc/lxdm/default.conf
sudo sed -i 's/bottom_pane=1/bottom_pane=0/g' /etc/lxdm/default.conf
sudo sed -i 's/disable=0/disable=1/g' /etc/lxdm/default.conf
wget -O onos.png "https://gerrit.onosproject.org/gitweb?p=onos-vm.git;a=blob_plain;hb=refs/heads/onos-tutorial;f=onos.png"
sudo cp onos.png /usr/share/backgrounds/default.png
# Automatically start LXDE on login
echo '[[ -z $DISPLAY && $XDG_VTNR -eq 1 ]] && exec startx' >> ~/.bashrc
# Automatically log into the VM
#sudo sed -i 's/exec /sbin/getty -8 38400 tty1//g' /etc/init/tty1.conf
#sudo sed -i '$ d' /etc/init/tty1.conf
#echo 'exec /bin/login -f bob < /dev/tty1 > /dev/tty1 2>&1' | sudo tee -a /etc/init/tty1.conf
# Disable screensaver
sudo sed -i '/screensaver/d' /etc/xdg/lxsession/LXDE/autostart
cat > ${USER_HOME}/.xsessionrc << EOF
# disable screensaver
xset s off
# disable dpms (standby)
xset -dpms
EOF
# Change LXTerminal default colors
#sudo sed -i 's/bgcolor=#000000000000/bgcolor=#ffffffffffff/g' ${USER_HOME}/.config/lxterminal/lxterminal.conf
#sudo sed -i 's/fgcolor=#aaaaaaaaaaaa/fgcolor=#000000000000/g' ${USER_HOME}/.config/lxterminal/lxterminal.conf
sudo sed -i 's/bgcolor=#000000000000/bgcolor=#ffffffffffff/g' /usr/share/lxterminal/lxterminal.conf
sudo sed -i 's/fgcolor=#aaaaaaaaaaaa/fgcolor=#000000000000/g' /usr/share/lxterminal/lxterminal.conf
DESKTOP=${USER_HOME}/Desktop
mkdir -p ${DESKTOP}
cat > ${DESKTOP}/IntelliJ << EOF
[Desktop Entry]
Encoding=UTF-8
Type=Application
Name=IntelliJ
Name[en_US]=IntelliJ
Icon=/home/distributed/Applications/idea/bin/idea.png
Exec=/home/distributed/Applications/idea/bin/idea.sh
Comment[en_US]=
EOF
cat > ${DESKTOP}/Tutorial << EOF
[Desktop Entry]
Encoding=UTF-8
Type=Application
Name=ONOS Tutorial
Name[en_US]=ONOS Tutorial
Icon=internet-web-browser
Exec=/usr/bin/chromium-browser https://wiki.onosproject.org/display/ONOS/Distributed+ONOS+Tutorial
Comment[en_US]=
EOF
cat > ${DESKTOP}/Wireshark << EOF
[Desktop Entry]
Encoding=UTF-8
Type=Application
Name=Wireshark
Name[en_US]=Wireshark
Icon=wireshark
Exec=/usr/bin/wireshark
Comment[en_US]=
EOF
cat > ${DESKTOP}/Terminal << EOF
[Desktop Entry]
Encoding=UTF-8
Name=LXTerminal
TryExec=lxterminal
Exec=lxterminal
Icon=lxterminal
Type=Application
Categories=GTK;Utility;TerminalEmulator;
EOF
# ------------- Install Other Tools -------------
sudo apt-get install -y wireshark
# Enable root-less wireshark and add mininet
echo "Enabling wireshark group"
echo "wireshark-common wireshark-common/install-setuid boolean true" | sudo debconf-set-selections
sudo dpkg-reconfigure -f noninteractive wireshark-common
sudo usermod -a -G wireshark mininet
sudo usermod -a -G wireshark tutorial1
echo "Installing VirtualBox Guest Additions"
sudo apt-get install -y virtualbox-guest-x11
sudo apt-get install -y git-review
cd ~/Applications
wget -c -N -O /tmp/idea.tar.gz ${IDEA_URL}
tar xzf /tmp/idea.tar.gz
sudo mv idea-IC-139.659.2 idea
cd -
sudo apt-get clean
# ------------- Zero Unused Blocks -------------
#TODO investigate zerofree
echo "Zeroing unused blocks"
sync
dd if=/dev/zero of=tmp-zeros
sync
rm tmp-zeros
sync