#!/bin/sh -efu

# Toplevel cron select-task/run-task runner.

GB_REPO_NAME="$1"; shift
export GB_REPO_NAME

# Ensure that only one instance is running for the given repo.
lockdir="$HOME/.lockdir/$USER-$GB_REPO_NAME"
mkdir -p "$lockdir"
enable -f /usr/lib/bash/lockf lockf
builtin lockf -n "$lockdir" || exit 0
exec >> "$lockdir/log" 2>&1

# Set cwd to directory with scripts and configs.
GB_HOME="${0%/*}"
[ "$GB_HOME" != "$0" ]
cd "$GB_HOME"
export GB_HOME

# Add path to scripts to $PATH.
PATH="$PWD:$PATH"

. gb-sh-functions

rc=
"$@" || rc=$?
