################################################################################ # Copyright 2022 Antonin Portelli # # This file is part of miria-cli. # # miria-cli is free software: you can redistribute it and/or modify it under # the terms of the GNU General Public License as published by the Free Software # Foundation, either version 3 of the License, or (at your option) any # later version. # # miria-cli is distributed in the hope that it will be useful, but WITHOUT ANY # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along with # miria-cli. If not, see . ################################################################################ #!/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 -n [-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