Merge pull request #73 from PR0M3TH3AN/codex/add-trap-commands-to-remove-temp-files

Add cleanup traps to shell scripts
This commit is contained in:
thePR0M3TH3AN
2025-06-21 12:25:03 -04:00
committed by GitHub
3 changed files with 20 additions and 6 deletions

View File

@@ -18,12 +18,16 @@ tear=$(jq -r '.tear_off_link' "$CONFIG")
tmp_content=$(mktemp)
tmp_tear=$(mktemp)
cleanup() {
rm -f "$tmp_content" "$tmp_tear"
}
trap cleanup EXIT
qrencode -o "$tmp_content" -s 10 -m 0 "$url"
qrencode -o "$tmp_tear" -s 10 -m 0 "$tear"
convert "$tmp_content" -resize 128x128 "qrcode-content.png"
convert "$tmp_tear" -resize 128x128 "qrcode-tear-offs.png"
rm -f "$tmp_content" "$tmp_tear"
echo "QR codes generated"

View File

@@ -31,6 +31,12 @@ temp_js_file=$(mktemp_with_suffix .js) # Temporary .js file for extracting Java
temp_js_obfuscated_file=$(mktemp_with_suffix .js) # Temporary file for obfuscated JavaScript
temp_html_file=$(mktemp) # Temporary file for processing HTML without JS
cleanup() {
rm -f "$temp_js_file" "$temp_js_obfuscated_file" "$temp_html_file"
}
trap cleanup EXIT
# Check if the input file exists
if [ ! -f "$input_file" ]; then
echo "Input file $input_file does not exist."
@@ -61,7 +67,6 @@ html-minifier-terser \
--output "$output_file" \
"$temp_html_file"
# Clean up temporary files
rm "$temp_js_file" "$temp_js_obfuscated_file" "$temp_html_file"
# Clean up temporary files handled by trap
echo "Obfuscation and minification complete. Output saved as $output_file."

View File

@@ -31,6 +31,12 @@ temp_js_file=$(mktemp_with_suffix .js) # Temporary .js file for extracting Java
temp_js_obfuscated_file=$(mktemp_with_suffix .js) # Temporary file for obfuscated JavaScript
temp_html_file=$(mktemp) # Temporary file for processing HTML without JS
cleanup() {
rm -f "$temp_js_file" "$temp_js_obfuscated_file" "$temp_html_file"
}
trap cleanup EXIT
# Check if the input file exists
if [ ! -f "$input_file" ]; then
echo "Input file $input_file does not exist."
@@ -61,7 +67,6 @@ html-minifier-terser \
--output "$output_file" \
"$temp_html_file"
# Clean up temporary files
rm "$temp_js_file" "$temp_js_obfuscated_file" "$temp_html_file"
# Clean up temporary files handled by trap
echo "Obfuscation and minification complete. Output saved as $output_file."