53 lines
1.2 KiB
Bash
Executable File
53 lines
1.2 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
set -uoe pipefail
|
|
|
|
script_dir=$(dirname $(readlink -f $0))
|
|
source ${script_dir}/functions.sh
|
|
miria_get_url
|
|
|
|
print_usage() {
|
|
echo "usage: $(basename $0) -p <project> -n <pattern> [-x]" 1>&2
|
|
echo "" 1>&2
|
|
echo "flags:" 1>&2
|
|
echo " -p: project name in Miria archive" 1>&2
|
|
echo " -n: file pattern (use * as wildcard)" 1>&2
|
|
echo " -x: show raw XML answer" 1>&2
|
|
}
|
|
|
|
project=''
|
|
pattern=''
|
|
xml='false'
|
|
while getopts 'xp:n:' flag; do
|
|
case "${flag}" in
|
|
p) project="${OPTARG}" ;;
|
|
n) pattern="${OPTARG}" ;;
|
|
x) xml='true' ;;
|
|
*) print_usage
|
|
exit 1 ;;
|
|
esac
|
|
done
|
|
if [[ -z "${project}" ]]; then
|
|
miria_error "missing -p flag"
|
|
print_usage
|
|
exit 1
|
|
fi
|
|
if [[ -z "${pattern}" ]]; then
|
|
miria_error "missing -n flag"
|
|
print_usage
|
|
exit 1
|
|
fi
|
|
base="$(basename "${pattern}")"
|
|
dir="$(dirname "${pattern}")"
|
|
if [[ "${dir}" == "." ]]; then
|
|
dir=''
|
|
fi
|
|
miria_api_cmd fileSearch "filename=${base}" "path=${project}@/${dir}"
|
|
if [[ "${xml}" == "true" ]]; then
|
|
echo "${miria_last_xml}"
|
|
else
|
|
miria_xml_get_attribute "${miria_last_xml}" '//file' 'name' \
|
|
| sed -E "s/archive@${project}://g" \
|
|
| sed -E 's/\/\//\//g'
|
|
fi
|