#!/bin/sh -efu

. girar-sh-functions
PROG='girar-task approve'

usage()
{
	[ -z "$*" ] || message "$*"
	echo >&2 "usage: $PROG <task_id> <subtask_number>"
	exit 1
}

if [ "${1-}" = '--help' ]; then
	usage
fi

if [ "$#" -gt 2 ]; then
	usage 'Too many arguments.'
fi

if [ "$#" -lt 2 ]; then
	usage 'Not enough arguments.'
fi

id=$(PROG="$PROG" girar-task-find-current "$1"); shift
num="$1"; shift

cd "$GB_TASKS/$id"

for i in $(gear_nums); do
	[ -d "acl/$i" -a 'all' = "$num" -o "$i" = "$num" ] ||
		continue
	touch "acl/$i/$GIRAR_USER"
	[ 'all' = "$num" ] ||
		exit
done
[ 'all' = "$num" ] ||
	fatal "task #$id: subtask #$num not found"
