start-sftp-atmoz.sh 1.8 KB

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