File tree Expand file tree Collapse file tree 5 files changed +60
-0
lines changed
Expand file tree Collapse file tree 5 files changed +60
-0
lines changed Original file line number Diff line number Diff line change @@ -152,6 +152,18 @@ _parse_config() {
152152 if configPath=" $( _mongod_hack_get_arg_val --config " $@ " ) " ; then
153153 # if --config is specified, parse it into a JSON file so we can remove a few problematic keys (especially SSL-related keys)
154154 # see https://docs.mongodb.com/manual/reference/configuration-options/
155+ if grep -vEm1 ' ^[[:space:]]*(#|$)' " $configPath " | grep -qE ' ^[[:space:]]*[^=:]+[[:space:]]*=' ; then
156+ # if the first non-comment/non-blank line of the config file looks like "foo = ...", this is probably the 2.4 and older "ini-style config format"
157+ # https://docs.mongodb.com/v2.4/reference/configuration-options/
158+ # https://docs.mongodb.com/v2.6/reference/configuration-options/
159+ # https://github.com/mongodb/mongo/blob/r4.4.2/src/mongo/util/options_parser/options_parser.cpp#L1359-L1375
160+ # https://stackoverflow.com/a/25518018/433558
161+ echo >&2
162+ echo >&2 " WARNING: it appears that '$configPath ' is in the older INI-style format (replaced by YAML in MongoDB 2.6)"
163+ echo >&2 ' This script does not parse the older INI-style format, and thus will ignore it.'
164+ echo >&2
165+ return 1
166+ fi
155167 mongo --norc --nodb --quiet --eval " load('/js-yaml.js'); printjson(jsyaml.load(cat($( _js_escape " $configPath " ) )))" > " $jsonConfigFile "
156168 if [ " $( head -c1 " $jsonConfigFile " ) " != ' {' ] || [ " $( tail -c2 " $jsonConfigFile " ) " != ' }' ]; then
157169 # if the file doesn't start with "{" and end with "}", it's *probably* an error ("uncaught exception: YAMLException: foo" for example), so we should print it out
Original file line number Diff line number Diff line change @@ -152,6 +152,18 @@ _parse_config() {
152152 if configPath=" $( _mongod_hack_get_arg_val --config " $@ " ) " ; then
153153 # if --config is specified, parse it into a JSON file so we can remove a few problematic keys (especially SSL-related keys)
154154 # see https://docs.mongodb.com/manual/reference/configuration-options/
155+ if grep -vEm1 ' ^[[:space:]]*(#|$)' " $configPath " | grep -qE ' ^[[:space:]]*[^=:]+[[:space:]]*=' ; then
156+ # if the first non-comment/non-blank line of the config file looks like "foo = ...", this is probably the 2.4 and older "ini-style config format"
157+ # https://docs.mongodb.com/v2.4/reference/configuration-options/
158+ # https://docs.mongodb.com/v2.6/reference/configuration-options/
159+ # https://github.com/mongodb/mongo/blob/r4.4.2/src/mongo/util/options_parser/options_parser.cpp#L1359-L1375
160+ # https://stackoverflow.com/a/25518018/433558
161+ echo >&2
162+ echo >&2 " WARNING: it appears that '$configPath ' is in the older INI-style format (replaced by YAML in MongoDB 2.6)"
163+ echo >&2 ' This script does not parse the older INI-style format, and thus will ignore it.'
164+ echo >&2
165+ return 1
166+ fi
155167 mongo --norc --nodb --quiet --eval " load('/js-yaml.js'); printjson(jsyaml.load(cat($( _js_escape " $configPath " ) )))" > " $jsonConfigFile "
156168 if [ " $( head -c1 " $jsonConfigFile " ) " != ' {' ] || [ " $( tail -c2 " $jsonConfigFile " ) " != ' }' ]; then
157169 # if the file doesn't start with "{" and end with "}", it's *probably* an error ("uncaught exception: YAMLException: foo" for example), so we should print it out
Original file line number Diff line number Diff line change @@ -152,6 +152,18 @@ _parse_config() {
152152 if configPath=" $( _mongod_hack_get_arg_val --config " $@ " ) " ; then
153153 # if --config is specified, parse it into a JSON file so we can remove a few problematic keys (especially SSL-related keys)
154154 # see https://docs.mongodb.com/manual/reference/configuration-options/
155+ if grep -vEm1 ' ^[[:space:]]*(#|$)' " $configPath " | grep -qE ' ^[[:space:]]*[^=:]+[[:space:]]*=' ; then
156+ # if the first non-comment/non-blank line of the config file looks like "foo = ...", this is probably the 2.4 and older "ini-style config format"
157+ # https://docs.mongodb.com/v2.4/reference/configuration-options/
158+ # https://docs.mongodb.com/v2.6/reference/configuration-options/
159+ # https://github.com/mongodb/mongo/blob/r4.4.2/src/mongo/util/options_parser/options_parser.cpp#L1359-L1375
160+ # https://stackoverflow.com/a/25518018/433558
161+ echo >&2
162+ echo >&2 " WARNING: it appears that '$configPath ' is in the older INI-style format (replaced by YAML in MongoDB 2.6)"
163+ echo >&2 ' This script does not parse the older INI-style format, and thus will ignore it.'
164+ echo >&2
165+ return 1
166+ fi
155167 mongo --norc --nodb --quiet --eval " load('/js-yaml.js'); printjson(jsyaml.load(cat($( _js_escape " $configPath " ) )))" > " $jsonConfigFile "
156168 if [ " $( head -c1 " $jsonConfigFile " ) " != ' {' ] || [ " $( tail -c2 " $jsonConfigFile " ) " != ' }' ]; then
157169 # if the file doesn't start with "{" and end with "}", it's *probably* an error ("uncaught exception: YAMLException: foo" for example), so we should print it out
Original file line number Diff line number Diff line change @@ -152,6 +152,18 @@ _parse_config() {
152152 if configPath=" $( _mongod_hack_get_arg_val --config " $@ " ) " ; then
153153 # if --config is specified, parse it into a JSON file so we can remove a few problematic keys (especially SSL-related keys)
154154 # see https://docs.mongodb.com/manual/reference/configuration-options/
155+ if grep -vEm1 ' ^[[:space:]]*(#|$)' " $configPath " | grep -qE ' ^[[:space:]]*[^=:]+[[:space:]]*=' ; then
156+ # if the first non-comment/non-blank line of the config file looks like "foo = ...", this is probably the 2.4 and older "ini-style config format"
157+ # https://docs.mongodb.com/v2.4/reference/configuration-options/
158+ # https://docs.mongodb.com/v2.6/reference/configuration-options/
159+ # https://github.com/mongodb/mongo/blob/r4.4.2/src/mongo/util/options_parser/options_parser.cpp#L1359-L1375
160+ # https://stackoverflow.com/a/25518018/433558
161+ echo >&2
162+ echo >&2 " WARNING: it appears that '$configPath ' is in the older INI-style format (replaced by YAML in MongoDB 2.6)"
163+ echo >&2 ' This script does not parse the older INI-style format, and thus will ignore it.'
164+ echo >&2
165+ return 1
166+ fi
155167 mongo --norc --nodb --quiet --eval " load('/js-yaml.js'); printjson(jsyaml.load(cat($( _js_escape " $configPath " ) )))" > " $jsonConfigFile "
156168 if [ " $( head -c1 " $jsonConfigFile " ) " != ' {' ] || [ " $( tail -c2 " $jsonConfigFile " ) " != ' }' ]; then
157169 # if the file doesn't start with "{" and end with "}", it's *probably* an error ("uncaught exception: YAMLException: foo" for example), so we should print it out
Original file line number Diff line number Diff line change @@ -152,6 +152,18 @@ _parse_config() {
152152 if configPath=" $( _mongod_hack_get_arg_val --config " $@ " ) " ; then
153153 # if --config is specified, parse it into a JSON file so we can remove a few problematic keys (especially SSL-related keys)
154154 # see https://docs.mongodb.com/manual/reference/configuration-options/
155+ if grep -vEm1 ' ^[[:space:]]*(#|$)' " $configPath " | grep -qE ' ^[[:space:]]*[^=:]+[[:space:]]*=' ; then
156+ # if the first non-comment/non-blank line of the config file looks like "foo = ...", this is probably the 2.4 and older "ini-style config format"
157+ # https://docs.mongodb.com/v2.4/reference/configuration-options/
158+ # https://docs.mongodb.com/v2.6/reference/configuration-options/
159+ # https://github.com/mongodb/mongo/blob/r4.4.2/src/mongo/util/options_parser/options_parser.cpp#L1359-L1375
160+ # https://stackoverflow.com/a/25518018/433558
161+ echo >&2
162+ echo >&2 " WARNING: it appears that '$configPath ' is in the older INI-style format (replaced by YAML in MongoDB 2.6)"
163+ echo >&2 ' This script does not parse the older INI-style format, and thus will ignore it.'
164+ echo >&2
165+ return 1
166+ fi
155167 mongo --norc --nodb --quiet --eval " load('/js-yaml.js'); printjson(jsyaml.load(cat($( _js_escape " $configPath " ) )))" > " $jsonConfigFile "
156168 if [ " $( head -c1 " $jsonConfigFile " ) " != ' {' ] || [ " $( tail -c2 " $jsonConfigFile " ) " != ' }' ]; then
157169 # if the file doesn't start with "{" and end with "}", it's *probably* an error ("uncaught exception: YAMLException: foo" for example), so we should print it out
You can’t perform that action at this time.
0 commit comments