FROM debian:bullseye

# Detecting zip is currently broken in libmagic1 5.39-3, see
# https://bugs.astron.com/view.php?id=228

RUN apt-get update -qq && apt-get install --yes -qq libmagic1 libmagic-dev file python3 python3-pip >/dev/null
RUN python3 -m pip install python-magic
COPY hello.zip file.py /root/
WORKDIR /root

RUN file /root/hello.zip
RUN file --mime-type /root/hello.zip
RUN python3 /root/file.py /root/hello.zip

# The fix for bug #228 above did not help for mime-type reporting via
# magic_buffer. In the current development version of file, magic_file
# reports the zip correctly, but magic_buffer doesn't.

RUN apt-get install --yes -qq build-essential libbz2-dev liblzma-dev zlib1g-dev curl autoconf automake libtool >/dev/null
RUN curl -L https://github.com/file/file/archive/refs/heads/master.tar.gz|tar -xzf -
RUN cd /root/file-master && autoreconf -fi && ./configure -q && make -s install && ldconfig
RUN python3 /root/file.py /root/hello.zip

# It appears that another magic entry in Magdir/archive used to match zip
# archives but does not anymore. Restoring the old file fixes the problem.

RUN curl https://raw.githubusercontent.com/file/file/FILE5_38/magic/Magdir/archive > /root/file-master/magic/Magdir/archive
RUN cd /root/file-master && make -s install
RUN python3 /root/file.py /root/hello.zip
