File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -80,12 +80,23 @@ if [ "$1" = '/opt/couchdb/bin/couchdb' ]; then
8080
8181 if [ " $COUCHDB_USER " ] && [ " $COUCHDB_PASSWORD " ] && [ -z " $COUCHDB_SYNC_ADMINS_NODE " ]; then
8282 # Create admin only if not already present
83- if ! awk -v user=" $COUCHDB_USER " '
84- /^\[.*\]$/ { in_admins = ($0 == "[admins]") }
83+ admin_status= $( awk -v user=" $COUCHDB_USER " '
84+ /^\[.*\]$/ { in_admins = ($0 == "[admins]"); if (in_admins) has_admins = 1 }
8585 in_admins && $1 == user && $2 == "=" { found = 1; exit }
86- END { exit !found }
87- ' " $CLUSTER_CREDENTIALS " ; then
88- printf " \n[admins]\n%s = %s\n" " $COUCHDB_USER " " $COUCHDB_PASSWORD " >> $CLUSTER_CREDENTIALS
86+ END {
87+ if (found) print "found"
88+ else if (has_admins) print "has_admins"
89+ else print "missing"
90+ }
91+ ' " $CLUSTER_CREDENTIALS " )
92+
93+ if [ " $admin_status " = " has_admins" ]; then
94+ awk -v user=" $COUCHDB_USER " -v pass=" $COUCHDB_PASSWORD " '
95+ { print $0 }
96+ /^\[admins\]$/ { print user " = " pass }
97+ ' " $CLUSTER_CREDENTIALS " > " $CLUSTER_CREDENTIALS .tmp" && cat " $CLUSTER_CREDENTIALS .tmp" > " $CLUSTER_CREDENTIALS " && rm " $CLUSTER_CREDENTIALS .tmp"
98+ elif [ " $admin_status " = " missing" ]; then
99+ printf " \n[admins]\n%s = %s\n" " $COUCHDB_USER " " $COUCHDB_PASSWORD " >> " $CLUSTER_CREDENTIALS "
89100 fi
90101 fi
91102
You can’t perform that action at this time.
0 commit comments