-
Notifications
You must be signed in to change notification settings - Fork 0
/
transferbot.sh
executable file
·59 lines (52 loc) · 1.36 KB
/
transferbot.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
#!/bin/sh
set -eu
set -o pipefail
trap finish EXIT INT TERM
finish () {
exit_code=$?;
if [ ! -z "${CALLBACK_ON_SUCCESS:-}" ] && [ "$exit_code" = 0 ]; then
sh -c "$CALLBACK_ON_SUCCESS"
elif [ ! -z "${CALLBACK_ON_FAILURE:-}" ] && [ "$exit_code" != 0 ]; then
sh -c "$CALLBACK_ON_FAILURE"
fi
}
source_wiki_origin="$1"
shift
target_wiki_origin="$1"
shift
{
cat <<CREDS
{
"credentials": {
"${target_wiki_origin}": {
"oauth": {
"consumer_key": "${TARGET_WIKI_OAUTH_CONSUMER_TOKEN}",
"consumer_secret": "${TARGET_WIKI_OAUTH_CONSUMER_SECRET}",
"token": "${TARGET_WIKI_OAUTH_ACCESS_TOKEN}",
"token_secret": "${TARGET_WIKI_OAUTH_ACCESS_SECRET}"
}
}
}
}
CREDS
} > $(wb config path)
read_entities() {
# entities are passed as either
# "Q42" which fetches the latest revision
# "Q42@123" which fetches revision 123
for entity in $@; do
case $entity in
*@*)
revision=$(echo $entity | cut -d "@" -f 2)
id=$(echo $entity | cut -d "@" -f 1)
wb data "$id" --revision "$revision" --instance "$source_wiki_origin"
;;
*)
wb data "$entity" --instance "$source_wiki_origin"
;;
esac
done
}
read_entities $@ |\
mangle_data -t "$target_wiki_origin" -p type -p labels -p descriptions -p aliases -p datatype |\
wb create-entity --batch --instance "$target_wiki_origin"