mirror of
https://github.com/buildplan/du_setup.git
synced 2025-12-29 16:14:59 +00:00
USERNAME veriable not set error
This commit is contained in:
18
du_setup.sh
18
du_setup.sh
@@ -408,19 +408,25 @@ cleanup_provider_packages() {
|
|||||||
print_section "Provider Package Cleanup (Optional)"
|
print_section "Provider Package Cleanup (Optional)"
|
||||||
|
|
||||||
# Validate required global variables
|
# Validate required global variables
|
||||||
if [[ -z "$LOG_FILE" ]]; then
|
if [[ -z "${LOG_FILE:-}" ]]; then
|
||||||
LOG_FILE="/var/log/du_setup_$(date +%Y%m%d_%H%M%S).log"
|
LOG_FILE="/var/log/du_setup_$(date +%Y%m%d_%H%M%S).log"
|
||||||
echo "Warning: LOG_FILE not set, using: $LOG_FILE"
|
echo "Warning: LOG_FILE not set, using: $LOG_FILE"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ -z "$USERNAME" ]]; then
|
if [[ -z "${USERNAME:-}" ]]; then
|
||||||
print_error "ERROR: USERNAME variable not set. Cannot proceed safely."
|
if [[ $EUID -eq 0 ]]; then
|
||||||
log "cleanup_provider_packages() failed: USERNAME not defined"
|
USERNAME="root"
|
||||||
return 1
|
print_warning "USERNAME not set, defaulting to 'root' for cleanup context."
|
||||||
|
log "USERNAME defaulted to 'root' for cleanup-only mode"
|
||||||
|
else
|
||||||
|
USERNAME="${SUDO_USER:-$USER}"
|
||||||
|
print_warning "USERNAME not set, defaulting to '$USERNAME' for cleanup context."
|
||||||
|
log "USERNAME defaulted to '$USERNAME' for cleanup-only mode"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Validate required variables
|
# Validate required variables
|
||||||
if [[ -z "$BACKUP_DIR" ]]; then
|
if [[ -z "${BACKUP_DIR:-}" ]]; then
|
||||||
BACKUP_DIR="/root/setup_harden_backup_$(date +%Y%m%d_%H%M%S)"
|
BACKUP_DIR="/root/setup_harden_backup_$(date +%Y%m%d_%H%M%S)"
|
||||||
mkdir -p "$BACKUP_DIR"
|
mkdir -p "$BACKUP_DIR"
|
||||||
log "Created backup directory: $BACKUP_DIR"
|
log "Created backup directory: $BACKUP_DIR"
|
||||||
|
|||||||
Reference in New Issue
Block a user