#!/bin/sh # 30-writable-config.sh: Verify read/write permissions for config and database files. # # This script ensures that the application can read from and write to the # critical configuration and database files after startup. # --- Color Codes --- RED=$(printf '\033[1;31m') YELLOW=$(printf '\033[1;33m') RESET=$(printf '\033[0m') # --- Main Logic --- # Define paths that need read-write access READ_WRITE_PATHS=" ${NETALERTX_CONFIG_FILE} ${NETALERTX_DB_FILE} " # --- Permission Validation --- failures=0 # Check read-write paths for existence, read, and write access for path in $READ_WRITE_PATHS; do if [ ! -e "$path" ]; then failures=1 >&2 printf "%s" "${RED}" >&2 cat <&2 printf "%s" "${RESET}" elif [ ! -r "$path" ]; then failures=1 >&2 printf "%s" "${YELLOW}" >&2 cat <&2 printf "%s" "${RESET}" elif [ ! -w "$path" ]; then failures=1 >&2 printf "%s" "${YELLOW}" >&2 cat <&2 printf "%s" "${RESET}" fi done # If there were any failures, exit if [ "$failures" -ne 0 ]; then exit 1 fi