forked from 2600hz/kazoo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkz_diaspora.bash
executable file
·303 lines (265 loc) · 7.47 KB
/
kz_diaspora.bash
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
#!/bin/bash -e
pushd "$(dirname "$0")" >/dev/null
ROOT="$(pwd -P)"/..
replace() {
local M0=$1
local F0=$2
local M1=$3
local F1=$4
for FILE in $(grep -Irl $M0:$F0 "$ROOT"/{core,applications}); do
sed -i "s%$M0:$F0%$M1:$F1%g" "$FILE"
done
}
replace_call() {
FROM="$1"
TO="$2"
OLD_FUN="$3"
NEW_FUN="${3%$4}"
FILE="$5"
#echo "s/$FROM:$OLD_FUN/$TO:$NEW_FUN/g"
sed -i "s%$FROM:$OLD_FUN%$TO:$NEW_FUN%g" "$FILE"
}
search_and_replace() {
declare -a FUNS=("${!1}")
FROM="$2"
TO="$3"
SUFFIX="$4"
for FUN in "${FUNS[@]}"; do
for FILE in $(grep -Irl $FROM:$FUN "$ROOT"/{core,applications}); do
replace_call $FROM $TO "$FUN" "$SUFFIX" "$FILE"
done
done
}
search_and_replace_exact() {
declare -a FUNS=("${!1}")
FROM=$2
TO=$3
TOFUN=$4
for FUN in "${FUNS[@]}"; do
for FILE in `grep -rl "$FROM:$FUN" $ROOT/{core,applications}`; do
replace $FROM $TO "$FUN" "$TOFUN" $FILE
done
done
}
replace_call_prefix() {
FROM="$1"
TO="$2"
OLD_FUN="$3"
NEW_FUN="${3#$4}"
FILE="$5"
#echo "s/$FROM:$OLD_FUN/$TO:$NEW_FUN/g"
sed -i "s%$FROM:$OLD_FUN%$TO:$NEW_FUN%g" "$FILE"
}
search_and_replace_prefix() {
declare -a FUNS=("${!1}")
FROM="$2"
TO="$3"
PREFIX="$4"
for FUN in "${FUNS[@]}"; do
for FILE in $(grep -Irl $FROM:$FUN "$ROOT"/{core,applications}); do
replace_call_prefix $FROM $TO "$FUN" "$PREFIX" "$FILE"
done
done
}
replace_call_with_prefix() {
FROM="$1"
TO="$2"
OLD_FUN="$3"
NEW_FUN="$4$3"
FILE="$5"
#echo "s/$FROM:$OLD_FUN/$TO:$NEW_FUN/g"
sed -i "s%$FROM:$OLD_FUN%$TO:$NEW_FUN%g" "$FILE"
}
search_and_replace_with_prefix() {
declare -a FUNS=("${!1}")
FROM="$2"
TO="$3"
PREFIX="$4"
for FUN in "${FUNS[@]}"; do
for FILE in $(grep -Irl $FROM:$FUN "$ROOT"/{core,applications}); do
replace_call_with_prefix $FROM $TO "$FUN" "$PREFIX" "$FILE"
done
done
}
# Functions moved from kz_util into more appropriately-named modules
# Run this to convert references from kz_util:* to the new module names
kz_util_to_term() {
local fs=(shuffle_list
to_integer
to_float
to_number
to_hex
to_hex_binary
to_hex_char
to_list
to_binary
to_atom
to_boolean
to_date
to_datetime
to_lower_binary
to_lower_string
to_upper_binary
to_upper_string
to_upper_char
to_lower_char
error_to_binary
is_true
is_false
is_boolean
is_ne_binary
is_empty
is_not_empty
is_proplist
identity
always_true
always_false
a1hash
floor
ceiling
)
search_and_replace fs[@] kz_util kz_term ''
}
kz_util_to_binary() {
local fs=(rand_hex_binary
hexencode_binary
from_hex_binary
ucfirst_binary
lcfirst_binary
strip_binary
strip_left_binary
strip_right_binary
suffix_binary
truncate_binary
truncate_left_binary
truncate_right_binary
from_hex_string
clean_binary
remove_white_spaces
binary_md5
pad_binary
pad_binary_left
join_binary
binary_reverse
)
local special=(binary_md5 binary_reverse)
search_and_replace fs[@] kz_util kz_binary _binary
search_and_replace special[@] kz_util kz_binary binary_
search_and_replace_prefix special[@] kz_binary kz_binary binary_
}
kz_util_to_time() {
local fs=(current_tstamp
current_unix_tstamp
decr_timeout
elapsed_ms
elapsed_ms
elapsed_s
elapsed_s
elapsed_us
elapsed_us
format_date
format_datetime
format_time
gregorian_seconds_to_unix_seconds
iso8601
microseconds_to_seconds
milliseconds_to_seconds
month
now
now_ms
now_s
now_us
pad_month
pretty_print_datetime
pretty_print_elapsed_s
rfc1036
unitfy_seconds
unix_seconds_to_gregorian_seconds
unix_timestamp_to_gregorian_seconds
weekday
)
search_and_replace fs[@] kz_util kz_time ''
}
kz_time_to_date() {
local fs=(iso8601_date)
local fs2=(pad_date
pad_month
)
search_and_replace_exact fs[@] "kz_time" "kz_date" "to_iso8601_extended"
search_and_replace fs2[@] "kz_time" "kz_date" ""
}
kz_json_to_kz_doc() {
local fs=(get_public_keys
public_fields
private_fields
is_private_key
)
search_and_replace fs[@] kz_json kz_doc ''
}
kz_json_to_kz_http() {
local fs=(to_querystring)
search_and_replace_with_prefix fs[@] kz_json kz_http_util json_
}
props_to_kz_http() {
local fs=(to_querystring)
search_and_replace_with_prefix fs[@] props kz_http_util props_
}
kapps_speech_to_kazoo_speech() {
local fs=(create)
local asrs=(asr_freeform
asr_commands
)
search_and_replace fs[@] kapps_speech kazoo_tts ''
search_and_replace_prefix asrs[@] kapps_speech kazoo_asr asr_
}
kz_media_recording_to_kzc_recording() {
FROM=kz_media_recording
TO=kzc_recording
for FILE in $(grep -Irl $FROM: "$ROOT"/{core,applications}); do
replace_call $FROM $TO '' '' "$FILE"
done
}
kz_includes() {
INCLUDES=(kz_databases.hrl
kz_log.hrl
kz_types.hrl
)
FROM=kazoo/include
TO=kazoo_stdlib/include
for FILE in $(grep -Irl $FROM/ "$ROOT"/{core,applications}); do
for INCLUDE in "${INCLUDES[@]}"; do
sed -i "s%$FROM/$INCLUDE%$TO/$INCLUDE%g" "$FILE"
done
done
}
dedupe() {
replace crossbar_util get_account_doc kz_account fetch
replace kz_util get_account_realm kz_account fetch_realm
replace crossbar_util get_account_realm kz_account fetch_realm
replace kapps_util get_account_name kz_account fetch_name
replace kz_services account_name kz_account fetch_name
replace kapps_util get_event_type kz_util get_event_type
}
echo "ensuring kz_term is used"
kz_util_to_term
echo "ensuring kz_binary is used"
kz_util_to_binary
echo "ensuring kz_time is used"
kz_util_to_time
echo "ensuring kz_time -> kz_date migration is performed"
kz_time_to_date
echo "ensuring kz_json:public/private are moved to kz_doc"
kz_json_to_kz_doc
echo "ensuring kz_json:to_querystring is moved to kz_http_util"
kz_json_to_kz_http
echo "ensuring props:to_querystring is moved to kz_http_util"
props_to_kz_http
echo "ensuring kapps_speech to kazoo_speech"
kapps_speech_to_kazoo_speech
echo "ensuring kz_media_recording to kzc_recording"
kz_media_recording_to_kzc_recording
echo "ensuring includes from kazoo are moved to kazoo_stdlib"
kz_includes
echo 'ensuring utility calls are not duplicated all over the place'
dedupe
popd >/dev/null