Skip to content

Conversation

@shbhmexe
Copy link
Contributor

@shbhmexe shbhmexe commented Dec 5, 2025

Summary

This PR delivers two focused, low-risk fixes that improve safety and correctness of shell scripts without changing any features:

  1. util_sh/db_data_mv.sh
  • Add strict mode (set -euo pipefail).
  • Validate input argument (non-empty, directory must exist) and guard dangerous operations.
  • Create destination parent directories to avoid cp failures when subpaths are provided.
  • Use cp -a -v -- to preserve attributes and robustly copy data.
  • Quote and guard rm -rf and path arguments (--) to prevent accidental deletions when variables are empty or contain spaces.
  • Keep existing ownership/permission adjustments.
  1. grafana/shared/grafana_start.sh
  • Quote destructive cleanup targets:
    • rm -f -- "$f"/*
    • rm -rf -- "$f"
  • Prevents pathname/globbing issues during cleanup; behavior is unchanged as long as $f points to a valid directory.
  1. cron/backup_artificial.sh
  • Add strict mode, quote variables, and guard rm/mv/tar targets (--, quotes) to avoid unintended deletions and path issues.
  • Keep output, file names, and exit codes identical.
  1. util_sh/sort_json.sh
  • Add strict mode, create temp file in current directory using mktemp, quote paths, and avoid UUOC.
  • Behavior unchanged: stable key-sorted JSON written back atomically.

Reasoning and impact

  • Prevents accidental deletions if variables are unset/empty or contain whitespace.
  • Avoids subtle failures when destination parent directories do not exist.
  • Improves script robustness in automation/CI and container environments.
  • No change to intended behavior or outputs.

Files changed

  • util_sh/db_data_mv.sh
  • grafana/shared/grafana_start.sh
  • cron/backup_artificial.sh
  • util_sh/sort_json.sh

Enhanced quoting, error handling, and strict mode in backup_artificial.sh, db_data_mv.sh, sort_json.sh, and grafana_start.sh. These changes prevent accidental data loss, improve robustness, and ensure safer file operations. Added a new empty file XcwSsn.

Signed-off-by: shbhmexe <[email protected]>
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.

1 participant