app="ympd"
version="${1:-"1.2.3"}"
name="$app-$version"
url="https://www.ympd.org/downloads/$name-armhf.tar.bz2"
archive="$(basename "$url")"
target="/opt/$name"
prefix="${PREFIX:-"/usr/local"}"

tmp_dir="$(mktemp -d)"
trap 'rm -rf "$tmp_dir"' EXIT

(
    cd "$tmp_dir"
    wget "$url"
    sudo mkdir "$target"
    sudo tar -xvf "$archive" -C "$target"
    sudo ln -s -t "$prefix/bin" "$target/ympd"
)