3 # This script is called within the docker-compose to provision the controller with either
4 # the global or per-device credentials.
6 stderr() { echo "$@" 1>&2; }
8 [ $# -eq 0 ] && { stderr "Usage: $0 ( -global | -per-device id ) username password(s)"; exit 1; }
10 : ${1?"Usage: $0 -global | -per-device"}
14 if [[ "${option}" == "-per-device" ]]; then
15 : ${2?"Usage: $0 Device Id"}
16 : ${3?"Usage: $0 Device Username"}
17 : ${4?"Usage: $0 Device Password"}
22 elif [[ "${option}" == "-global" ]]; then
23 : ${2?"Usage: $0 Global Username"}
24 : ${3?"Usage: $0 Global Password"}
30 stderr "$0: must supply -global or -per-device command line argument for global password changes, not '${option}''"
37 if [[ ! -z "$pwdsjson" ]]; then
44 controller=ODL_SYSTEM_IP
46 basicauth="YWRtaW46YWRtaW4="
48 baseurl="http://${controller}:${port}/restconf/config/odl-netconf-callhome-server:netconf-callhome-server"
50 if [[ "${option}" == "-global" ]]; then
51 url="${baseurl}/global/credentials"
53 url="${baseurl}/allowed-devices/device/${devid}/credentials"
57 read -r -d '' payload << EOM
60 "username": "${user}",
61 "passwords": [${pwdsjson}]
67 payload=$(echo "${payload}" | tr '\n' ' ' | tr -s " ")
69 echo "PUT of user (${user}) and pwd (${pwd})"
70 res=$(curl -s -X PUT \
71 -H "Authorization: Basic ${basicauth}" \
72 -H "Content-Type: application/json" \
73 -H "Cache-Control: no-cache" \
77 if [[ $res == *"error-message"* ]]; then
82 echo "Getting user/pwd ..."
84 res=$(curl -s -X GET \
85 -H "Authorization: Basic ${basicauth}" \
86 -H "Cache-Control: no-cache" \