-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmove_files_to_hgl.sh
More file actions
294 lines (251 loc) · 7.34 KB
/
move_files_to_hgl.sh
File metadata and controls
294 lines (251 loc) · 7.34 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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
#!/usr/bin/env bash
# SPDX-License-Identifier: Apache-2.0
# Move HGL Infrastructure Files to Correct Locations
#
# Usage:
# ./move_files_to_hgl.sh [--dry-run]
#
# This script moves files from the parent directory into the HGL repository structure.
set -euo pipefail
# Colors
COLOR_RESET='\033[0m'
COLOR_GREEN='\033[32m'
COLOR_YELLOW='\033[33m'
COLOR_RED='\033[31m'
COLOR_CYAN='\033[36m'
COLOR_BLUE='\033[34m'
log_info() {
echo -e "${COLOR_CYAN}▶ $*${COLOR_RESET}"
}
log_success() {
echo -e "${COLOR_GREEN}✓ $*${COLOR_RESET}"
}
log_warning() {
echo -e "${COLOR_YELLOW}⚠ $*${COLOR_RESET}"
}
log_error() {
echo -e "${COLOR_RED}✗ $*${COLOR_RESET}" >&2
}
log_header() {
echo -e "${COLOR_BLUE}========================================${COLOR_RESET}"
echo -e "${COLOR_BLUE}$*${COLOR_RESET}"
echo -e "${COLOR_BLUE}========================================${COLOR_RESET}"
}
# Parse arguments
DRY_RUN=false
if [[ "${1:-}" == "--dry-run" ]]; then
DRY_RUN=true
log_warning "DRY RUN MODE - No files will be moved"
echo
fi
# Determine script location and directories
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PARENT_DIR="$(dirname "$SCRIPT_DIR")"
HGL_DIR="$SCRIPT_DIR"
log_header "HGL Infrastructure File Mover"
echo
log_info "Parent directory: $PARENT_DIR"
log_info "HGL directory: $HGL_DIR"
echo
# Define file mappings: SOURCE -> DESTINATION
declare -A FILE_MAP=(
# Verification Scripts
["verify_and_eval.sh"]="tools/verify_and_eval.sh"
["verify_and_eval.ps1"]="tools/verify_and_eval.ps1"
# CI/CD Workflows
["verify_provenance.yml"]=".github/workflows/verify_provenance.yml"
["verify_signatures.yml"]=".github/workflows/verify_signatures.yml"
["verify_policy.yml"]=".github/workflows/verify_policy.yml"
["reproducibility_smoke.yml"]=".github/workflows/reproducibility_smoke.yml"
# Tools
["generate_provenance.py"]="tools/generate_provenance.py"
["generate-hashes.sh"]="tools/generate-hashes.sh"
["pre-commit-hook"]="tools/pre-commit-hook"
# Security Infrastructure
["allowed_signers"]=".github/allowed_signers"
# Documentation
["HGL_GAP_ANALYSIS.md"]="docs/HGL_GAP_ANALYSIS.md"
["IMPLEMENTATION_README.md"]="docs/IMPLEMENTATION_README.md"
["DEPLOYMENT_CHECKLIST.md"]="docs/DEPLOYMENT_CHECKLIST.md"
["PACKAGE_INDEX.md"]="docs/PACKAGE_INDEX.md"
)
# Check which files exist in parent directory
log_header "Checking Source Files"
echo
FOUND_FILES=()
MISSING_FILES=()
for src_file in "${!FILE_MAP[@]}"; do
src_path="$PARENT_DIR/$src_file"
if [[ -f "$src_path" ]]; then
log_success "Found: $src_file"
FOUND_FILES+=("$src_file")
else
log_warning "Missing: $src_file"
MISSING_FILES+=("$src_file")
fi
done
echo
log_info "Summary: ${#FOUND_FILES[@]} files found, ${#MISSING_FILES[@]} missing"
if [[ ${#MISSING_FILES[@]} -gt 0 ]]; then
echo
log_warning "Missing files:"
for missing in "${MISSING_FILES[@]}"; do
echo " - $missing"
done
fi
if [[ ${#FOUND_FILES[@]} -eq 0 ]]; then
echo
log_error "No files found to move!"
log_info "Expected files in: $PARENT_DIR"
exit 1
fi
# Ask for confirmation
echo
if [[ "$DRY_RUN" == false ]]; then
read -p "Continue with moving ${#FOUND_FILES[@]} files? (y/N) " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
log_warning "Aborted by user"
exit 0
fi
fi
# Create necessary directories
log_header "Creating Directories"
echo
DIRECTORIES=(
"tools"
".github"
".github/workflows"
"docs"
)
for dir in "${DIRECTORIES[@]}"; do
dest_dir="$HGL_DIR/$dir"
if [[ ! -d "$dest_dir" ]]; then
if [[ "$DRY_RUN" == false ]]; then
mkdir -p "$dest_dir"
log_success "Created: $dir"
else
log_info "[DRY RUN] Would create: $dir"
fi
else
log_info "Exists: $dir"
fi
done
# Move files
echo
log_header "Moving Files"
echo
MOVED_COUNT=0
SKIPPED_COUNT=0
ERROR_COUNT=0
for src_file in "${FOUND_FILES[@]}"; do
src_path="$PARENT_DIR/$src_file"
dest_path="$HGL_DIR/${FILE_MAP[$src_file]}"
dest_dir=$(dirname "$dest_path")
# Check if destination already exists
if [[ -f "$dest_path" ]]; then
log_warning "Skip: $src_file (destination exists)"
SKIPPED_COUNT=$((SKIPPED_COUNT + 1))
continue
fi
# Move the file
if [[ "$DRY_RUN" == false ]]; then
if mv "$src_path" "$dest_path"; then
log_success "Moved: $src_file -> ${FILE_MAP[$src_file]}"
MOVED_COUNT=$((MOVED_COUNT + 1))
else
log_error "Failed: $src_file"
ERROR_COUNT=$((ERROR_COUNT + 1))
fi
else
log_info "[DRY RUN] Would move: $src_file -> ${FILE_MAP[$src_file]}"
MOVED_COUNT=$((MOVED_COUNT + 1))
fi
done
# Set permissions for executable files
if [[ "$DRY_RUN" == false ]]; then
echo
log_header "Setting Permissions"
echo
EXECUTABLE_FILES=(
"tools/verify_and_eval.sh"
"tools/verify_and_eval.ps1"
"tools/generate_provenance.py"
"tools/generate-hashes.sh"
"tools/pre-commit-hook"
)
for exe_file in "${EXECUTABLE_FILES[@]}"; do
exe_path="$HGL_DIR/$exe_file"
if [[ -f "$exe_path" ]]; then
chmod +x "$exe_path"
log_success "Made executable: $exe_file"
fi
done
fi
# Verify the file structure
echo
log_header "Verifying File Structure"
echo
VERIFICATION_OK=true
for src_file in "${FOUND_FILES[@]}"; do
dest_path="$HGL_DIR/${FILE_MAP[$src_file]}"
if [[ -f "$dest_path" ]]; then
log_success "Verified: ${FILE_MAP[$src_file]}"
else
if [[ "$DRY_RUN" == false ]]; then
log_error "Missing: ${FILE_MAP[$src_file]}"
VERIFICATION_OK=false
fi
fi
done
# Display final summary
echo
log_header "Summary"
echo
if [[ "$DRY_RUN" == false ]]; then
echo "Files moved: $MOVED_COUNT"
echo "Files skipped: $SKIPPED_COUNT"
echo "Errors: $ERROR_COUNT"
echo
if [[ $ERROR_COUNT -gt 0 ]]; then
log_error "Some files failed to move!"
exit 1
elif [[ $MOVED_COUNT -eq 0 ]]; then
log_warning "No files were moved (all destinations exist)"
else
log_success "All files moved successfully!"
fi
if [[ "$VERIFICATION_OK" == false ]]; then
log_warning "Some files failed verification"
exit 1
fi
else
echo "Files to move: $MOVED_COUNT"
echo "Files to skip: $SKIPPED_COUNT"
echo
log_info "This was a dry run - no files were actually moved"
log_info "Run without --dry-run to move files"
fi
# Show next steps
if [[ "$DRY_RUN" == false ]] && [[ $MOVED_COUNT -gt 0 ]]; then
echo
log_header "Next Steps"
echo
echo "1. Review the moved files:"
echo " tree -L 2 tools/ .github/ docs/"
echo
echo "2. Update .github/allowed_signers with your actual keys:"
echo " nano .github/allowed_signers"
echo
echo "3. Test the verification scripts:"
echo " ./tools/verify_and_eval.sh releases/HGL-v1.2-beta.1"
echo
echo "4. Commit the changes:"
echo " git add tools/ .github/ docs/"
echo " git commit -m 'Infrastructure: Add verification tooling and CI/CD workflows'"
echo
echo "5. Follow the deployment checklist:"
echo " cat docs/DEPLOYMENT_CHECKLIST.md"
echo
fi
exit 0