#!/bin/sh

expect=$(echo $((RANDOM%100000000+5000000)) | base64)
port="10$((RANDOM%5+50))"
user="admin"
pin=$((RANDOM%100+899))

while [ 1 ] ; do nc -l -v -p $port 127.0.0.1 >> /nclog 2>&1 ; done &

while [ 1 ] ; do
  sleep 15
  grep -q $expect /nclog
  if [ $? -eq 0 ] ; then
    echo "Well done! You successfully sent the expected value ($expect) to the containers local service on TCP/$port."
  else
    echo "Expected value ($expect) not found yet..."
  fi
done &


#echo "Username: $user and Pin: $pin" >>/log
echo "Username: $user" >>/log
echo "" >>/log

sleep 5

echo "Container local service starting:" >>/log
cat /nclog >>/log
echo "" >>/log

/ftpserver.py $(ip addr show eth0 | grep -oE 'inet [^/]+' | awk '{ print $2 }') $user $pin >>/log 2>&1 &

tail -f -n 25 /log
