forked from CinemaMod/java-cef
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#!/bin/bash | ||
|
||
# Function to create SHA256 hash for a file | ||
create_sha256_file() { | ||
sha256sum "$1" | cut -d ' ' -f 1 | ||
} | ||
|
||
# Function to update .tar.gz files with .hash and .sha256 | ||
update_tar_gz() { | ||
local input_file="$1" | ||
local output_folder="./output" | ||
local output_file="$output_folder/$(basename "$input_file")" | ||
|
||
# Create a temporary directory for extraction | ||
local tmp_dir="$(mktemp -d)" | ||
|
||
# Extract files from .tar.gz | ||
tar -xzf "$input_file" -C "$tmp_dir" | ||
|
||
# Create a .hash file with SHA256 hashes | ||
jq -n '{}' > "$tmp_dir/.hash" | ||
find "$tmp_dir" -type f | while read -r file; do | ||
relative_path="${file#$tmp_dir/}" | ||
if [ "$relative_path" != ".hash" ]; then | ||
hash_value=$(create_sha256_file "$file") | ||
jq --arg file "$relative_path" --arg hash "$hash_value" '.[$file] = $hash' "$tmp_dir/.hash" > "$tmp_dir/.hash_tmp" && mv "$tmp_dir/.hash_tmp" "$tmp_dir/.hash" | ||
fi | ||
done | ||
|
||
|
||
# Create a new compressed .tar file | ||
tar -czf "$output_file" -C "$tmp_dir" . | ||
|
||
# Clean up temporary directory | ||
rm -rf "$tmp_dir" | ||
|
||
# Create a .sha256 file for the updated .tar.gz | ||
sha256_hash=$(create_sha256_file "$output_file") | ||
echo "$sha256_hash" > "$output_folder/$(basename "$input_file").sha256" | ||
} | ||
|
||
# Process all .tar.gz files in the current directory | ||
for file_name in *.tar.gz; do | ||
if [ -f "$file_name" ]; then | ||
update_tar_gz "$file_name" | ||
echo "Processing completed for $file_name" | ||
fi | ||
done |