-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpost-configure-as-import-agent.sh
executable file
·132 lines (114 loc) · 4.26 KB
/
post-configure-as-import-agent.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
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
#!/bin/bash
if [ "$AGENT_NAME" == "importagent" ]; then
# UCD Server takes a few seconds to startup. If we call this function too early it will fail
# loop until it succeeds or fail after # of attempts
attempt=0
until $(curl -k -u admin:admin --output /dev/null --silent --head --fail "${DEPLOY_SERVER_URL}/cli/systemConfiguration"); do
attempt=$(($attempt + 1))
sleep 10
if [ "$attempt" -gt "18" ]; then
echo "Failed to connect to ucd server at ${DEPLOY_SERVER_URL}. Please check the environment variable DEPLOY_SERVER_URL for a valid value."
exit 1
fi
done
echo "Successfully connected to UCD server at ${DEPLOY_SERVER_URL}"
# It can sometimes take a couple of seconds for the agent to be "registered" with the UCD server
# if we call this function and it fails to find the agent try again until success or fail after # of attempts
localAgentId=
attempt=1
until [ -n "$localAgentId" ]; do
attempt=$(($attempt + 1))
echo "Searching for registered agent with name ${AGENT_NAME}... $attempt"
# setup localagent as the default source config importer
localAgentId=`curl -s -u admin:admin \
-H 'Content-Type: application/json' \
-X GET \
"${DEPLOY_SERVER_URL}/rest/agent" | python -c \
"import json; import sys;
data=json.load(sys.stdin);
for item in data:
if item['name'] == 'importagent':
print item['id']"`
if [ "$attempt" -gt "18" ]; then
echo "Failed to locate a registered ucd agent with name ${AGENT_NAME} on UCD ${DEPLOY_SERVER_URL}."
exit 1
fi
if [ -z "$localAgentId" ]; then
sleep 10
fi
done
echo "Successfully located registered Agent \"${AGENT_NAME}\" with id ${localAgentId}"
# curl -s -u admin:admin \
# -H 'Content-Type: application/json' \
# -X GET \
# http://192.168.27.100:8080/rest/agent/$localagentId/restart
newDefaultImportAgentId=
attempt=0
until [ -n "$newDefaultImportAgentId" ]; do
attempt=$(($attempt + 1))
echo "Attempting to register Agent ${AGENT_NAME} as default for imports on UCD server ${DEPLOY_SERVER_URL}... $attempt"
curl -s -u admin:admin \
-H 'Content-Type: application/json' \
-X PUT \
-d "
{
\"externalURL\": \""$DEPLOY_SERVER_URL"\",
\"externalUserURL\": \""$DEPLOY_SERVER_URL"\",
\"repoAutoIntegrationPeriod\": 300000,
\"deployMailHost\": \"smtp.example.com\",
\"deployMailPassword\": \"\",
\"deployMailPort\": 25,
\"deployMailSecure\": false,
\"deployMailSender\": \"[email protected]\",
\"deployMailUsername\": \"username\",
\"cleanupHourOfDay\": 0,
\"cleanupDaysToKeep\": -1,
\"cleanupCountToKeep\": -1,
\"cleanupArchivePath\": \"\",
\"historyCleanupTimeOfDay\": 1473379223743,
\"historyCleanupDaysToKeep\": 730,
\"historyCleanupDuration\": 23,
\"historyCleanupEnabled\": false,
\"enableInactiveLinks\": false,
\"enablePromptOnUse\": false,
\"enableAllowFailure\": false,
\"validateAgentIp\": false,
\"skipCollectPropertiesForExistingAgents\": false,
\"requireComplexPasswords\": false,
\"minimumPasswordLength\": 0,
\"enableUIDebugging\": false,
\"enableMaintenanceMode\": false,
\"isCreateDefaultChildren\": false,
\"requireCommentForProcessChanges\": false,
\"failProcessesWithUnresolvedProperties\": true,
\"enforceDeployedVersionIntegrity\": true,
\"artifactAgent\": \""$localAgentId"\",
\"artifactAgentName\": \""$AGENT_NAME"\",
\"serverLicenseType\": \"No License\",
\"serverLicenseBackupType\": \"No License\",
\"rclServerUrl\": \""$RCL_URL"\",
\"agentAutoLicense\": false,
\"defaultLocale\": \"en_US\",
\"defaultSnapshotLockType\": \"ALL\"
}
" \
"${DEPLOY_SERVER_URL}/rest/system/configuration"
# setup localagent as the default source config importer
newDefaultImportAgentId=`curl -s -u admin:admin \
-H 'Content-Type: application/json' \
-X GET \
"${DEPLOY_SERVER_URL}/cli/systemConfiguration" | python -c \
"import json; import sys;
data=json.load(sys.stdin);
print data['artifactAgentName']"`
if [ "$attempt" -gt "18" ]; then
echo "Failed to register Agent ${AGENT_NAME} as default for imports on UCD server ${DEPLOY_SERVER_URL}."
exit 1
fi
if [ -z "$newDefaultImportAgentId" ]; then
sleep 10
fi
done
echo "Successfully configured Agent \"${AGENT_NAME}\" as the default for imports on UCD server ${DEPLOY_SERVER_URL}"
fi
exit 0