-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcopy-user-from-remote
executable file
·49 lines (35 loc) · 1.24 KB
/
copy-user-from-remote
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
#!/bin/bash
#
# Copies a user account from the production system
# to the staging environment.
#
set -e
if [ -z "$PGHOST" ]; then
echo "Error: PGHOST not set in environment"
exit 1
fi
if [ -z "$SRCNEO4JHOST" ]; then
echo "Error: SRCNEO4JHOST not set in environment"
exit 1
fi
if [ -z "$DSTNEO4JHOST" ]; then
echo "Error: DSTNEO4JHOST not set in environment"
exit 1
fi
USER=$1
if [ -z "$USER" ]; then
echo "Arg should be a user ID!"
exit 1
fi
NEO4JUSER=neo4j
SRC_BASE=http://$SRCNEO4JHOST:7474/ehri
SRC_URL=$SRC_BASE/classes/UserProfile
DST_BASE=http://$DSTNEO4JHOST:7474/ehri
DST_URL=$DST_BASE/classes/UserProfile
CURL_CMD="curl --netrc-file $HOME/.neo4j-netrc --silent --header X-User:admin --header Content-type:application/json"
psql --user docview_stage docview -c "\copy (SELECT * from users where id = '$1') TO STDOUT" | \
psql --user docview_stage docview_stage -c "\copy users from stdin"
$CURL_CMD $SRC_URL/$USER | $CURL_CMD --data-binary @- "$DST_URL?group=portal"
$CURL_CMD --data-binary '["owner"]' "$DST_BASE/permissions/$USER/item/$USER"
$CURL_CMD "$DST_BASE/entities?id=$USER" | java -jar /opt/docview/bin/indexer.jar --index --rest $DST_BASE -U $NEO4JUSER -p $NEO4JPASS --file -
echo "Copied user $USER to from prod"