#!/bin/sh

if [ -z "$1" ]; then
	echo "Usage: $0 <fpm>"
	exit 1
fi

FPM="$1"

if [ ! -f "$FPM" ]; then
	echo "$FPM does not exist."
	exit 1
fi

HELPER="$(dirname "$0")/dumpabi-helper"

if [ ! -f "$HELPER" ]; then
	echo "Helper binary cannot be found."
	exit 1
fi

export LC_ALL=C

DIR="$(mktemp -td)"

tar -C "$DIR" -x -f "$FPM"

chmod -R 0777 "$DIR"

"$HELPER" "$DIR"

rm -rf "$DIR"
