start-sftp-atmoz.sh 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #!/usr/bin/env bash
  2. #
  3. # ownCloud
  4. #
  5. # This script start a docker container to test the files_external tests
  6. # against. It will also change the files_external config to use the docker
  7. # container as testing environment. This is reverted in the stop step.W
  8. #
  9. # Set environment variable DEBUG to print config file
  10. #
  11. # @author Morris Jobke
  12. # @copyright 2015 Morris Jobke <hey@morrisjobke.de>
  13. #
  14. if ! command -v docker >/dev/null 2>&1; then
  15. echo "No docker executable found - skipped docker setup"
  16. exit 0;
  17. fi
  18. echo "Docker executable found - setup docker"
  19. echo "Fetch recent atmoz/sftp docker image"
  20. docker pull atmoz/sftp
  21. # retrieve current folder to place the config in the parent folder
  22. thisFolder=`echo $0 | sed 's#env/start-sftp-atmoz\.sh##'`
  23. if [ -z "$thisFolder" ]; then
  24. thisFolder="."
  25. fi;
  26. user=test
  27. password=12345
  28. container=`docker run -d atmoz/sftp $user:$password:1001`
  29. host=`docker inspect --format="{{.NetworkSettings.IPAddress}}" $container`
  30. cat > $thisFolder/config.sftp.php <<DELIM
  31. <?php
  32. return array(
  33. 'run'=>true,
  34. 'host'=>'$host',
  35. 'user'=>'$user',
  36. 'password'=>'$password',
  37. 'root'=>'upload',
  38. );
  39. DELIM
  40. echo "sftp container: $container"
  41. # put container IDs into a file to drop them after the test run (keep in mind that multiple tests run in parallel on the same host)
  42. echo $container >> $thisFolder/dockerContainerAtmoz.$EXECUTOR_NUMBER.sftp
  43. echo -n "Waiting for sftp initialization"
  44. if ! "$thisFolder"/env/wait-for-connection ${host} 22 60; then
  45. echo "[ERROR] Waited 60 seconds, no response" >&2
  46. exit 1
  47. fi
  48. sleep 1
  49. if [ -n "$DEBUG" ]; then
  50. cat $thisFolder/config.sftp.php
  51. cat $thisFolder/dockerContainerAtmoz.$EXECUTOR_NUMBER.sftp
  52. fi
  53. # create folder "upload" with correct permissions
  54. docker exec $container bash -c "mkdir /home/$user/upload && chown $user:users /home/$user/upload"