-
Notifications
You must be signed in to change notification settings - Fork 205
/
zip_script.sh
executable file
·33 lines (26 loc) · 1.07 KB
/
zip_script.sh
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
#!/bin/bash
version="$1"
format="$2"
zip_file="$3"
# Create a temporary directory to store the compatible config files
temp_dir=$(mktemp -d)
# Find folders containing config.yaml within the Mods directory and its subdirectories
IFS=$'\n' # Set the IFS (Internal Field Separator) to handle folder names with spaces
folders=($(find . -type f -name "config.yaml" -exec dirname {} \;))
# Iterate through the folders
for folder in "${folders[@]}"; do
# Read the game versions using yq and store them in an array using mapfile
result=$(yq e ".game.version[] | select(. == \"$version\")" "$folder/config.yaml")
if [[ -n $result ]]; then
# Copy the folder to the temporary directory
mkdir -p "$temp_dir/$folder" && cp -r "$folder" "$temp_dir/$folder/../"
fi
done
# Create a zip file containing the compatible folders
7z a -t"$format" -mx9 "$zip_file" "$temp_dir/*"
7z a -t"$format" -mx9 "$zip_file" "README.md"
7z a -t"$format" -mx9 "$zip_file" "LICENSE"
7z a -t"$format" -mx9 "$zip_file" "Guide"
# Clean up the temporary directory
rm -rf "$temp_dir"
echo "Zip file created: $zip_file"