#!/usr/bin/env bash
# Inspired by https://medium.com/@patnaikshekhar/initialize-your-aks-nodes-with-daemonsets-679fa81fd20e

# Copy installation scripts and files to host
cp /ship-to/* /host
cp /tmp/install.sh /host  

/usr/bin/nsenter -m/proc/1/ns/mnt -- chmod u+x /tmp/install/wait.sh
/usr/bin/nsenter -m/proc/1/ns/mnt -- chmod u+x /tmp/install/install.sh

# Wait for Node updates to complete
/usr/bin/nsenter -m/proc/1/ns/mnt /tmp/install/wait.sh

# If the /tmp folder is mounted on the host then it can run the script
/usr/bin/nsenter --all --target 1 /tmp/install/install.sh

# Sleep 30 seconds, then exit
echo "Waiting for 30 seconds..."
sleep 30
echo "Task Completed"