-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathauthlinks-delete
More file actions
executable file
·63 lines (47 loc) · 1.68 KB
/
authlinks-delete
File metadata and controls
executable file
·63 lines (47 loc) · 1.68 KB
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
#!/usr/bin/bash
auth 2>/dev/null || authn 2>/dev/null
tenant=$(cat tenant)
okapi_url=$(cat okapi.url)
okapi_token=$(cat okapi.token)
SECONDS=1
TIMER=1
counter=0
batchsize=10
instance_uuid="${1//[^0-9a-f\-]}"
deletedata='{ "links": [] }'
deletefile="delete"
delete_log="delete.log"
rm -f ${delete_log} tmp_deleteauthlinks.*
if [[ ${instance_uuid} =~ ^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$ ]];then echo ${instance_uuid} > ${deletefile}; fi
numrecs=$(wc -l ${deletefile} |cut -d " " -f1)
deletelinks() {
local instance_uuid=${1}
local seq=${2}
local apicall
apicall=$(curl -s -w '\n' -X PUT -H "Content-type: application/json" -H "X-Okapi-Tenant: ${tenant}" -H "x-okapi-token: ${okapi_token}" -d "${deletedata}" "${okapi_url}/links/instances/${instance_uuid}")
echo "${apicall}" >> "tmp_deleteauthlinks.${seq}"
}
while mapfile -t -n ${batchsize} uuids && ((${#uuids[@]})); do
seq=0
for uuid in "${uuids[@]}";do
deletelinks ${uuid} ${seq} &
counter=$(($counter + 1))
seq=$(($seq + 1))
done
wait
if [[ $SECONDS -gt 500 ]]; then
auth 2>/dev/null || authn 2>/dev/null
okapi_token=$(cat okapi.token)
SECONDS=1
OFFSET=$(($OFFSET + 1))
TIMER=$(($OFFSET * 500 + $SECONDS))
else
if [[ $OFFSET -eq 0 ]];then TIMER=$SECONDS;fi
fi
if [[ $TIMER -gt 60 ]];then TIME=$(($TIMER/60));msg="$TIME minutes";fi
if [[ $TIMER -gt 3600 ]];then TIME=$(($TIMER/3600));msg="$TIME hours";fi
echo -en "Processing record $counter of $numrecs in $msg in $(($counter/$TIMER)) recs/sec \r"
cat tmp_deleteauthlinks.* >> ${delete_log}
rm tmp_deleteauthlinks.*
done < ${deletefile}
echo "Done removing authority links for $counter records. See ${delete_log} for details."