|
@@ -1,41 +1,42 @@
|
1
|
1
|
#! /bin/bash
|
2
|
2
|
|
3
|
3
|
usage() {
|
4
|
|
- echo -e "Usage : $0 host database newuser_identifier newuser_pwd (admin_identifier|config_file) [admin_pwd]" 1>&2
|
|
4
|
+ echo -e "Usage : $0 host port database newuser_identifier newuser_pwd (admin_identifier|config_file) [admin_pwd]" 1>&2
|
5
|
5
|
echo -e "config_file has to define ADMIN and ADMINPWD" 1>&2
|
6
|
6
|
exit 1
|
7
|
7
|
}
|
8
|
8
|
|
9
|
|
-if [ $# -lt 5 ]
|
|
9
|
+if [ $# -lt 6 ]
|
10
|
10
|
then
|
11
|
11
|
echo "Not enough arguments" 1>&2
|
12
|
12
|
usage
|
13
|
13
|
fi
|
14
|
14
|
|
15
|
|
-if [ $# -eq 5 ]
|
|
15
|
+if [ $# -eq 6 ]
|
16
|
16
|
then
|
17
|
|
- if [ ! -f $5 ]
|
|
17
|
+ if [ ! -f $6 ]
|
18
|
18
|
then
|
19
|
|
- echo "Not enough arguments or the configation file $5 doesn't exist" 1>&2
|
|
19
|
+ echo "Not enough arguments or the configation file $6 doesn't exist" 1>&2
|
20
|
20
|
usage
|
21
|
21
|
else
|
22
|
|
- . $5
|
|
22
|
+ . $6
|
23
|
23
|
fi
|
24
|
24
|
fi
|
25
|
25
|
|
26
|
|
-if [ $# -eq 6 ]
|
|
26
|
+if [ $# -eq 7 ]
|
27
|
27
|
then
|
28
|
|
- ADMIN=$5
|
29
|
|
- ADMINPWD=$6
|
|
28
|
+ ADMIN=$6
|
|
29
|
+ ADMINPWD=$7
|
30
|
30
|
fi
|
31
|
31
|
|
32
|
32
|
host=$1
|
33
|
|
-db=$2
|
34
|
|
-newuser=$3
|
35
|
|
-newuserpwd=$4
|
|
33
|
+port=$2
|
|
34
|
+db=$3
|
|
35
|
+newuser=$4
|
|
36
|
+newuserpwd=$5
|
36
|
37
|
|
37
|
|
-mongo $1/admin -u $ADMIN -p $ADMINPWD <<EOF
|
38
|
|
-db.addUser('$3', '$4')
|
|
38
|
+mongo $1:$2/admin -u $ADMIN -p $ADMINPWD <<EOF
|
|
39
|
+db.addUser('$4', '$5')
|
39
|
40
|
use $db
|
40
|
41
|
quit()
|
41
|
|
-EOF
|
|
42
|
+EOF
|