Skip to content

Commit d4fd91f

Browse files
committed
Fixed:
- Failure to run when there is no configuration file - Repeat N times fails to run properly in some instances
1 parent 4a3b2a5 commit d4fd91f

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
- none
1111

12+
## [1.0.2] - 2024-12-17
13+
14+
### Fixed
15+
16+
- Failure to run when there is no configuration file
17+
- Repeat N times fails to run properly in some instances
18+
1219
## [1.0.1] - 2024-12-17
1320

1421
### Changed

noircon

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
# App version and name
88
APP_NAME="NoirCon"
9-
VERSION=1.0.1
9+
VERSION=1.0.2
1010
LAST_UPDATED="2024-12-17"
1111

1212
# ==============================
@@ -25,7 +25,7 @@ DEPENDENCIES=("nc" "openssl" "timeout" "whois")
2525

2626
# Default configuration file location (full default path added during initialization)
2727
CONFIG_FILE_NAME="$(basename "$0").json"
28-
SKIP_CONFIG_KEYS=("CONFIG_FILE" "PID_FILE")
28+
SKIP_CONFIG_KEYS=("PID_FILE")
2929

3030
# Master directory to store all cache files (full default path added during initialization)
3131
CACHE_DIR="$(basename "$0")_cache"
@@ -802,9 +802,12 @@ start_process() {
802802
# Function: Load configuration from JSON file
803803
load_config() {
804804
local config_file_path="$1"
805-
if [[ ! -f "$config_file_path" ]]; then
805+
806+
if key_exists "CONFIG_FILE" SKIP_CONFIG_KEYS[@] && [[ ! -f "$config_file_path" ]]; then
806807
log_message "FATAL" "Configuration file not found: $config_file_path" "$LINENO"
807808
exit 1
809+
elif ! key_exists "CONFIG_FILE" SKIP_CONFIG_KEYS[@] && [[ ! -f "$config_file_path" ]]; then
810+
return 0
808811
fi
809812

810813
# Use jq to parse the JSON and set environment variables
@@ -814,7 +817,7 @@ load_config() {
814817

815818
while IFS="=" read -r key value; do
816819
# Skip empty lines, invalid entries, or keys that are in the skip_keys array
817-
if [[ -n "$key" && -n "$value" && ! " ${SKIP_CONFIG_KEYS[@]} " =~ " ${key} " ]]; then
820+
if [[ -n "$key" && -n "$value" && ! " ${SKIP_CONFIG_KEYS[@]} " =~ " ${key} " && "$key" != "CONFIG_FILE" ]]; then
818821
[[ "$key" == *_DIR || "$key" == *_FILE || "$key" == *_CMD ]] && value="$(normalize_path "$value")"
819822
export "$key"="$value"
820823
log_message "DEBUG" "Setting $key=$value" "$LINENO"
@@ -828,6 +831,17 @@ get_connection_groups() {
828831
jq -r '.connections | keys | sort[]' "$config_file_path"
829832
}
830833

834+
# Function: Check if a key exists in the SKIP_CONFIG_KEYS
835+
key_exists() {
836+
local key="$1"
837+
838+
if [[ " ${SKIP_CONFIG_KEYS[@]} " =~ " ${key} " ]]; then
839+
return 0 # Key exists
840+
fi
841+
842+
return 1 # Key does not exist
843+
}
844+
831845
# Function: Get connection settings as key-value pairs
832846
get_connection_settings() {
833847
local group="$1"
@@ -1983,7 +1997,7 @@ main() {
19831997
log_message "DEBUG" "Iteration: $repeat_count" "$LINENO"
19841998

19851999
# Check if REPEAT is set and not zero
1986-
if [[ -n "$REPEAT" || "$REPEAT" -ne 0 ]] && [[ "$repeat_count" -ge "$REPEAT" ]]; then
2000+
if [[ -z "$REPEAT" || "$REPEAT" != 0 ]] && [[ "$repeat_count" -ge "$REPEAT" ]]; then
19872001
log_message "DEBUG" "Reached the maximum number of repetitions: $REPEAT" "$LINENO"
19882002
break
19892003
else

0 commit comments

Comments
 (0)