copytocontainer 785 B

1234567891011121314151617181920212223
  1. #!/usr/bin/env bash
  2. [ $# -eq 0 ] && echo "Please specify one or more directories/files to copy to container (ex. vendor, --all)" && exit 1
  3. REAL_SRC=$(cd -P "src" >/dev/null && pwd)
  4. CONTAINER_ID=$(bin/docker-compose ps -q phpfpm | awk '{print $1}')
  5. for ARG in "$@"; do
  6. if [ "$ARG" == "--all" ]; then
  7. docker cp "$REAL_SRC/./" "$CONTAINER_ID":/var/www/html/
  8. echo "Completed copying all files from host to container"
  9. bin/fixowns
  10. bin/fixperms
  11. else
  12. if [ -f "$REAL_SRC/$ARG" ]; then
  13. docker cp "$REAL_SRC/$ARG" "$CONTAINER_ID":/var/www/html/"$ARG"
  14. else
  15. docker cp "$REAL_SRC/$ARG" "$CONTAINER_ID":/var/www/html/"$(dirname "$ARG")"
  16. fi
  17. echo "Completed copying $ARG from host to container"
  18. bin/fixowns "$ARG"
  19. bin/fixperms "$ARG"
  20. fi
  21. done