#!/usr/bin/with-contenv bash

# This is an install script that is designed to run after init-mods-package-install
# so it can take advantage of packages installed
# init-mods-end depends on this script so that later init and services wait until this script exits

echo "*** Removing existing par2cmdline packages ***"
if apk list --installed -q | grep par2cmdline &> /dev/null; then
    apk del --purge -q par2cmdline
fi

ARCH=$(uname -m)
if [[ -d "/par2cmdline-turbo/${ARCH}" ]]; then
    echo "**** Installing par2cmdline-turbo ****"
    cp -a /par2cmdline-turbo/${ARCH}/* /
    rm -rf /par2cmdline-turbo
else
    echo "**** par2cmdline-turbo already installed or platform unsupported ****"
fi
