feat(config): implement configuration system and contributing guide (#6, #4)

This commit is contained in:
2026-01-27 00:10:27 -08:00
parent 631046df34
commit 092299ff33
6 changed files with 767 additions and 2 deletions

73
scripts/validate-config.sh Executable file
View File

@@ -0,0 +1,73 @@
#!/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