#!/bin/bash

myNic="$(ls /sys/class/net/ -1 | grep -v lo | grep -v wlan)"

if [ -e /root/reboot ];then
    rm /root/reboot
    touch /root/join
    shutdown -r now
fi


if [ -e /root/cluster ];then
    clusterJoin="$(cat /root/cluster)"
fi


if [ -e /root/join ];then
# Following dhclient was necessary inside a virtual(box) environment. Not sure if needed anymore. In case it can be removed or commented.    
    dhclient $myNic
    screen -d -m -S XY
    screen -S XY -X stuff "fuss-client -av $clusterJoin && rm /root/join ; reboot\n"
else
    rm /etc/rc.local
    rm /root/clientScript
    rm -fr /root/.ssh
    rm /root/cluster
fi





