-
Notifications
You must be signed in to change notification settings - Fork 16
/
getMetadata.sh
executable file
·136 lines (118 loc) · 2.83 KB
/
getMetadata.sh
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#!/bin/bash
###
### Script for getting Alfresco Metadata files (Bulk Import) for a given downloaded Alfresco folder structure
###
rawurlencode() {
local string="${1}"
local strlen=${#string}
local encoded=''
local pos c o dot_enc
if [ "$2" == 'yes' ]; then
dot_enc='yes'
fi
for (( pos=0 ; pos<strlen ; pos++ )); do
c=${string:$pos:1}
case "$c" in
[_~1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-])
o="${c}"
;;
[.])
if [[ "$dot_enc" == "yes" ]]; then
o=$(printf "$c" | xxd -plain | tr -d '\n' | sed 's/\(..\)/%\1/g')
else
o="${c}"
fi
;;
*)
o=$(printf "$c" | xxd -plain | tr -d '\n' | sed 's/\(..\)/%\1/g')
esac
encoded+="${o}"
done
echo "$encoded"
return 0
}
rawurldecode() {
# This is perhaps a risky gambit, but since all escape characters must be
# encoded, we can replace %NN with \xNN and pass the lot to printf -b, which
# will decode hex for us
printf -v decoded '%b' "${1//%/\\x}"
echo "${decoded}"
return 0
}
urlencode() {
# urlencode <string>
old_lc_collate=$LC_COLLATE
LC_COLLATE=C
local length="${#1}"
for (( i = 0; i < length; i++ )); do
local c="${1:i:1}"
case $c in
[a-zA-Z0-9.~_-]) printf "$c" ;;
*) printf '%%%02X' "'$c" ;;
esac
done
LC_COLLATE=$old_lc_collate
}
urldecode() {
# urldecode <string>
local url_encoded="${1//+/ }"
printf '%b' "${url_encoded//%/\\x}"
}
# Usage functions
usage() { echo "Usage: $0 [-f <local-webdav-folder>]" 1>&2; exit 1; }
# Command line options
while getopts "u:p:he:f:" o; do
case "${o}" in
u)
MYUSER=${OPTARG}
;;
p)
MYPASS=${OPTARG}
;;
e)
URL=${OPTARG}
;;
f)
FOLDER=${OPTARG}
;;
\?)
echo "Invalid Option: -$OPTARG" 1>&2
exit 1
;;
h)
usage
;;
*)
usage
;;
esac
done
shift $((OPTIND-1))
# Exports ALFALFURL,MYUSER,MYPASS
source ./exportENVARS.sh
# Default parameters
#ALFURL=${ALFURL:-http://localhost:8080/alfresco}
#MYUSER=${MYUSER:-admin}
#MYPASS=${MYPASS:-admin}
if [ -z "${ALFURL}" ] || [ -z "${MYUSER}" ] || [ -z "${MYPASS}" ]; then
usage
fi
# Needs at least -f as parameter
if [ -z "${FOLDER}" ]; then
usage
fi
SAVEIFS=$IFS
IFS=$(echo -en "\n\b")
for f in `find $FOLDER`
do
#inp=`echo "$f" | sed -e 's#^webdav##'`
inp=`rawurlencode "$f" | sed -e 's#^webdav##'`
out=`rawurldecode "$inp"`
echo "Getting metadata file for path: $inp"
#echo "f : $f"
#echo "inp : $inp"
#echo "out : $out"
#echo "fld : $f.metadata.properties.xml"
curl -k -s -u $MYUSER:$MYPASS "$ALFURL/service/net/zylk/export-bulk-metadata?path=$inp" > "$f.metadata.properties.xml"
done
IFS=$SAVEIFS