-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathlisting.sh
More file actions
executable file
·43 lines (34 loc) · 1.03 KB
/
listing.sh
File metadata and controls
executable file
·43 lines (34 loc) · 1.03 KB
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
43
#!/usr/bin/dash
# Based upon http://stackoverflow.com/a/21960296/4534
s3ns=http://s3.amazonaws.com/doc/2006-03-01/
tmp=$(mktemp)
while read s3url
do
test "$s3url" || continue
i=0
# Normalise URL
s3url=$(curl $s3url -s -L -I -o /dev/null -w '%{url_effective}')
s3get=$s3url # s3get gets marker requests appended to it
while :; do
curl -f -s $s3get > "$tmp$i.xml"
if test $? -ne 0
then
echo ERROR $? retrieving: $s3get 1>&2
break
fi
xml sel -N w="http://s3.amazonaws.com/doc/2006-03-01/" -T -t -m "//w:Key" -o "${s3url%/}/" -v . -n "$tmp$i.xml"
nextkey=$(xml sel -T -N "w=$s3ns" -t \
--if '/w:ListBucketResult/w:IsTruncated="true"' \
-v 'str:encode-uri(/w:ListBucketResult/w:Contents[last()]/w:Key, true())' \
-b -n "$tmp$i.xml")
# -b -n adds a newline to the result unconditionally,
# this avoids the "no XPaths matched" message; $() drops newlines.
rm -f "$tmp$i.xml"
if [ -n "$nextkey" ] ; then
s3get=$(echo $s3get | sed "s/[?].*//")"?marker=$nextkey"
i=$((i+1))
else
break
fi
done
done