#!/bin/sh
echo '#!/bin/sh' >/var/upgrade/upgrade1.sh
chmod 755 /var/upgrade/upgrade1.sh

if [  -d "/shares/internal/PUBLIC" ];then

  echo 'WELCOME TO THE SSH INSTALLATION On YOUR MYBOOK'>/shares/internal/PUBLIC/MBWE-SSH-ENABLE.log
  echo '---------------------------------------------------------------------'>>/shares/internal/PUBLIC/MBWE-SSH-ENABLE.log
  # test that we have Write Access on PUBLIC
  if [  -f "/shares/internal/PUBLIC/MBWE-SSH-ENABLE.log" ];then
      cd /shares/internal/PUBLIC
      echo '-Status Checking before Applying Hack  ! --------------'>>/shares/internal/PUBLIC/MBWE-SSH-ENABLE.log
      echo 'inetd.conf permissions  ! --------------'>>/shares/internal/PUBLIC/MBWE-SSH-ENABLE.log
      ls -l /etc/inetd.conf >>/shares/internal/PUBLIC/MBWE-SSH-ENABLE.log
      cat /etc/inetd.conf >>/shares/internal/PUBLIC/MBWE-SSH-ENABLE.log
      
      echo '-SSH Activation  ! --------------'>>/shares/internal/PUBLIC/MBWE-SSH-ENABLE.log
      INETDC=/etc/inetd.conf
      INETDCB=/etc/inetd.conf.bak
      cp $INETDC $INETDCB
      if [  -f "/etc/inetd.conf.bak" ];then
        sed 's/^#ssh /ssh /' < $INETDCB > $INETDC

        echo '-SSH installation Verification  ! --------------'>>/shares/internal/PUBLIC/MBWE-SSH-ENABLE.log
        cat /etc/inetd.conf >>/shares/internal/PUBLIC/MBWE-SSH-ENABLE.log

        echo '-SSH SSH will be activated at next reboot... --------------'>>/shares/internal/PUBLIC/MBWE-SSH-ENABLE.log
      else
        echo 'ERROR in copying /etc/inetd.conf to /etc/inetd.conf.bak'>>/shares/internal/PUBLIC/MBWE-SSH-ENABLE.log
        echo 'Is your system in read only mode?'>>/shares/internal/PUBLIC/MBWE-SSH-ENABLE.log
      fi
  echo '---------------------------------------------------------------------'>>/shares/internal/PUBLIC/MBWE-SSH-ENABLE.log
  chown www-data:www-data /shares/internal/PUBLIC/MBWE-SSH-ENABLE.log

  fi

fi

rm -f /tmp/active_upgrade
exit 0
