Files
nextcloud-share/scripts/validate-config.sh

74 lines
1.9 KiB
Bash
Executable File

#!/bin/bash
# Validate that all required configuration is present
set -e
# Color output
GREEN='\033[0;32m'
RED='\033[0;31m'
NC='\033[0m' # No Color
# Load configuration first
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "$SCRIPT_DIR/load-config.sh" > /dev/null 2>&1 || true
# Validation flags
VALID=true
# Validate required fields
if [ -z "$NEXTCLOUD_URL" ]; then
echo -e "${RED}✗ Error: NEXTCLOUD_URL is not set${NC}" >&2
VALID=false
fi
if [ -z "$NEXTCLOUD_USER" ]; then
echo -e "${RED}✗ Error: NEXTCLOUD_USER is not set${NC}" >&2
VALID=false
fi
if [ -z "$NEXTCLOUD_PASSWORD" ]; then
echo -e "${RED}✗ Error: NEXTCLOUD_PASSWORD is not set${NC}" >&2
VALID=false
fi
# Validate URL format
if [ -n "$NEXTCLOUD_URL" ]; then
if [[ ! "$NEXTCLOUD_URL" =~ ^https?:// ]]; then
echo -e "${RED}✗ Error: NEXTCLOUD_URL must start with http:// or https://${NC}" >&2
VALID=false
fi
# Warn if using HTTP instead of HTTPS
if [[ "$NEXTCLOUD_URL" =~ ^http:// ]]; then
echo -e "${RED}⚠ Warning: Using HTTP instead of HTTPS is insecure!${NC}" >&2
fi
fi
# Validate numeric settings
if ! [[ "$MAX_RECENT_FOLDERS" =~ ^[0-9]+$ ]]; then
echo -e "${RED}✗ Error: MAX_RECENT_FOLDERS must be a number${NC}" >&2
VALID=false
fi
if ! [[ "$UPLOAD_CHUNK_SIZE" =~ ^[0-9]+$ ]]; then
echo -e "${RED}✗ Error: UPLOAD_CHUNK_SIZE must be a number${NC}" >&2
VALID=false
fi
# Exit with appropriate code
if [ "$VALID" = true ]; then
echo -e "${GREEN}✓ Configuration is valid${NC}"
exit 0
else
echo ""
echo "Please set the missing configuration values in:"
echo " 1. config.json (copy from config.example.json), or"
echo " 2. Environment variables"
echo ""
echo "Required environment variables:"
echo " - NEXTCLOUD_URL"
echo " - NEXTCLOUD_USER"
echo " - NEXTCLOUD_PASSWORD"
exit 1
fi