blob: 0f8207051f29263a37964ce06d7ab259dcd818c4 [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 \". /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
}
# ------------- Set 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 $PATH
# -------------- Install ONOS ----------------
USER=mininet
USER_HOME=/home/${USER}
echo `whoami`
cd ~
git clone https://gerrit.onosproject.org/onos
cd onos && git checkout onos-1.1 && cd -
mkdir -p ~/Downloads
echo $PATH
echo "export ONOS_ROOT=${USER_HOME}/onos" >> ~/.bashrc
echo ". ~/onos/tools/dev/bash_profile" >> ~/.bashrc
export ONOS_ROOT=${USER_HOME}/onos
. ~/onos/tools/dev/bash_profile
echo $PATH
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
echo $PATH
onos-package
onos-group install -f
onos-wait-for-start $OC1
onos-wait-for-start $OC2
onos-wait-for-start $OC3
sleep 20
onos-service --cell status
echo $PATH
# ------------- 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 ${CURRENT_USER} -H sh -c 'cp tutorial1-setup-lxc.sh ~/ && cd ~/ && sh tutorial1-setup-lxc.sh'
# ------------- Zero Unused Blocks -------------
#TODO investigate zerofree
#echo "Zeroing unused blocks"
#sync
#dd if=/dev/zero of=tmp-zeros
#sync
#rm tmp-zeros
#sync