#!/bin/bash

# make a directory for output files and make it writable to all
mkdir -p `pwd`/output && chmod -R 0777 `pwd`/output
# build the Dockerfile into an image
sudo docker build . -f Dockerfile -t ffmpeg-windows-build-helpers-image
# create a new container of an image, and execute the container OR start it if it were stopped
sudo docker run -d --name ffmpegbuilder -it ffmpeg-windows-build-helpers-image || docker start ffmpegbuilder -i
# after it has completed, copy the output back to the host
sudo docker cp ffmpegbuilder:/ffmpeg-windows-build-helpers/sandbox/redist/. `pwd`/output
# stop the container and remove it
sudo docker stop ffmpegbuilder && docker rm ffmpegbuilder && docker image rm -f ffmpeg-windows-build-helpers-image
# remove all unused docker resources (confirming Y)
echo "y" | sudo docker system prune -a
