#!/bin/sh -e

# TODO: verify checksum before extracting
# SUM
# TODO: extract self without resolving to $0 because it doesn't resolve links
tail -c +"$(expr BYTES + 1)" $0 | lz4 -dc | tar -x
# TODO: remove hardcoded directory
# TODO: use a different extraction path
cd ID

export ORIGIN="$(pwd)"
export LD_LIBRARY_PATH="$ORIGIN/lib"
export PATH="$ORIGIN/bin":$PATH

#export LD_DEBUG='libs'

# TODO: use $0 instead
# FIXME: uses the system's basename
exec bin/"$(basename "$1")"