-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathduplicate
executable file
·156 lines (147 loc) · 5.58 KB
/
duplicate
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#!/bin/bash
PROGRAM=$(basename "$0")
PROGRAM_PATH=$(dirname "$0")
CONFIG_PATH="${PROGRAM_PATH}/config"
OLD_IFS=${IFS}
LANGUAGES=(de-de en-asia en-au en-ca en-gb en-ie en-sg en-us es-es es-us fr-ca fr-fr it-it pl-pl pt-pt)
OVERWRITE_SUBS='de en es fr it pl pt'
OVERWRITE_MODE=body
MANAGER=(
"de-de::https://www.ovh.com/auth/?action=gotomanager\&from=https://www.ovh.de/\&ovhSubsidiary=de"
"en-asia::https://ca.ovh.com/auth/?action=gotomanager\&from=https://www.ovh.com/asia/\&ovhSubsidiary=asia"
"en-au::https://ca.ovh.com/auth/?action=gotomanager\&from=https://www.ovh.com.au/\&ovhSubsidiary=au"
"en-ca::https://ca.ovh.com/auth/?action=gotomanager\&from=https://www.ovh.com/ca/en/\&ovhSubsidiary=ca"
"en-gb::https://www.ovh.com/auth/?action=gotomanager\&from=https://www.ovh.co.uk/\&ovhSubsidiary=GB"
"en-ie::https://www.ovh.com/auth/?action=gotomanager\&from=https://www.ovh.ie/\&ovhSubsidiary=ie"
"en-sg::https://ca.ovh.com/auth/?action=gotomanager\&from=https://www.ovh.com/sg/\&ovhSubsidiary=sg"
"en-us::https://ca.ovh.com/auth/?action=gotomanager\&from=https://www.ovh.com/world/\&ovhSubsidiary=we"
"es-es::https://www.ovh.com/auth/?action=gotomanager\&from=https://www.ovh.es/\&ovhSubsidiary=es"
"es-us::https://ca.ovh.com/auth/?action=gotomanager\&from=https://www.ovh.com/world/\&ovhSubsidiary=ws"
"fr-ca::https://ca.ovh.com/auth/?action=gotomanager\&from=https://www.ovh.com/ca/fr/\&ovhSubsidiary=qc"
"fr-fr::https://www.ovh.com/auth/?action=gotomanager\&from=https://www.ovh.com/fr/\&ovhSubsidiary=fr"
"it-it::https://www.ovh.com/auth/?action=gotomanager\&from=https://www.ovh.it/\&ovhSubsidiary=it"
"pl-pl::https://www.ovh.com/auth/?action=gotomanager\&from=https://www.ovh.pl/\&ovhSubsidiary=pl"
"pt-pt::https://www.ovh.com/auth/?action=gotomanager\&from=https://www.ovh.pt/\&ovhSubsidiary=pt"
)
OVHCLOUD_LANG=(
"de-de::de"
"en-asia::asia"
"en-au::en-au"
"en-ca::en-ca"
"en-gb::en-gb"
"en-ie::en-ie"
"en-sg::en-sg"
"en-us::en"
"es-es::es-es"
"es-us::es"
"fr-ca::fr-ca"
"fr-fr::fr"
"it-it::it"
"pl-pl::pl"
"pt-pt::pt"
)
OVHDOCS_LANG=(
"de-de::de"
"en-asia::asia/en"
"en-au::au/en"
"en-ca::ca/en"
"en-gb::gb/en"
"en-ie::ie/en"
"en-sg::sg/en"
"en-us::us/en"
"es-es::es"
"es-us::us/es"
"fr-ca::ca/fr"
"fr-fr::fr"
"it-it::it"
"pl-pl::pl"
"pt-pt::pt"
)
update_link_subs(){
for i in "${MANAGER[@]}";do
if [[ "${i%%::*}" == "${GUIDE_SUB}" ]];then
SEARCH="${i##*::}"
fi
if [[ "${i%%::*}" == "${LANG}" ]];then
REPLACE="${i##*::}"
fi
done
sed -i '' "s,${SEARCH},${REPLACE},g" "${TARGET}"
for i in "${OVHCLOUD_LANG[@]}";do
if [[ "${i%%::*}" == "${GUIDE_SUB}" ]];then
SEARCH="www.ovhcloud.com/${i##*::}"
fi
if [[ "${i%%::*}" == "${LANG}" ]];then
REPLACE="www.ovhcloud.com/${i##*::}"
fi
done
sed -i '' "s,${SEARCH},${REPLACE},g" "${TARGET}"
for i in "${OVHDOCS_LANG[@]}";do
if [[ "${i%%::*}" == "${GUIDE_SUB}" ]];then
SEARCH="docs.ovh.com/${i##*::}"
fi
if [[ "${i%%::*}" == "${LANG}" ]];then
REPLACE="docs.ovh.com/${i##*::}"
fi
done
sed -i '' "s,${SEARCH},${REPLACE},g" "${TARGET}"
}
git rev-parse --is-inside-work-tree > /dev/null
GIT_ROOT="$(git rev-parse --show-toplevel)"
cd "${GIT_ROOT}"
find "${GIT_ROOT}" -type f -name "duplicate.task" | while read tasks
do
cat "${tasks}" | while read task
do
GUIDE_SUB=$(echo "${task}" | awk -F ":" '{print $1}')
GUIDE_CONFIG=$(echo "${task}" | awk -F ":" '{print $2}')
GUIDE_OVERWRITE=$(echo "${task}" | awk -F ":" '{print $3}')
GUIDE=$(dirname ${tasks})/guide.${GUIDE_SUB}.md
[[ -f "${GUIDE_CONFIG}" ]] && source "${CONFIG_PATH}/${GUIDE_CONFIG}"
[[ -n "${GUIDE_OVERWRITE}" ]] && eval "${GUIDE_OVERWRITE}"
LANGUAGES=("${LANGUAGES[@]/$GUIDE_SUB}")
for LANG in ${LANGUAGES[@]}
do
TARGET="$(dirname ${GUIDE})/guide.${LANG}.md"
echo "GUIDE: ${GUIDE#${GIT_ROOT}\/}"
echo "TARGET: ${TARGET#${GIT_ROOT}\/}"
if [[ -f "${TARGET}" && "${OVERWRITE_MODE}" == "body" && $(echo "${OVERWRITE_SUBS}" | grep -ow "${LANG::2}" | wc -w) != 0 ]];then
TARGET_FM=$(sed -n '1,/---/p' "${TARGET}")
sed -e '1,/---/d' "${GUIDE}" > "${TARGET}"
update_link_subs && wait
CONTENT=$(echo "${TARGET_FM}" && cat "${TARGET}")
echo "${CONTENT}" > "${TARGET}"
GUIDE_UPDATED_KEY=$(grep -Eo "^updated: [0-9]{4}(-[0-9]{2}){2}$" "${GUIDE}")
TARGET_UPDATED_KEY=$(grep -Eo "^updated: [0-9]{4}(-[0-9]{2}){2}$" "${TARGET}")
sed -i '' "2,/---/ s/${TARGET_UPDATED_KEY}/${GUIDE_UPDATED_KEY}/" "${TARGET}"
else
cp -f "${GUIDE}" "${TARGET}"
update_link_subs && wait
if [[ "${GUIDE_SUB::2}" != "${LANG::2}" ]];then
for i in "${OVHDOCS_LANG[@]}";do
if [[ "${i%%::*}" == "${GUIDE_SUB}" ]];then
CANONICAL_LANG="${i##*::}"
fi
done
CANONICAL_URL="https://docs.ovh.com/${CANONICAL_LANG}/"
IFS='/' read -r -a arr <<< "${GUIDE}"
p=''
for d in "${arr[@]}"
do
p+="${d}/"
if [[ -f "${p}product.${GUIDE_SUB}.md" ]];then
CANONICAL_URL+=$(cat "${p}product.${GUIDE_SUB}.md" | sed -n '2,/---/p' | awk -F ": " '/^slug: / {print $2}' | tr -d "\r")/
fi
done
CANONICAL_URL+=$(cat "${GUIDE}" | sed -n '2,/---/p' | awk -F ": " '/^slug: / {print $2}')/
sed -i '' "2,/---/ s;---;routes:\n canonical: '${CANONICAL_URL}'\n---;" "${TARGET}"
echo "CANONICAL_URL: ${CANONICAL_URL}"
IFS=${OLD_IFS}
fi
fi
echo
done
done && wait
rm -f ${tasks}
echo
done