initial commit with find function
This commit is contained in:
commit
43dc548a3d
12
functions.sh
Executable file
12
functions.sh
Executable file
@ -0,0 +1,12 @@
|
||||
miria_error() {
|
||||
echo "error: $1" 1>&2
|
||||
}
|
||||
|
||||
miria_get_url() {
|
||||
if [ -e ~/.miria-url ]; then
|
||||
miria_url="$(cat ~/.miria-url)"
|
||||
else
|
||||
echo 'error: file ~/.miria-url not found' 1>&2
|
||||
exit 1
|
||||
fi
|
||||
}
|
55
miria-find
Executable file
55
miria-find
Executable file
@ -0,0 +1,55 @@
|
||||
#!/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}
|
Loading…
Reference in New Issue
Block a user