21 lines
1.5 KiB
Bash
Executable File
21 lines
1.5 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
set +x
|
|
: "${REPORT_ZIP_PASSWORD:?Set REPORT_ZIP_PASSWORD to encrypt publication archives}"
|
|
build_root=${1:-}; artifact_dir=${2:-}
|
|
[[ -n "$build_root" && -n "$artifact_dir" && $# -eq 2 ]]||{ echo "Usage: $0 BUILD_ROOT ARTIFACT_DIR" >&2; exit 2; }
|
|
build_root=$(realpath "$build_root"); mkdir -p "$artifact_dir"; artifact_dir=$(realpath "$artifact_dir")
|
|
for command in zip unzip openssl; do command -v "$command" >/dev/null||{ echo "$command is required" >&2; exit 1; }; done
|
|
stage=$(mktemp -d "${TMPDIR:-/tmp}/report-package.XXXXXXXX"); trap 'rm -rf "$stage"' EXIT
|
|
for category in Reports Diagnostics; do
|
|
source_dir="$build_root/${category,,}/pdfs"; [[ -d "$source_dir" ]]||source_dir="$build_root/${category,,}"
|
|
count=0
|
|
while IFS= read -r -d '' pdf; do [[ -s "$pdf" && $(head -c 5 "$pdf") == '%PDF-' ]]||{ echo "Invalid PDF: $pdf" >&2; exit 1; }; ((count+=1)); done < <(find "$source_dir" -type f -name '*.pdf' -print0)
|
|
((count > 0))||{ echo "No PDFs for $category" >&2; exit 1; }
|
|
(cd "$source_dir" && zip -q -r "$stage/$category.zip" . -i '*.pdf')
|
|
openssl enc -aes-256-cbc -salt -pbkdf2 -pass env:REPORT_ZIP_PASSWORD -in "$stage/$category.zip" -out "$artifact_dir/$category.zip.enc"
|
|
openssl enc -d -aes-256-cbc -pbkdf2 -pass env:REPORT_ZIP_PASSWORD -in "$artifact_dir/$category.zip.enc" -out "$stage/$category.verify.zip"
|
|
unzip -tq "$stage/$category.verify.zip" >/dev/null
|
|
done
|
|
echo "Created encrypted report archives in $artifact_dir"
|