#!/bin/sh -efu

. girar-sh-functions

usage()
{
	echo >&2 "$PROG: $*"
	echo >&2 "usage: $PROG <pocket package repository name>"
	exit 1
}

[ "$#" -ge 1 ] ||
	usage 'Not enough arguments.'
[ "$#" -le 1 ] ||
	usage 'Too many arguments.'

pocket="$1"; shift

# Returns:
# 0 - $pocket base repo file exists;
# 1 - otherwise.
# stdout = pocket base repository name

[ -n "${GIRAR_USER-}" ] ||
	fatal 'GIRAR_USER undefined'

GIRAR_POCKET_REPO_DIR="$GIRAR_POCKETS/$pocket"

[ -d "${GIRAR_POCKET_REPO_DIR-}" ] ||
	fatal 'GIRAR_POCKET_REPO_DIR is either undefined or invalid'

GIRAR_POCKET_BASE_REPO_FILE="$GIRAR_POCKET_REPO_DIR/files/pocket/repo"

[ -f "${GIRAR_POCKET_BASE_REPO_FILE-}" ] ||
	fatal "$GIRAR_POCKET_REPO_DIR/files/pocket/repo file not exists"

repo=$(cat "$GIRAR_POCKET_BASE_REPO_FILE")

printf %s "$repo"
