Repository navigation
Expand file tree
/
Copy pathsetup-cloudkit-schema.sh
More file actions
executable file
·212 lines (191 loc) · 6.88 KB
/
Copy pathsetup-cloudkit-schema.sh
File metadata and controls
executable file
·212 lines (191 loc) · 6.88 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
#!/bin/bash
# CloudKit Schema Setup Script
# This script imports the SwoopMistKit schema into your CloudKit container
set -eo pipefail
# Parse command line arguments
DRY_RUN=false
while [[ $# -gt 0 ]]; do
case $1 in
--dry-run)
DRY_RUN=true
shift
;;
--help|-h)
echo "Usage: $0 [OPTIONS]"
echo ""
echo "Options:"
echo " --dry-run Validate schema without importing"
echo " --help, -h Show this help message"
echo ""
echo "Environment variables:"
echo " CLOUDKIT_CONTAINER_ID CloudKit container ID (default: iCloud.com.brightdigit.Swoop)"
echo " CLOUDKIT_TEAM_ID Apple Developer Team ID (10-character)"
echo " CLOUDKIT_ENVIRONMENT Environment (development or production, default: development)"
exit 0
;;
*)
echo "Unknown option: $1"
echo "Use --help for usage information"
exit 1
;;
esac
done
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
echo "========================================"
echo "CloudKit Schema Setup for SwoopMistKit"
echo "========================================"
if [ "$DRY_RUN" = true ]; then
echo "(DRY RUN MODE - No changes will be made)"
fi
echo ""
# Check if cktool is available
if ! command -v xcrun &> /dev/null || ! xcrun cktool --version &> /dev/null; then
echo -e "${RED}ERROR: cktool is not available.${NC}"
echo "cktool is distributed with Xcode 13+ and is required for schema import."
echo "Please install Xcode 13 or later."
exit 1
fi
echo -e "${GREEN}✓${NC} cktool is available"
echo ""
# Check for CloudKit Management Token
echo "Checking for CloudKit Management Token..."
if ! xcrun cktool get-teams 2>&1 | grep -qE "^[A-Z0-9]+:"; then
echo -e "${RED}ERROR: CloudKit Management Token not configured.${NC}"
echo ""
echo "You need to save a CloudKit Web Services Management Token for cktool first."
echo ""
echo "Steps to configure:"
echo " 1. Go to: https://icloud.developer.apple.com/dashboard/"
echo " 2. Select your container"
echo " 3. Go to 'API Access' → 'CloudKit Web Services'"
echo " 4. Generate a Management Token (not Server-to-Server Key)"
echo " 5. Copy the token"
echo " 6. Save it with cktool:"
echo ""
echo " xcrun cktool save-token"
echo ""
echo " 7. Paste your Management Token when prompted"
echo ""
echo "Note: Management Token is for schema operations (cktool)."
echo " Server-to-Server Key is for runtime API operations (swoopmist sync)."
echo ""
exit 1
fi
echo -e "${GREEN}✓${NC} CloudKit Management Token is configured"
echo ""
# Check for required parameters
if [ -z "$CLOUDKIT_CONTAINER_ID" ]; then
echo -e "${YELLOW}CLOUDKIT_CONTAINER_ID not set.${NC}"
read -p "Enter your CloudKit Container ID [iCloud.com.brightdigit.Swoop]: " CLOUDKIT_CONTAINER_ID
CLOUDKIT_CONTAINER_ID=${CLOUDKIT_CONTAINER_ID:-iCloud.com.brightdigit.Swoop}
fi
if [ -z "$CLOUDKIT_TEAM_ID" ]; then
echo -e "${YELLOW}CLOUDKIT_TEAM_ID not set.${NC}"
read -p "Enter your Apple Developer Team ID (10-character ID): " CLOUDKIT_TEAM_ID
fi
# Validate required parameters
if [ -z "$CLOUDKIT_CONTAINER_ID" ] || [ -z "$CLOUDKIT_TEAM_ID" ]; then
echo -e "${RED}ERROR: Container ID and Team ID are required.${NC}"
exit 1
fi
# Default to development environment
ENVIRONMENT=${CLOUDKIT_ENVIRONMENT:-development}
echo ""
echo "Configuration:"
echo " Container ID: $CLOUDKIT_CONTAINER_ID"
echo " Team ID: $CLOUDKIT_TEAM_ID"
echo " Environment: $ENVIRONMENT"
echo ""
# Check if schema file exists
SCHEMA_FILE="$(dirname "$0")/../schema.ckdb"
if [ ! -f "$SCHEMA_FILE" ]; then
echo -e "${RED}ERROR: Schema file not found at $SCHEMA_FILE${NC}"
exit 1
fi
echo -e "${GREEN}✓${NC} Schema file found: $SCHEMA_FILE"
echo ""
# Validate schema
echo "Validating schema..."
if xcrun cktool validate-schema \
--team-id "$CLOUDKIT_TEAM_ID" \
--container-id "$CLOUDKIT_CONTAINER_ID" \
--environment "$ENVIRONMENT" \
--file "$SCHEMA_FILE" 2>&1; then
echo -e "${GREEN}✓${NC} Schema validation passed"
else
echo -e "${RED}✗${NC} Schema validation failed"
exit 1
fi
echo ""
# Skip import if dry-run
if [ "$DRY_RUN" = true ]; then
echo ""
echo -e "${GREEN}✓✓✓ Dry run complete! ✓✓✓${NC}"
echo ""
echo "Schema validation passed. Run without --dry-run to import."
exit 0
fi
# Confirm before import
echo -e "${YELLOW}Warning: This will import the schema into your CloudKit container.${NC}"
echo "This operation will create/modify record types in the $ENVIRONMENT environment."
echo ""
read -p "Continue? (y/n) " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
echo "Import cancelled."
exit 0
fi
# Import schema
echo ""
echo "Importing schema to CloudKit..."
if xcrun cktool import-schema \
--team-id "$CLOUDKIT_TEAM_ID" \
--container-id "$CLOUDKIT_CONTAINER_ID" \
--environment "$ENVIRONMENT" \
--file "$SCHEMA_FILE" 2>&1; then
echo ""
echo -e "${GREEN}✓✓✓ Schema import successful! ✓✓✓${NC}"
echo ""
echo "Your CloudKit container now has the following record types:"
echo " • RestoreImage - macOS restore images for virtualization"
echo " • XcodeVersion - Xcode releases with requirements"
echo " • SwiftVersion - Swift compiler versions"
echo " • SDKVersion - Platform SDK builds, with beta → release supersession"
echo " • SimulatorRuntime - Simulator runtimes from Apple's simulator index"
echo " • DataSourceMetadata - Data source tracking metadata"
echo ""
echo "Next steps:"
echo " 1. Get your Server-to-Server Key:"
echo " a. Go to: https://icloud.developer.apple.com/dashboard/"
echo " b. Navigate to: API Access → Server-to-Server Keys"
echo " c. Create a new key and download the private key .pem file"
echo " d. Store it securely (e.g., ~/.cloudkit/swoop-private-key.pem)"
echo ""
echo " 2. Set environment variables:"
echo " export CLOUDKIT_KEY_ID=YOUR_KEY_ID"
echo " export CLOUDKIT_PRIVATE_KEY_PATH=~/.cloudkit/swoop-private-key.pem"
echo " export CLOUDKIT_CONTAINER_ID=$CLOUDKIT_CONTAINER_ID"
echo ""
echo " 3. Run 'swoopmist sync' to populate data:"
echo " .build/debug/swoopmist sync --verbose"
echo ""
echo " 4. Verify data in CloudKit Dashboard: https://icloud.developer.apple.com/"
echo ""
echo " Important: Never commit .pem files to version control!"
echo ""
else
echo ""
echo -e "${RED}✗✗✗ Schema import failed ✗✗✗${NC}"
echo ""
echo "Common issues:"
echo " • Authentication token not saved (run: xcrun cktool save-token)"
echo " • Incorrect container ID or team ID"
echo " • Missing permissions in CloudKit Dashboard"
echo ""
echo "For help, see: https://developer.apple.com/documentation/cloudkit"
exit 1
fi