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

69
scripts/load-config.sh Executable file
View File

@@ -0,0 +1,69 @@
#!/bin/bash
# Load configuration from JSON file and export as environment variables
# Environment variables take precedence over JSON values
set -e
# Default config file location
CONFIG_FILE="${CONFIG_FILE:-config.json}"
# Color output
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
NC='\033[0m' # No Color
# Function to safely extract JSON values
get_json_value() {
local file="$1"
local key="$2"
local default="${3:-}"
if [ -f "$file" ]; then
value=$(jq -r "$key" "$file" 2>/dev/null || echo "null")
if [ "$value" = "null" ] || [ -z "$value" ]; then
echo "$default"
else
echo "$value"
fi
else
echo "$default"
fi
}
# Check if config file exists
if [ ! -f "$CONFIG_FILE" ]; then
echo -e "${YELLOW}Warning: $CONFIG_FILE not found${NC}" >&2
echo -e "${YELLOW}Using environment variables only${NC}" >&2
echo -e "${YELLOW}Copy config.example.json to config.json and fill in your credentials${NC}" >&2
echo "" >&2
fi
# Check if jq is installed
if ! command -v jq &> /dev/null; then
echo -e "${RED}Error: jq is not installed${NC}" >&2
echo -e "${RED}Install it with: sudo apt-get install jq${NC}" >&2
exit 1
fi
# Load configuration values, preferring environment variables
export NEXTCLOUD_URL="${NEXTCLOUD_URL:-$(get_json_value "$CONFIG_FILE" '.nextcloud.url' '')}"
export NEXTCLOUD_USER="${NEXTCLOUD_USER:-$(get_json_value "$CONFIG_FILE" '.nextcloud.username' '')}"
export NEXTCLOUD_PASSWORD="${NEXTCLOUD_PASSWORD:-$(get_json_value "$CONFIG_FILE" '.nextcloud.password' '')}"
# Load settings
export MAX_RECENT_FOLDERS="${MAX_RECENT_FOLDERS:-$(get_json_value "$CONFIG_FILE" '.settings.maxRecentFolders' '5')}"
export UPLOAD_CHUNK_SIZE="${UPLOAD_CHUNK_SIZE:-$(get_json_value "$CONFIG_FILE" '.settings.uploadChunkSize' '10485760')}"
# Show what was loaded (without showing password)
if [ -n "$NEXTCLOUD_URL" ]; then
echo -e "${GREEN}${NC} NEXTCLOUD_URL: $NEXTCLOUD_URL"
fi
if [ -n "$NEXTCLOUD_USER" ]; then
echo -e "${GREEN}${NC} NEXTCLOUD_USER: $NEXTCLOUD_USER"
fi
if [ -n "$NEXTCLOUD_PASSWORD" ]; then
echo -e "${GREEN}${NC} NEXTCLOUD_PASSWORD: [set]"
fi
echo -e "${GREEN}${NC} MAX_RECENT_FOLDERS: $MAX_RECENT_FOLDERS"
echo -e "${GREEN}${NC} UPLOAD_CHUNK_SIZE: $UPLOAD_CHUNK_SIZE"