Files
gniza4cp/scripts/uninstall.sh
shuki 1f68ea1058 Security hardening, static analysis fixes, and expanded test coverage
- Fix CRITICAL: safe config parser replacing shell source, sshpass -e,
  CSRF with /dev/urandom, symlink-safe file I/O
- Fix HIGH: input validation for timestamps/accounts, path traversal
  prevention in Runner.pm, AJAX CSRF on all endpoints
- Fix MEDIUM: umask 077, chmod 700 on config dirs, Config.pm TOCTOU lock,
  rsync exit code capture bug, RSYNC_EXTRA_OPTS character validation
- ShellCheck: fix word-splitting in notify.sh, safe rm in pkgacct.sh,
  suppress cross-file SC2034 false positives
- Perl::Critic: return undef→bare return, return (sort), unpack @_,
  explicit return on void subs, rename Config::write→save
- Remove dead code: enforce_retention_all(), rsync_dry_run()
- Add require_cmd checks for rsync/ssh/hostname/gzip at startup
- Escape $hint/$tip in CGI helper functions for defense-in-depth
- Expand tests from 17→40: validate_timestamp, validate_account_name,
  _safe_source_config (including malicious input), numeric validation

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-04 23:57:26 +02:00

68 lines
2.2 KiB
Bash
Executable File

#!/usr/bin/env bash
# gniza uninstall script
set -euo pipefail
INSTALL_DIR="/usr/local/gniza"
BIN_LINK="/usr/local/bin/gniza"
if [[ $EUID -ne 0 ]]; then
echo "Error: uninstall.sh must be run as root" >&2
exit 1
fi
echo "Uninstalling gniza..."
# Remove symlink
if [[ -L "$BIN_LINK" ]]; then
rm -f "$BIN_LINK"
echo "Removed $BIN_LINK"
fi
# Remove install directory
if [[ -d "$INSTALL_DIR" ]]; then
rm -rf "$INSTALL_DIR"
echo "Removed $INSTALL_DIR"
fi
# ── Remove cron entries ───────────────────────────────────────
if crontab -l 2>/dev/null | grep -q '# gniza:'; then
echo "Removing gniza cron entries..."
crontab -l 2>/dev/null | grep -v '# gniza:' | grep -v '/usr/local/bin/gniza' | crontab -
echo "Cron entries removed."
fi
# ── WHM Plugin ────────────────────────────────────────────────
WHM_CGI_DIR="/usr/local/cpanel/whostmgr/docroot/cgi"
if [[ -d "$WHM_CGI_DIR/gniza-whm" ]]; then
echo "Removing WHM plugin..."
/usr/local/cpanel/bin/unregister_appconfig gniza-whm 2>/dev/null || true
rm -rf "$WHM_CGI_DIR/gniza-whm"
echo "WHM plugin removed."
fi
# ── cPanel User Plugin ────────────────────────────────────────
CPANEL_BASE="/usr/local/cpanel/base/frontend/jupiter"
ADMINBIN_DIR="/usr/local/cpanel/bin/admin/Gniza"
if [[ -d "$CPANEL_BASE/gniza" ]]; then
echo "Removing cPanel user plugin..."
/usr/local/cpanel/scripts/uninstall_plugin "$CPANEL_BASE/gniza/install.json" 2>/dev/null || true
rm -rf "$CPANEL_BASE/gniza"
echo "cPanel user plugin removed."
fi
if [[ -d "$ADMINBIN_DIR" ]]; then
rm -rf "$ADMINBIN_DIR"
echo "AdminBin module removed."
fi
echo ""
echo "gniza uninstalled."
echo ""
echo "The following were NOT removed (manual cleanup if desired):"
echo " /etc/gniza/ (configuration + remotes.d/)"
echo " /var/log/gniza/ (log files)"
echo " /var/run/gniza.lock (lock file)"
echo ""
echo "To remove configs: rm -rf /etc/gniza/"
echo "To remove logs: rm -rf /var/log/gniza/"