Jonathan Hart | 7b6cfef | 2015-03-27 10:09:38 -0700 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # onos-setup-lxc.sh |
| 3 | # |
| 4 | # This script sets up the VM ready to run ONOS and tutorials, including installing an LXC cluster |
| 5 | # for ONOS to run in. |
| 6 | |
Jonathan Hart | b1e2211 | 2015-03-31 16:42:03 -0700 | [diff] [blame] | 7 | function create_user { |
| 8 | local name=$1 |
| 9 | local description=$2 |
| 10 | |
| 11 | sudo /usr/sbin/useradd -c "$description" -d /home/$name -U -m -p $(openssl passwd -1 $name) -s /bin/bash $name |
| 12 | echo "$name ALL=(ALL) NOPASSWD:ALL" >> $name |
| 13 | sudo mv $name /etc/sudoers.d |
| 14 | sudo chown root:root /etc/sudoers.d/$name |
| 15 | sudo usermod -aG wireshark $name |
| 16 | |
| 17 | sudo mkdir /home/$name/.ssh |
| 18 | sudo chown $name:$name /home/$name/.ssh |
| 19 | sudo cp /home/mininet/.ssh/id_rsa /home/$name/.ssh/ |
| 20 | sudo chown $name:$name /home/$name/.ssh/id_rsa |
| 21 | |
| 22 | sudo -u $name sh -c "echo \"export ONOS_ROOT=/home/mininet/onos\" >> /home/$name/.bashrc" |
| 23 | sudo -u $name sh -c "echo \". /home/mininet/onos/tools/dev/bash_profile\" >> /home/$name/.bashrc" |
| 24 | |
| 25 | sudo -u $name ssh -o "StrictHostKeyChecking no" sdn@10.0.3.11 ls |
| 26 | sudo -u $name ssh -o "StrictHostKeyChecking no" sdn@10.0.3.12 ls |
| 27 | sudo -u $name ssh -o "StrictHostKeyChecking no" sdn@10.0.3.13 ls |
| 28 | } |
| 29 | |
Jonathan Hart | b1e2211 | 2015-03-31 16:42:03 -0700 | [diff] [blame] | 30 | # ------------- Set up desktop environment ------------- |
| 31 | |
| 32 | # Remove kernel boot options that will prevent the gui from running |
| 33 | sudo sed -i s/text// /etc/default/grub |
| 34 | sudo sed -i s/ipv6.disable=1// /etc/default/grub |
| 35 | sudo update-grub |
| 36 | |
| 37 | sudo apt-get install -y xorg lxde systemd-shim |
| 38 | |
| 39 | #TODO: add backgrounds folder |
| 40 | sudo mkdir -p /usr/share/backgrounds |
| 41 | #TODO: change background |
| 42 | # Remove wallpaper, change background color |
| 43 | sudo sed -i 's/wallpaper_mode=1/wallpaper_mode=0/g' /usr/share/lxde/pcmanfm/LXDE.conf |
| 44 | sudo sed -i 's/desktop_bg=#000000/desktop_bg=#104187/g' /usr/share/lxde/pcmanfm/LXDE.conf |
| 45 | |
| 46 | sudo sed -i 's/lang=1/lang=0/g' /etc/lxdm/default.conf |
| 47 | sudo sed -i 's/bottom_pane=1/bottom_pane=0/g' /etc/lxdm/default.conf |
| 48 | sudo sed -i 's/disable=0/disable=1/g' /etc/lxdm/default.conf |
| 49 | |
| 50 | # Allow VM to be rebooted from GUI |
| 51 | echo "session required pam_systemd.so" | sudo tee --append /etc/pam.d/lxdm |
| 52 | |
| 53 | wget -O onos.png "https://gerrit.onosproject.org/gitweb?p=onos-vm.git;a=blob_plain;hb=refs/heads/onos-tutorial;f=onos.png" |
| 54 | sudo cp onos.png /usr/share/backgrounds/default.png |
| 55 | |
| 56 | # Change LXTerminal default colors |
| 57 | sudo sed -i 's/bgcolor=#000000000000/bgcolor=#ffffffffffff/g' /usr/share/lxterminal/lxterminal.conf |
| 58 | sudo sed -i 's/fgcolor=#aaaaaaaaaaaa/fgcolor=#000000000000/g' /usr/share/lxterminal/lxterminal.conf |
| 59 | |
| 60 | # Disable screensaver |
| 61 | sudo sed -i '/screensaver/d' /etc/xdg/lxsession/LXDE/autostart |
| 62 | cat > /home/mininet/.xsessionrc << EOF |
| 63 | # disable screensaver |
| 64 | xset s off |
| 65 | # disable dpms (standby) |
| 66 | xset -dpms |
| 67 | EOF |
| 68 | |
Jonathan Hart | f5a22f4 | 2015-03-31 17:44:40 -0700 | [diff] [blame^] | 69 | echo $PATH |
| 70 | |
| 71 | # -------------- Install ONOS ---------------- |
| 72 | |
| 73 | USER=mininet |
| 74 | USER_HOME=/home/${USER} |
| 75 | |
| 76 | echo `whoami` |
| 77 | |
| 78 | cd ~ |
| 79 | git clone https://gerrit.onosproject.org/onos |
| 80 | cd onos && git checkout onos-1.1 && cd - |
| 81 | |
| 82 | mkdir -p ~/Downloads |
| 83 | |
| 84 | echo $PATH |
| 85 | |
| 86 | echo "export ONOS_ROOT=${USER_HOME}/onos" >> ~/.bashrc |
| 87 | echo ". ~/onos/tools/dev/bash_profile" >> ~/.bashrc |
| 88 | |
| 89 | export ONOS_ROOT=${USER_HOME}/onos |
| 90 | . ~/onos/tools/dev/bash_profile |
| 91 | |
| 92 | echo $PATH |
| 93 | |
| 94 | echo $ONOS_ROOT |
| 95 | |
| 96 | echo $JAVA_HOME |
| 97 | export JAVA_HOME="" |
| 98 | cd $ONOS_ROOT && mvn clean install && mvn dependency:go-offline && cd - |
| 99 | |
| 100 | cat << EOF >> onos/tools/test/cells/3node |
| 101 | export ONOS_NIC=10.0.3.* |
| 102 | export OC1="10.0.3.11" |
| 103 | export OC2="10.0.3.12" |
| 104 | export OC3="10.0.3.13" |
| 105 | export OCI="${OC1}" |
| 106 | export ONOS_FEATURES="webconsole,onos-rest,onos-gui,onos-api,onos-core,onos-cli,onos-openflow" |
| 107 | export ONOS_USER="sdn" |
| 108 | EOF |
| 109 | |
| 110 | cat << EOF >> onos/tools/test/cells/1node |
| 111 | export ONOS_NIC=10.0.3.* |
| 112 | export OC1="10.0.3.11" |
| 113 | export OCI="${OC1}" |
| 114 | export ONOS_FEATURES="webconsole,onos-rest,onos-gui,onos-api,onos-core,onos-cli,onos-openflow" |
| 115 | export ONOS_USER="sdn" |
| 116 | EOF |
| 117 | |
| 118 | cell 3node |
| 119 | |
| 120 | echo $PATH |
| 121 | |
| 122 | onos-package |
| 123 | onos-group install -f |
| 124 | onos-wait-for-start $OC1 |
| 125 | onos-wait-for-start $OC2 |
| 126 | onos-wait-for-start $OC3 |
| 127 | |
| 128 | sleep 20 |
| 129 | onos-service --cell status |
| 130 | |
| 131 | echo $PATH |
| 132 | |
Jonathan Hart | b1e2211 | 2015-03-31 16:42:03 -0700 | [diff] [blame] | 133 | # ------------- Set up each tutorial ------------- |
| 134 | |
| 135 | create_user tutorial1 "Basic ONOS Tutorial" |
Jonathan Hart | f5a22f4 | 2015-03-31 17:44:40 -0700 | [diff] [blame^] | 136 | |
| 137 | URL='https://gerrit.onosproject.org/gitweb?p=onos-vm.git;a=blob_plain;hb=refs/heads/new-onos-tutorial;f=tutorial1-setup-lxc.sh' |
Jonathan Hart | b1e2211 | 2015-03-31 16:42:03 -0700 | [diff] [blame] | 138 | wget -O tutorial1-setup-lxc.sh $URL |
| 139 | sudo -u ${CURRENT_USER} -H sh -c 'cp tutorial1-setup-lxc.sh ~/ && cd ~/ && sh tutorial1-setup-lxc.sh' |
Jonathan Hart | 97b8121 | 2015-03-27 11:19:22 -0700 | [diff] [blame] | 140 | |
| 141 | # ------------- Zero Unused Blocks ------------- |
| 142 | #TODO investigate zerofree |
Jonathan Hart | c3f5a14 | 2015-03-30 16:42:37 -0700 | [diff] [blame] | 143 | #echo "Zeroing unused blocks" |
| 144 | #sync |
| 145 | #dd if=/dev/zero of=tmp-zeros |
| 146 | #sync |
| 147 | #rm tmp-zeros |
| 148 | #sync |