blob: 14110f4279ab7e86436d94afa48b58f2f08db260 [file] [log] [blame]
#!/bin/bash
# onos-setup-lxc.sh
#
# This script sets up the VM ready to run ONOS and tutorials, including installing an LXC cluster
# for ONOS to run in.
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 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 ONOS_ROOT=/home/mininet/onos\" >> /home/$name/.bashrc"
sudo -u $name sh -c "echo \"export KARAF_ROOT=/home/mininet/apache-karaf-3.0.2\" >> /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;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/new-onos-tutorial;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.2/apache-karaf-3.0.2.tar.gz
tar -xzf apache-karaf-3.0.2.tar.gz
git clone https://gerrit.onosproject.org/onos
cd onos && git checkout onos-1.1 && cd -
mkdir -p ~/Downloads
echo "export ONOS_ROOT=${USER_HOME}/onos" >> ~/.bashrc
echo "export KARAF_ROOT=${USER_HOME}/apache-karaf-3.0.2" >> ~/.bashrc
echo ". ~/onos/tools/dev/bash_profile" >> ~/.bashrc
export ONOS_ROOT=${USER_HOME}/onos
export KARAF_ROOT=${USER_HOME}/apache-karaf-3.0.2
. ~/onos/tools/dev/bash_profile
echo $ONOS_ROOT
echo $JAVA_HOME
export JAVA_HOME=""
cd $ONOS_ROOT && mvn clean install && mvn dependency:go-offline && 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="${OC1}"
export ONOS_FEATURES="webconsole,onos-rest,onos-gui,onos-api,onos-core,onos-cli,onos-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="${OC1}"
export ONOS_FEATURES="webconsole,onos-rest,onos-gui,onos-api,onos-core,onos-cli,onos-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
export ONOS_ROOT=/home/mininet/onos
. ${ONOS_ROOT}/tools/dev/bash_profile
. ${ONOS_ROOT}/tools/build/envDefaults
cell 3node
onos-service --cell stop
cell 1node
onos-package
onos-install -f $OC1
EOF
cat << EOF >> ${USER_HOME}/reset-to-3.sh
#!/bin/bash
export ONOS_ROOT=/home/mininet/onos
. ${ONOS_ROOT}/tools/dev/bash_profile
. ${ONOS_ROOT}/tools/build/envDefaults
cell 3node
onos-service --cell stop
onos-package
onos-install -f $OC1
onos-install -f $OC2
onos-install -f $OC3
EOF
# ------------- 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/new-onos-tutorial;f=tutorial1-setup-lxc.sh'
wget -O tutorial1-setup-lxc.sh $URL
sudo -u tutorial1 -H sh -c 'cp tutorial1-setup-lxc.sh ~/ && cd ~/ && sh tutorial1-setup-lxc.sh'
create_user sdnip "SDN-IP Tutorial"
SDNIP_URL='https://gerrit.onosproject.org/gitweb?p=onos-vm.git;a=blob_plain;hb=refs/heads/new-onos-tutorial;f=sdnip-setup-lxc.sh'
wget -O sdnip-setup-lxc.sh $SDNIP_URL
sudo -u ${SDN_IP_USER} -H sh -c 'cp sdnip-setup-lxc.sh ~/ && cd ~/ && sh sdnip-setup-lxc.sh'
create_user distributed "Distributed Tutorial"
create_user optical "Optical Tutorial"
# ------------- Zero Unused Blocks -------------
#TODO investigate zerofree
echo "Zeroing unused blocks"
sync
dd if=/dev/zero of=tmp-zeros
sync
rm tmp-zeros
sync