|
6 | 6 |
|
7 | 7 | # App version and name |
8 | 8 | APP_NAME="NoirNet" |
9 | | -VERSION=1.0.3 |
| 9 | +VERSION=1.0.4 |
10 | 10 | LAST_UPDATED="2024-11-22" |
11 | 11 |
|
12 | 12 | # Default configuration file location |
@@ -196,11 +196,26 @@ log_message() { |
196 | 196 |
|
197 | 197 | # Function: Initialize the log file |
198 | 198 | init_log() { |
| 199 | + if [ -z "$LOG_FILE" ]; then |
| 200 | + log_message "ERROR" "LOG_FILE variable is not set." "$LINENO" |
| 201 | + exit 1 |
| 202 | + fi |
| 203 | + |
199 | 204 | if [ ! -f "$LOG_FILE" ]; then |
200 | | - touch "$LOG_FILE" |
201 | | - log_message "DEBUG" "Created log file: $LOG_FILE" "$LINENO" |
| 205 | + # Attempt to create the log file |
| 206 | + if touch "$LOG_FILE" 2>/dev/null; then |
| 207 | + log_message "DEBUG" "Created log file: $LOG_FILE" "$LINENO" |
| 208 | + else |
| 209 | + log_message "ERROR" "Failed to create log file: $LOG_FILE" "$LINENO" |
| 210 | + exit 1 |
| 211 | + fi |
202 | 212 | else |
203 | | - log_message "DEBUG" "Log file already exists: $LOG_FILE" "$LINENO" |
| 213 | + # Check if the log file is writable |
| 214 | + if [ ! -w "$LOG_FILE" ]; then |
| 215 | + log_message "ERROR" "Log file exists but is not writable: $LOG_FILE" "$LINENO" |
| 216 | + exit 1 |
| 217 | + fi |
| 218 | + log_message "DEBUG" "Log file already exists and is writable: $LOG_FILE" "$LINENO" |
204 | 219 | fi |
205 | 220 | } |
206 | 221 |
|
@@ -276,28 +291,28 @@ delete_cache() { |
276 | 291 |
|
277 | 292 | # Ensure CACHE_DIR is defined and not empty |
278 | 293 | if [[ -z "$CACHE_DIR" ]]; then |
279 | | - printf "Error: CACHE_DIR is not set. Unable to proceed.\n" >&2 |
| 294 | + log_message "ERROR" "CACHE_DIR is not set. Unable to proceed." "$LINENO" |
280 | 295 | exit 1 |
281 | 296 | fi |
282 | 297 |
|
283 | 298 | # Ensure CACHE_DIR exists |
284 | 299 | if [[ ! -d "$CACHE_DIR" ]]; then |
285 | | - printf "Error: Cache directory '%s' does not exist.\n" "$CACHE_DIR" >&2 |
| 300 | + log_message "ERROR" "Cache directory '$CACHE_DIR' does not exist." "$LINENO" |
286 | 301 | exit 1 |
287 | 302 | fi |
288 | 303 |
|
289 | 304 | # Prevent deletion of critical directories |
290 | 305 | if is_critical_directory "$CACHE_DIR"; then |
291 | | - printf "Error: Attempted to delete a critical directory '%s'. Aborting.\n" "$CACHE_DIR" >&2 |
| 306 | + log_message "ERROR" "Attempted to delete a critical directory '$CACHE_DIR'. Aborting." "$LINENO" |
292 | 307 | exit 1 |
293 | 308 | fi |
294 | 309 |
|
295 | 310 | # Attempt to delete the cache directory |
296 | 311 | if rm -rf "$CACHE_DIR"; then |
297 | | - printf "Success: All cached files in '%s' deleted.\n" "$CACHE_DIR" |
| 312 | + log_message "INFO" "Success: All cached files in '$CACHE_DIR' deleted." "$LINENO" |
298 | 313 | exit 0 |
299 | 314 | else |
300 | | - printf "Error: Failed to delete cached files in '%s'.\n" "$CACHE_DIR" >&2 |
| 315 | + log_message "ERROR" "Failed to delete cached files in '$CACHE_DIR'." "$LINENO" |
301 | 316 | exit 1 |
302 | 317 | fi |
303 | 318 | } |
@@ -911,9 +926,15 @@ process_arguments() { |
911 | 926 |
|
912 | 927 | [[ "$CLEAN" = true ]] && delete_cache |
913 | 928 | init_cache |
| 929 | + |
| 930 | + [[ -n "$CLI_LOG_FILE" ]] && LOG_FILE="$CLI_LOG_FILE" |
914 | 931 | [[ -n "$CLI_LOG_LEVEL" ]] && LOG_LEVEL="$CLI_LOG_LEVEL" |
915 | 932 | init_log |
| 933 | + |
| 934 | + # Initialize CSV file |
916 | 935 | init_csv |
| 936 | + |
| 937 | + # Override config settings with command line options |
917 | 938 | [[ "$SHOW_LOG" = true ]] && show_log |
918 | 939 | [[ "$SHOW_HELP" = true ]] && show_help |
919 | 940 | [[ -n "$CLI_PUSHOVER_NOTIFICATION" ]] && PUSHOVER_NOTIFICATION="$CLI_PUSHOVER_NOTIFICATION" |
|
0 commit comments