#/bin/bash

printf "\n========== Cloudlet tools installation ==========\n"
printf "\n +++ novnc/websockify\n "
sudo dnf -y install epel-release
sudo dnf -y install novnc.noarch
sudo dnf -y install python3
sudo ln -s /usr/bin/python3 /usr/bin/python
sudo python3 -m pip install --upgrade pip setuptools

# not clear why the websockify does not install into /usr/local with the first install, but it does the second time.
# /usr/local is necessary if you don't want to modify the container start script
sudo python3 -m pip install --prefix /usr/local websockify
sudo python3 -m pip uninstall -y websockify
sudo python3 -m pip install --prefix /usr/local websockify

printf "\n +++ install podman\n"
sudo dnf -y install podman

printf "\n +++ install buildah\n"
sudo dnf -y install buildah

printf "\n +++ SELinux updates for Cloudlet\n"
# the container_manage_cgroup boolean is availabl after the podman install
# Allows podman to handle cgroups to set scope
sudo setsebool -P container_manage_cgroup true 
# Allows podman network to talk to host network
sudo setsebool -P httpd_can_network_relay 1
# Allows podman to open reserved (<1000) ports
sudo setsebool -P httpd_can_network_connect 1

# do not disable SELinux - leaving here as debug placeholder
#sudo setenforce 0
#sudo sed -i 's/enforcing/disabled/g' /etc/selinux/config

#Get EPAD/SciEdge/Cloudlet public repo
printf "\n+++ Get public repo\n"
sudo mkdir /opt/ern
sudo git clone https://github.com/mghpcc/SciEdge.git /opt/ern/SciEdge
sudo chown root:root /opt/ern/SciEdge/etc/ood/config/ood_portal.yml
sudo chmod 0600 /opt/ern/SciEdge/etc/ood/config/ood_portal.yml

printf "\n ========= End Cloudlet tools installation ========\n "
