ZIPFILE="../$( grep "^id=" module.prop | cut -f2 -d "=" )_$( grep "^version=" module.prop | cut -f2 -d "=" ).zip" 

# correct the env script if necessary
#
#
PERL_VERSION="$( ls -d system/usr/lib/perl5/5* )"
echo "The Perl version in this Magisk Module is \"${PERL_VERSION##*/}\""
ENV_SCRIPT="system/bin/perl_env"


PERL5_VERSION_LIB="/system/usr/lib/perl5/system/usr/lib/perl5/5.44.0"

echo "Checking the file \"${ENV_SCRIPT}\" ..."
grep "^PERL5_VERSION_LIB=" "${ENV_SCRIPT}" | grep "/${PERL_VERSION}"
if [ $? -eq 0 ] ; then
	echo "The script \"${ENV_SCRIPT}\" is already okay"
else
	echo "Correcting the script ${ENV_SCRIPT} ..."
	sed -i -e "s#^PERL5_VERSION_LIB=.*#PERL5_VERSION_LIB=\"/system/usr/lib/perl5/${PERL_VERSION}\"#g" "${ENV_SCRIPT}"
fi

echo ""
echo "*** Creating the ZIP file \"${ZIPFILE}\" ..."
[ -r "${ZIPFILE}" ] && \rm -r "${ZIPFILE}"
CUR_OUTPUT="$( zip -y -r "${ZIPFILE}" . 2>&1 )"
TEMPRC=$?
if [ ${TEMPRC} != 0 ] ; then
	echo "${CUR_OUTPUT}"
	echo
	echo "Error creating the ZIP file "
else
	echo ""
	ls -l "${ZIPFILE}"
fi

