forked from zylklab/alfresco-export-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetMetadata.sh
88 lines (76 loc) · 1.82 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
#!/bin/bash
###
### Script for getting Alfresco Metadata files (Bulk Import) for a given downloaded Alfresco folder structure
###
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=`urlencode "$f" | sed -e 's#^webdav##'`
out=`urldecode "$inp"`
echo "Getting metadata file for path: $inp"
curl -s -u $MYUSER:$MYPASS "$ALFURL/service/net/zylk/export-bulk-metadata?path=$inp" > "./webdav/$out.metadata.properties.xml"
done
IFS=$SAVEIFS