-
Notifications
You must be signed in to change notification settings - Fork 0
/
move.sh
executable file
·60 lines (56 loc) · 1.22 KB
/
move.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
#!/usr/bin/env bash
parse_yaml() {
local prefix=$2
local s
local w
local fs
s='[[:space:]]*'
w='[a-zA-Z0-9_]*'
fs="$(echo @|tr @ '\034')"
sed -ne "s|^\($s\)\($w\)$s:$s\"\(.*\)\"$s\$|\1$fs\2$fs\3|p" \
-e "s|^\($s\)\($w\)$s[:-]$s\(.*\)$s\$|\1$fs\2$fs\3|p" "$1" |
awk -F"$fs" '{
indent = length($1)/2;
vname[indent] = $2;
for (i in vname) {
if (i > indent) {
delete vname[i]
}
}
if (length($3) > 0) {
vn="";
for (i=0; i<indent; i++) {
vn=(vn)(vname[i])("_")
}
if ($2 == "targetNamespace") {
printf("%s\n", $3);
}
}
}' | sed 's/_=/+=/g'
}
rawUrlDecode() {
local string="${1}"
local length=${#string}
local encoded=""
local pos c o
for (( pos=0 ; pos<length ; pos++ )); do
c=${string:${pos}:1}
case "$c" in
[-_.~a-zA-Z0-9] ) o="${c}" ;;
* ) printf -v o '%%%02x' "'$c"; o=${o^^};
esac
encoded+="${o}"
done
echo "${encoded}"
}
cd yaml/
for i in *.yml; do
[ -f "$i" ] || break
test=$(parse_yaml "$i");
dir=serviceTemplates;
[[ -d ${dir} ]] || mkdir ${dir};
dir=${dir}/$(rawUrlDecode ${test});
[[ -d ${dir} ]] || mkdir ${dir};
mv ${i} ${dir}/${i}
done
cd ../