1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
|
#!/bin/bash
#set -xe
usage(){
echo "Usage: $0 [option]" >&2
echo
echo " -h, --help show this help"
echo " -u, --username username for basic authentication"
echo " -p, --password password for basic authentication"
echo " -H, --baseurl URL of Nexus instance "
echo " -r, --reponame name of the repository to list "
echo " -q, --query string to search to filter the results "
echo
}
while getopts ":hu:p:H:r:q:" opt; do
case $opt in
h | --help) usage; exit 0 >&2;;
u | --username) username=$OPTARG;;
p | --password) password=$OPTARG;;
H | --baseurl) baseurl=$OPTARG;;
r | --reponame) reponame=$OPTARG;;
q | --query) filter=$OPTARG;;
\?)
echo "Invalid option: -$OPTARG" >&2
exit 1
;;
:)
echo "Option -$OPTARG requires an argument." >&2
exit 1
;;
esac
done
url=${baseurl}/service/rest/v1/script/repoassetslister/run
curl -s -XPOST -u ${username}:${password} ${url} \
-H "Content-Type: text/plain" \
-d "{\"repoName\":\"${reponame}\", \"startDate\":\"1970-01-01\"}" \
| jq .result | tr ',' '\n' | grep ${filter} | tr -d '\\\"[]{}' | sed s#assets:##g
|