-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathvalidate_server.sh
More file actions
executable file
·87 lines (71 loc) · 2.05 KB
/
Copy pathvalidate_server.sh
File metadata and controls
executable file
·87 lines (71 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/bin/bash
# Simple validation script for server.json using jq
set -e
# Check if jq is installed
if ! command -v jq &> /dev/null; then
echo "✗ Error: jq is not installed. Please install jq to use this script."
exit 1
fi
# Check if server.json exists
if [ ! -f "server.json" ]; then
echo "✗ Error: server.json not found in current directory"
exit 1
fi
# Validate JSON syntax
if ! jq empty server.json 2>/dev/null; then
echo "✗ Error: server.json is not valid JSON"
exit 1
fi
# Extract and validate required fields
NAME=$(jq -r '.name // empty' server.json)
VERSION=$(jq -r '.version // empty' server.json)
DESCRIPTION=$(jq -r '.description // empty' server.json)
PACKAGES=$(jq -r '.packages // empty' server.json)
ERRORS=()
# Check required fields
if [ -z "$NAME" ]; then
ERRORS+=("Missing required field: name")
fi
if [ -z "$VERSION" ]; then
ERRORS+=("Missing required field: version")
fi
if [ -z "$DESCRIPTION" ]; then
ERRORS+=("Missing required field: description")
fi
if [ -z "$PACKAGES" ]; then
ERRORS+=("Missing required field: packages")
fi
# Validate name format for GitHub namespace
if [[ "$NAME" == io.github.* ]]; then
# Valid GitHub namespace
:
elif [[ "$NAME" == .* ]]; then
ERRORS+=("Name cannot start with a dot")
fi
# Count packages
PACKAGE_COUNT=$(jq '.packages | length' server.json)
# Check if there are validation errors
if [ ${#ERRORS[@]} -gt 0 ]; then
echo "✗ Validation errors found:"
for error in "${ERRORS[@]}"; do
echo " - $error"
done
exit 1
fi
# Success
echo "✓ server.json validation successful"
echo " Name: $NAME"
echo " Version: $VERSION"
echo " Packages: $PACKAGE_COUNT"
# Optional: Check if schema is accessible
SCHEMA=$(jq -r '."$schema" // empty' server.json)
if [ -n "$SCHEMA" ]; then
echo " Schema: $SCHEMA"
if command -v curl &> /dev/null; then
if curl -s -f -o /dev/null "$SCHEMA"; then
echo " ✓ Schema URL is accessible"
else
echo " ⚠ Warning: Schema URL is not accessible"
fi
fi
fi