Skip to content

Enhance UFW error handling and simplify documentation#34

Merged
StrangeRanger merged 18 commits into
mainfrom
dev
May 21, 2026
Merged

Enhance UFW error handling and simplify documentation#34
StrangeRanger merged 18 commits into
mainfrom
dev

Conversation

@StrangeRanger
Copy link
Copy Markdown
Owner

This pull request introduces several improvements and fixes to the ufw-cloudflare.bash script, focusing on error handling, script robustness, and user experience. The most significant changes include stricter Bash error handling, a new diagnostic error trap, improved backup procedures, and more reliable rule modification logic.

Error handling and robustness:

  • Enabled strict Bash error handling with set -euo pipefail to ensure the script exits on errors and undefined variables.
  • Added a diagnostic ERR trap (on_err) that reports the failing command and line number before exiting, making debugging easier.

Backup and restoration improvements:

  • The UFW backup archive is now created as a gzip-compressed tar archive for better storage and transfer.
  • The script now tracks whether modifications are in progress using a boolean, ensuring that backups are only restored if necessary. [1] [2] [3] [4]

Rule modification logic and user experience:

  • The UFW active-status check is moved after the user confirmation prompt, and the script exits with an error if UFW is not active.
  • The pipeline for deleting rules (yes | ufw delete) is replaced with a single y response to avoid SIGPIPE failures under pipefail.
  • The script now waits for changes to take effect only when necessary, preventing duplicate or unnecessary wait messages. [1] [2] [3] [4]

Other improvements:

  • The Cloudflare UFW comment constant is now reused when reading existing Cloudflare-marked rules, improving maintainability.
  • The version is updated to v1.0.3 and the changelog is updated to reflect all recent changes. [1] [2]

Copilot AI review requested due to automatic review settings May 21, 2026 18:24
@codacy-production
Copy link
Copy Markdown

codacy-production Bot commented May 21, 2026

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR hardens the ufw-cloudflare.bash script by enabling strict Bash error handling, adding an ERR diagnostic trap, and simplifying/clarifying the rule modification flow and documentation so failures are easier to debug and recover from.

Changes:

  • Enable set -euo pipefail and add an ERR trap to surface failing commands/line numbers.
  • Rework backup/restore flow using a modifications_in_progress boolean and gzip-compressed tar archives.
  • Adjust rule deletion/wait logic and reuse the Cloudflare comment constant for rule discovery.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.

File Description
hardening/UFW Cloudflare/ufw-cloudflare.bash Adds strict mode + ERR trap, revises backup/restore and rule update flow for Cloudflare-marked UFW rules.
hardening/UFW Cloudflare/CHANGELOG.md Documents v1.0.3 changes and minor formatting/consistency updates.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread hardening/UFW Cloudflare/ufw-cloudflare.bash Outdated
Comment thread hardening/UFW Cloudflare/ufw-cloudflare.bash
Comment thread hardening/UFW Cloudflare/ufw-cloudflare.bash
Comment thread hardening/UFW Cloudflare/ufw-cloudflare.bash
Comment thread hardening/UFW Cloudflare/CHANGELOG.md Outdated
@StrangeRanger StrangeRanger merged commit bffb501 into main May 21, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants