blob: 3cf275ee3cb794442b5b626a6deba3db3c23f901 [file] [log] [blame]
#!/bin/bash
# onos-setup.sh
#
# Runs as mininet user.
#
# This script sets up the desktop environment, installs ONOS in the LXC cluster,
# then creates a user for each tutorial and runs the tutorial setup script.
function create_user {
local name=$1
local description=$2
sudo /usr/sbin/useradd -c "$description" -d /home/$name -U -m -p $(openssl passwd -1 $name) -s /bin/bash $name
echo "$name ALL=(ALL) NOPASSWD:ALL" >> $name
sudo mv $name /etc/sudoers.d
sudo chown root:root /etc/sudoers.d/$name
sudo usermod -aG wireshark $name
sudo usermod -aG mininet $name
sudo mkdir /home/$name/.ssh
sudo chown $name:$name /home/$name/.ssh
sudo cp /home/mininet/.ssh/id_rsa /home/$name/.ssh/
sudo chown $name:$name /home/$name/.ssh/id_rsa
sudo -u $name sh -c "echo \"export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64\" >> /home/$name/.bashrc"
sudo -u $name sh -c "echo \"export ONOS_ROOT=/home/mininet/onos\" >> /home/$name/.bashrc"
sudo -u $name sh -c "echo \"export KARAF_ROOT=/home/mininet/apache-karaf-3.0.3\" >> /home/$name/.bashrc"
sudo -u $name sh -c "echo \"export M2_REPO=/home/mininet/.m2/repository\" >> /home/$name/.bashrc"
sudo -u $name sh -c "echo \". /home/mininet/onos/tools/dev/bash_profile\" >> /home/$name/.bashrc"
sudo -u $name ssh -o "StrictHostKeyChecking no" sdn@10.0.3.11 ls
sudo -u $name ssh -o "StrictHostKeyChecking no" sdn@10.0.3.12 ls
sudo -u $name ssh -o "StrictHostKeyChecking no" sdn@10.0.3.13 ls
sudo mkdir -p /home/$name/.wireshark/plugins
sudo cp /home/mininet/openflow.lua /home/$name/.wireshark/plugins
sudo chown -R $name:$name /home/$name/.wireshark
}
# ------------- Set up desktop environment -------------
echo "Setting up desktop environment"
# Remove kernel boot options that will prevent the gui from running
sudo sed -i s/text// /etc/default/grub
sudo sed -i s/ipv6.disable=1// /etc/default/grub
sudo update-grub
sudo apt-get install -y xorg lxde systemd-shim
#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
# Allow VM to be rebooted from GUI
echo "session required pam_systemd.so" | sudo tee --append /etc/pam.d/lxdm
wget -O onos.png "https://gerrit.onosproject.org/gitweb?p=onos-vm.git;a=blob_plain;hb=refs/heads/onos-tutorial-1.1;f=onos.png"
sudo cp onos.png /usr/share/backgrounds/default.png
# Change LXTerminal default colors
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
# Disable screensaver
sudo sed -i '/screensaver/d' /etc/xdg/lxsession/LXDE/autostart
cat > /home/mininet/.xsessionrc << EOF
# disable screensaver
xset s off
# disable dpms (standby)
xset -dpms
EOF
echo "Enabling non-root wireshark"
echo "wireshark-common wireshark-common/install-setuid boolean true" | sudo debconf-set-selections
sudo dpkg-reconfigure -f noninteractive wireshark-common
# Get the wireshark dissector handy
wget -O /home/mininet/openflow.lua "https://gerrit.onosproject.org/gitweb?p=onos-vm.git;a=blob_plain;hb=refs/heads/onos-tutorial-1.1;f=openflow.lua"
# -------------- Install ONOS ----------------
echo "Installing ONOS"
USER=mininet
USER_HOME=/home/${USER}
cd ~
# Download a local karaf so we can use the bin directory
wget http://archive.apache.org/dist/karaf/3.0.3/apache-karaf-3.0.3.tar.gz
tar -xzf apache-karaf-3.0.3.tar.gz
git clone https://gerrit.onosproject.org/onos
cd onos && git checkout 1.2.1 && cd -
mkdir -p ~/Downloads
echo "export ONOS_ROOT=${USER_HOME}/onos" >> ~/.bashrc
echo "export KARAF_ROOT=${USER_HOME}/apache-karaf-3.0.3" >> ~/.bashrc
echo ". ~/onos/tools/dev/bash_profile" >> ~/.bashrc
export ONOS_ROOT=${USER_HOME}/onos
export KARAF_ROOT=${USER_HOME}/apache-karaf-3.0.3
. ~/onos/tools/dev/bash_profile
echo $ONOS_ROOT
echo $JAVA_HOME
export JAVA_HOME="/usr/lib/jvm/java-8-openjdk-amd64"
cd $ONOS_ROOT && mvn clean install && mvn dependency:go-offline && cd -
# Get the sample apps and build them for the right version
git clone https://gerrit.onosproject.org/onos-app-samples
cd onos-app-samples
git checkout 52da58b5991049025ce1b599c000357500b00aef
mvn versions:set -DnewVersion=1.2.1 versions:commit
mvn clean install
cd ..
cat << EOF >> onos/tools/test/cells/3node
export ONOS_NIC=10.0.3.*
export OC1="10.0.3.11"
export OC2="10.0.3.12"
export OC3="10.0.3.13"
export OCI="10.0.3.11"
export ONOS_FEATURES="webconsole,onos-rest,onos-gui,onos-api,onos-core,onos-cli,onos-openflow"
export ONOS_APPS="drivers,openflow"
export ONOS_USER="sdn"
EOF
cat << EOF >> onos/tools/test/cells/1node
export ONOS_NIC=10.0.3.*
export OC1="10.0.3.11"
export OCI="10.0.3.11"
export ONOS_FEATURES="webconsole,onos-rest,onos-gui,onos-api,onos-core,onos-cli,onos-openflow"
export ONOS_APPS="drivers,openflow"
export ONOS_USER="sdn"
EOF
cell 3node
onos-package
onos-group install -f
onos-wait-for-start $OC1
onos-wait-for-start $OC2
onos-wait-for-start $OC3
echo "ONOS install and startup complete"
sleep 1
onos-service --cell status
# Prevent ONOS services from starting automatically
sudo sh -c "echo manual >> /var/lib/lxc/onos1/rootfs/etc/init/onos.override"
sudo sh -c "echo manual >> /var/lib/lxc/onos2/rootfs/etc/init/onos.override"
sudo sh -c "echo manual >> /var/lib/lxc/onos3/rootfs/etc/init/onos.override"
# ------------- Create reset scripts -------------
cat << EOF >> ${USER_HOME}/reset-to-1.sh
#!/bin/bash
sudo rm -rf /tmp/*
export ONOS_ROOT=/home/mininet/onos
export M2_REPO=/home/mininet/.m2/repository
export KARAF_TAR=/home/mininet/apache-karaf-3.0.3.tar.gz
. ${ONOS_ROOT}/tools/dev/bash_profile
. ${ONOS_ROOT}/tools/build/envDefaults
sudo mn -c
cell 3node
onos-service --cell stop
cell 1node
if [ -n "\$1" ]; then
export ONOS_APPS=\$ONOS_APPS,\$1
fi
onos-package
onos-install -f '$OC1'
EOF
sudo chmod 777 ${USER_HOME}/reset-to-1.sh
cat << EOF >> ${USER_HOME}/reset-to-3.sh
#!/bin/bash
sudo rm -rf /tmp/*
export ONOS_ROOT=/home/mininet/onos
export M2_REPO=/home/mininet/.m2/repository
export KARAF_TAR=/home/mininet/apache-karaf-3.0.3.tar.gz
. ${ONOS_ROOT}/tools/dev/bash_profile
. ${ONOS_ROOT}/tools/build/envDefaults
sudo mn -c
cell 3node
if [ -n "\$1" ]; then
export ONOS_APPS=\$ONOS_APPS,\$1
fi
onos-service --cell stop
onos-package
onos-install -f '$OC1'
onos-install -f '$OC2'
onos-install -f '$OC3'
EOF
sudo chmod 777 ${USER_HOME}/reset-to-3.sh
sudo apt-get clean
sudo rm /etc/apt/apt.conf.d/02proxy
# ------------- Set up each tutorial -------------
create_user tutorial1 "Basic ONOS Tutorial"
URL='https://gerrit.onosproject.org/gitweb?p=onos-vm.git;a=blob_plain;hb=refs/heads/onos-tutorial-1.1;f=tutorial1-setup.sh'
wget -O tutorial1-setup.sh $URL
sudo -u tutorial1 -H sh -c 'cp tutorial1-setup.sh ~/ && cd ~/ && sh tutorial1-setup.sh'
create_user sdnip "SDN-IP Tutorial"
SDNIP_URL='https://gerrit.onosproject.org/gitweb?p=onos-vm.git;a=blob_plain;hb=refs/heads/onos-tutorial-1.1;f=sdnip-setup.sh'
wget -O sdnip-setup.sh $SDNIP_URL
sudo -u sdnip -H sh -c 'cp sdnip-setup.sh ~/ && cd ~/ && sh sdnip-setup.sh'
create_user distributed "Distributed Tutorial"
DIST_URL='https://gerrit.onosproject.org/gitweb?p=onos-vm.git;a=blob_plain;hb=refs/heads/onos-tutorial-1.1;f=dist-setup.sh'
wget -O dist-setup.sh $DIST_URL
sudo -u distributed -H sh -c 'cp dist-setup.sh ~/ && cd ~/ && sh dist-setup.sh'
create_user optical "Optical Tutorial"
OPT_URL='https://gerrit.onosproject.org/gitweb?p=onos-vm.git;a=blob_plain;hb=refs/heads/onos-tutorial-1.1;f=opt-setup.sh'
wget -O opt-setup.sh $OPT_URL
sudo -u optical -H sh -c 'cp opt-setup.sh ~/ && cd ~/ && sh opt-setup.sh'
# ------------- Zero Unused Blocks -------------
#TODO investigate zerofree
echo "Zeroing unused blocks"
sync
dd if=/dev/zero of=tmp-zeros
sync
rm tmp-zeros
sync