-
Notifications
You must be signed in to change notification settings - Fork 220
Expand file tree
/
Copy pathsync_validation_output.sh
More file actions
47 lines (41 loc) · 1.38 KB
/
Copy pathsync_validation_output.sh
File metadata and controls
47 lines (41 loc) · 1.38 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
#!/bin/bash
# Define the target directory and the required files
TARGET_DIR="files"
REQUIRED_FILES=("Invalid_Repositories.md" "invalid_repositories.json" "repositories.json")
# Function to check for required files in the target directory
check_files() {
for file in "${REQUIRED_FILES[@]}"; do
if [[ ! -f "$1/$file" ]]; then
return 1
fi
done
return 0
}
# Function to read JSON files and echo attributes and values
read_json() {
local json_file="$1"
local file_name=$(basename "$json_file")
# Use jq to extract keys and values from the JSON file
jq -r 'to_entries | .[] | "\(.key): \(.value)"' "$json_file" | while read -r line; do
echo "$file_name - $line"
done
}
# Recursive search for the target directory
search_and_copy() {
for dir in $(find . -type d -name "$TARGET_DIR"); do
if check_files "$dir"; then
echo "Found all required files in: $dir"
for file in "${REQUIRED_FILES[@]}"; do
if [[ "$file" == *.json ]]; then
read_json "$dir/$file" # Read and echo JSON attributes
fi
cp "$dir/$file" .
echo "Copied $file to $(pwd)"
done
return
fi
done
echo "No valid 'files' directory containing all required files found."
}
# Execute the search and copy function
search_and_copy