chore: Messed up git stuff brought back

This commit is contained in:
Pratik Tripathy
2025-09-08 17:46:36 +05:30
parent 784dcfefcb
commit 4030f25ba9

View File

@@ -62,10 +62,16 @@ EOF
exit 1 exit 1
} }
parse_args() { parse_and_validate_args() {
while [ "$#" -gt 0 ]; do while [ "$#" -gt 0 ]; do
case "$1" in case "$1" in
-u | --username) -u | --username)
# Check if username already exists
if id -u "$2" >/dev/null 2>&1; then
console_log "ERROR" "User $2 already exists"
exit 1
fi
# Validate username format # Validate username format
if [ -n "$2" ] && echo "$2" | grep -qE '^[a-zA-Z][a-zA-Z0-9_-]*$'; then if [ -n "$2" ] && echo "$2" | grep -qE '^[a-zA-Z][a-zA-Z0-9_-]*$'; then
USERNAME="$2" USERNAME="$2"
@@ -287,27 +293,26 @@ reset_root_password() {
} }
revert_create_user() { revert_create_user() {
console_log "INFO" "Attempting to remove user $USERNAME"
file_log "INFO" "Attempting to remove user $USERNAME" file_log "INFO" "Attempting to remove user $USERNAME"
# Check if the user exists before attempting to remove # Check if the user exists before attempting to remove
if id "$USERNAME" >/dev/null 2>&1; then if id "$USERNAME" >/dev/null 2>&1; then
# Remove user and its home directory # Remove user and its home directory
output=$(userdel -r "$USERNAME" 2>&1) output=$(userdel -r "$USERNAME" 2>&1)
if [ -n "$output" ]; then command_status=$?
file_log "INFO" "userdel command output: $output" file_log "INFO" "$output"
fi
# shellcheck disable=SC2181 if [ $command_status -eq 0 ]; then
if [ $? -eq 0 ]; then console_log "SUCCESS" "User $USERNAME and home directory removed"
file_log "SUCCESS" "User $USERNAME and home directory removed successfully" file_log "SUCCESS" "User $USERNAME and home directory removed"
return 0
else else
console_log "ERROR" "Failed to remove user $USERNAME"
file_log "ERROR" "Failed to remove user $USERNAME" file_log "ERROR" "Failed to remove user $USERNAME"
return 1
fi fi
else else
console_log "WARNING" "No user $USERNAME found to remove"
file_log "WARNING" "No user $USERNAME found to remove" file_log "WARNING" "No user $USERNAME found to remove"
return 0
fi fi
} }
@@ -814,14 +819,9 @@ main() {
fi fi
# Step 5: Install required packages # Step 5: Install required packages
console_log "INFO" "Installing required packages..." if ! install_packages; then
file_log "INFO" "Installing required packages..."
if ! install_package "curl ufw fail2ban"; then
console_log "ERROR" "Failed to install required packages"
print_logfile_details
return 1 # Abort on error return 1 # Abort on error
fi fi
console_log "SUCCESS" "Successfully installed all required packages"
# Step 6: Configure UFW # Step 6: Configure UFW
console_log "INFO" "Configuring UFW..." console_log "INFO" "Configuring UFW..."