/
rmls
executable file
·91 lines (84 loc) · 3 KB
/
rmls
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/bin/sh
. $(dirname $0)/rmcommon
# set -e -x
rmcheck
#!/bin/bash
# [[file:index.org::*getmetadataname][getmetadataname:1]]
function getmetadataname {
# echo "Looking for document name in $1"
grep visibleName $1 | sed -e 's/.*": "\?//' -e 's/"\?,*$//'
## grep visibleName $1 | sed -e 's/.*": "//' -e 's/",*$//' -e 's/ /./g'
}
# getmetadataname:1 ends here
# [[file:index.org::*getfullname][getfullname:1]]
function getfullname {
xochitl=${1}
uuid=${2}
meta="${xochitl}/${uuid}.metadata"
documentname=$(getmetadataname ${meta})
# echo Document name is $documentname
# the document may be in a folder. Use the recursive function defined
# above to extra a full path to the destination folder
folders=""
parentuuid=$(grep parent $meta \
| sed -e 's/.*": "\?//' \
-e 's/"\?,*$//' \
-e 's/null,*$// ')
## | sed -e 's/.*": "\?//' -e 's/"\?,*$//' -e 's/ /./g' )
while [[ "$parentuuid" != "" && "$parentuuid" != "null" ]]
do
if [ "$parentuuid" != "trash" ]
then
# echo ".. found folder uuid = $parentuuid"
directoryname=$(getmetadataname ${xochitl}/${parentuuid}.metadata)
# echo ".. with name $documentname"
folders="${directoryname}/${folders}"
# move up a folder
parentuuid=$(grep parent "${xochitl}/${parentuuid}.metadata" \
| sed -e 's/.*": "\?//' \
-e 's/"\?,*$//' \
-e 's/null,*$// ')
## | sed -e 's/.*": "//' -e 's/",*$//' -e 's/ /./g' )
else
folders="trash/${folders}"
parentuuid=""
fi
done
# echo "back in main, folders = $folders"
destination="${destdir}/${folders}"
echo ${destination}${documentname}
}
# getfullname:1 ends here
# [[file:index.org::*main block][main block:1]]
T=$(mktemp --tmpdir --directory "rmadd1.XXXXX")
trap "killprogress '$T'; rm -rf '$T'" 0 1 2 3 9
mkprogress "$T" "Listing files"
xochitl="$RM_XOCHITL"
N=$(find ${xochitl} -name '*.metadata' | wc -l)
i=0
if test -n "$1"; then
QUERY="$1" # should return metadata files
else
QUERY='*.metadata'
fi
for metadata in $(find ${xochitl} -name "$QUERY")
do
uuid=$(basename "${metadata}" .metadata)
# check to see if this is a file or a directory (Collection)
type=$(grep type ${metadata} | sed -e 's/^.*": "//' -e 's/",.*$//' )
# echo 'Checking type of file: ' ${metadata} 'is of type' ${type}
if [ "${type}" == "DocumentType" ]
then
fullname=$(getfullname ${xochitl} ${uuid})
lastchange=$(grep lastModified ${metadata} | sed 's/^.*"\([0-9]\{10\}\).*$/\1/')
date=$(date --date="@${lastchange}" +%Y%m%d-%H:%M:%S)
echo ${uuid} ${date} ${fullname}
fi
percent=$(awk "BEGIN{print ($i/${N})*100}")
echoprogress "$T" -S "$percent"
if test "$?" != "0" ; then
break
fi
i=$(expr $i '+' 1)
done
# main block:1 ends here