This repository was archived by the owner on Nov 22, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdacs_add.sh
More file actions
executable file
·66 lines (53 loc) · 1.36 KB
/
dacs_add.sh
File metadata and controls
executable file
·66 lines (53 loc) · 1.36 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
64
65
66
#!/bin/bash
#
# Exit on errors or unitialized variables
#
set -e -o nounset
# Expected input
#
# $0 this script
# $1 Doctor (clinician) ID
# $2 Clinic ID
# $3 User name [optional]
# $4 User role [optional]
# $5 Jurisdiction [optional]
# $6 Password [optional]
# Check parameters
#
if([ $# -lt 3 ] || [ $# -gt 6 ])
then
echo ""
echo "Unexpected number of parameters."
echo ""
echo "Usage: dacs_add.sh [doctorID] [clinicID] [op:userName] [op:userRole] [op:jurisdiction] [op:password]"
echo ""
exit
fi
# Set variables from parameters, prompt when password not provided
#
export DOCTOR=${1}
export CLINIC=${2}
export U_NAME=${3:-$DOCTOR}
export U_ROLE=${4:-admin}
export JURISDICTION=${5:-TEST}
export PASSWORD=${6:-sample}
# Add user to DACS
#
if( dacspasswd -uj ${JURISDICTION} -l | grep ${U_NAME})
then
echo "Existing DACS user replaced"
/usr/bin/dacspasswd -uj ${JURISDICTION} -d ${U_NAME}
fi
/usr/bin/dacspasswd -uj ${JURISDICTION} -p ${PASSWORD} -a ${U_NAME}
# Add user to DACS_ROLEFILE, notify if overwriting
#
if ( cat ${DACS_ROLEFILE} | grep -qio ^${U_NAME}: )
then
echo "Existing user role replaced"
sed -i /${U_NAME}:/d ${DACS_ROLEFILE}
fi
echo ${U_NAME}:admin | tee -a ${DACS_ROLEFILE}
# Set private data
#
( dacspasswd -uj ${JURISDICTION} -pds '{ "clinician" : "'${DOCTOR}'", "clinic" : "'${CLINIC}'" }' ${U_NAME} )|| \
echo "ERROR: Failed to add private data."