#!/bin/sh die() { printf 'Error: %s\n' "$*" >&2; exit 1; } root=$(stack path --allow-different-user --local-install-root) || die "subcommand failed: 'stack path'" bin=$root/bin/fsmgr if [ "$SKIP_BUILD" ] then if ! bin=$(which fsmgr) then prev= for bin in .stack-work/install/*/*/*/bin/fsmgr do if [ "$prev" ] && [ "$prev" -nt "$bin" ] then bin=$prev else prev=$bin fi done fi else stack build fi case "$(id -u)" in 0) exec "$bin" "$@" ;; *) exec sudo -- "$bin" "$@" ;; esac