#!/usr/bin/with-contenv bash

ALPINE_VER=$(cat /etc/apk/repositories | grep main | sed 's|.*alpine/v||' | sed 's|/main.*||')
if [ "${ALPINE_VER}" = "3.14" ]; then
    PIP_ARGS="-f https://wheel-index.linuxserver.io/alpine/"
else
    PIP_ARGS="-f https://wheel-index.linuxserver.io/alpine-${ALPINE_VER}/"
fi

echo "**** Installing required packages ****"
apk add --no-cache \
    ffmpeg \
    imagemagick \
    supervisor \
    py3-numpy \
    py3-pillow \
    py3-asn1crypto

echo "**** Installing optional packages ****"
apk add --no-cache \
    py3-cffi \
    py3-scipy \
    py3-pynacl \
    py3-cryptography \
    py3-pip

if [ $(arch) = "armv7l" ]; then
    echo "**** Installing build deps for pillow_heif on arm32v7, compiling pillow_heif may take a long time in the next step ****"
    apk add --no-cache \
        python3-dev \
        libtool \
        git \
        gcc \
        m4 \
        perl \
        alpine-sdk \
        cmake \
        aom-dev
fi

echo "**** Installing pillow_heif, hexhamming and pywavelets ****"
python3 -m pip install -U pip wheel setuptools
python3 -m pip install ${PIP_ARGS} pillow_heif hexhamming pywavelets
