56 lines
1.2 KiB
Bash
Executable File
56 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
|
|
tmp_xml="$(mktemp)"
|
|
base="$(basename "${pattern}")"
|
|
dir="$(dirname "${pattern}")"
|
|
if [[ "${dir}" == "." ]]; then
|
|
dir=''
|
|
fi
|
|
curl -s "${miria_url}/fileSearch?filename=${base}&path=${project}@/${dir}" > ${tmp_xml}
|
|
if [[ "${xml}" == "true" ]]; then
|
|
cat ${tmp_xml}
|
|
else
|
|
xmllint --xpath '//file/@name' ${tmp_xml} \
|
|
| sed -E 's/ *name="(.+)"/\1/g' \
|
|
| sed -E "s/archive@${project}://g" \
|
|
| sed -E 's/\/\//\//g'
|
|
fi
|
|
rm -f ${tmp_xml}
|