#!/bin/bash

sudo apt-get update
sudo apt-get -y install \
  bash-completion bridge-utils curl eog expect genisoimage gnome-terminal \
  graphviz libappconfig-perl libdbi-perl liberror-perl libexception-class-perl \
  libfile-homedir-perl libio-pty-perl libmath-round-perl libnetaddr-ip-perl \
  libnet-ip-perl libnet-ipv6addr-perl libnet-pcap-perl libnet-telnet-perl \
  libreadonly-perl libswitch-perl libsys-virt-perl libterm-readline-perl-perl \
  libxml-checker-perl libxml-dom-perl libxml-libxml-perl \
  libxml-parser-perl libxml-tidy-perl lxc lxc-templates net-tools \
  openvswitch-switch picocom pv screen tree uml-utilities virt-manager \
  virt-viewer vlan w3m wmctrl xdotool xfce4-terminal xterm lsof libvirt-clients 

mkdir /tmp/vnx-update
cd /tmp/vnx-update
rm -rf /tmp/vnx-update/vnx-*
wget http://vnx.dit.upm.es/vnx/vnx-latest.tgz
tar xfvz vnx-latest.tgz
cd vnx-*-*
sudo ./install_vnx

cd /usr/share/vnx/filesystems/
sudo vnx_download_rootfs -r vnx_rootfs_lxc_ubuntu64-22.04-v025.tgz -l -y

sudo mv /usr/share/vnx/etc/vnx.conf.sample /etc/vnx.conf
sudo sed -i 's/lxc_console_cmd=lxc-console/lxc_console_cmd=lxc-attach/' /etc/vnx.conf

echo "export XAUTHORITY=/home/upm/.Xauthority" >> ~/.bashrc
xhost +SI:localuser:root

echo "--"
echo "-- VNX installed. Close the terminal and open it again."
echo "--"
