echo to printf

This commit is contained in:
buildplan 2025-10-16 18:29:39 +01:00
parent 4a5ea2b278
commit 901061e521

View File

@ -607,7 +607,7 @@ cleanup_provider_packages() {
if [[ "$CLEANUP_PREVIEW" == "true" ]]; then if [[ "$CLEANUP_PREVIEW" == "true" ]]; then
print_warning "=== PREVIEW MODE ENABLED ===" print_warning "=== PREVIEW MODE ENABLED ==="
print_info "No changes will be made. This is a simulation only." print_info "No changes will be made. This is a simulation only."
echo printf '\n'
fi fi
if [[ "$CLEANUP_PREVIEW" == "false" ]]; then if [[ "$CLEANUP_PREVIEW" == "false" ]]; then
@ -731,17 +731,17 @@ cleanup_provider_packages() {
if [[ "$CLEANUP_PREVIEW" == "true" ]]; then if [[ "$CLEANUP_PREVIEW" == "true" ]]; then
print_info "=== PREVIEW: Showing what would be done ===" print_info "=== PREVIEW: Showing what would be done ==="
echo printf '\n'
fi fi
# Audit and optionally clean up root SSH keys # Audit and optionally clean up root SSH keys
if [[ ${#ROOT_SSH_KEYS[@]} -gt 0 ]]; then if [[ ${#ROOT_SSH_KEYS[@]} -gt 0 ]]; then
print_section "Root SSH Key Audit" print_section "Root SSH Key Audit"
print_warning "SSH keys in /root/.ssh/authorized_keys can allow provider or previous admins access." print_warning "SSH keys in /root/.ssh/authorized_keys can allow provider or previous admins access."
echo printf '\n'
printf '%s\n' "${YELLOW}Current keys in /root/.ssh/authorized_keys:${NC}" printf '%s\n' "${YELLOW}Current keys in /root/.ssh/authorized_keys:${NC}"
awk '{print NR". "$0}' /root/.ssh/authorized_keys 2>/dev/null | head -20 awk '{print NR". "$0}' /root/.ssh/authorized_keys 2>/dev/null | head -20
echo printf '\n'
if [[ "$CLEANUP_PREVIEW" == "true" ]]; then if [[ "$CLEANUP_PREVIEW" == "true" ]]; then
print_info "[PREVIEW] Would offer to review and edit /root/.ssh/authorized_keys" print_info "[PREVIEW] Would offer to review and edit /root/.ssh/authorized_keys"
@ -777,7 +777,7 @@ cleanup_provider_packages() {
print_info "Skipping root SSH key audit." print_info "Skipping root SSH key audit."
fi fi
fi fi
echo printf '\n'
fi fi
# Special handling for cloud-init due to its complexity # Special handling for cloud-init due to its complexity
@ -841,7 +841,7 @@ cleanup_provider_packages() {
else else
print_info "Keeping cloud-init enabled." print_info "Keeping cloud-init enabled."
fi fi
echo printf '\n'
fi fi
# Remove identified provider packages # Remove identified provider packages
@ -916,14 +916,14 @@ cleanup_provider_packages() {
print_info "Keeping $pkg." print_info "Keeping $pkg."
fi fi
done done
echo printf '\n'
fi fi
# Check and remove default users # Check and remove default users
if [[ ${#PROVIDER_USERS[@]} -gt 0 ]]; then if [[ ${#PROVIDER_USERS[@]} -gt 0 ]]; then
print_section "Provider User Cleanup" print_section "Provider User Cleanup"
print_warning "Default users created during provisioning can be security risks." print_warning "Default users created during provisioning can be security risks."
echo printf '\n'
for user in "${PROVIDER_USERS[@]}"; do for user in "${PROVIDER_USERS[@]}"; do
printf '%s\n' "${YELLOW}Found user: $user${NC}" printf '%s\n' "${YELLOW}Found user: $user${NC}"
@ -946,7 +946,7 @@ cleanup_provider_packages() {
print_warning "User $user has sudo/admin privileges!" print_warning "User $user has sudo/admin privileges!"
fi fi
echo printf '\n'
if [[ "$CLEANUP_PREVIEW" == "true" ]] || confirm "Remove user $user and their home directory?" "n"; then if [[ "$CLEANUP_PREVIEW" == "true" ]] || confirm "Remove user $user and their home directory?" "n"; then
if [[ "$CLEANUP_PREVIEW" == "true" ]]; then if [[ "$CLEANUP_PREVIEW" == "true" ]]; then
@ -1006,7 +1006,7 @@ cleanup_provider_packages() {
print_info "Keeping user $user." print_info "Keeping user $user."
fi fi
done done
echo printf '\n'
fi fi
# Final cleanup step # Final cleanup step
@ -1026,7 +1026,7 @@ cleanup_provider_packages() {
log "Provider package cleanup completed." log "Provider package cleanup completed."
if [[ "$CLEANUP_PREVIEW" == "true" ]]; then if [[ "$CLEANUP_PREVIEW" == "true" ]]; then
echo printf '\n'
print_success "=== PREVIEW COMPLETED ===" print_success "=== PREVIEW COMPLETED ==="
print_info "No changes were made to the system." print_info "No changes were made to the system."
print_info "Run without --cleanup-preview flag to execute these actions." print_info "Run without --cleanup-preview flag to execute these actions."
@ -1388,9 +1388,9 @@ setup_user() {
print_info "Set a password for '$USERNAME' (required for sudo, or press Enter twice to skip for key-only access):" print_info "Set a password for '$USERNAME' (required for sudo, or press Enter twice to skip for key-only access):"
while true; do while true; do
read -rsp "$(printf '%s' "${CYAN}New password: ${NC}")" PASS1 read -rsp "$(printf '%s' "${CYAN}New password: ${NC}")" PASS1
echo printf '\n'
read -rsp "$(printf '%s' "${CYAN}Retype new password: ${NC}")" PASS2 read -rsp "$(printf '%s' "${CYAN}Retype new password: ${NC}")" PASS2
echo printf '\n'
if [[ -z "$PASS1" && -z "$PASS2" ]]; then if [[ -z "$PASS1" && -z "$PASS2" ]]; then
print_warning "Password skipped. Relying on SSH key authentication." print_warning "Password skipped. Relying on SSH key authentication."
log "Password setting skipped for '$USERNAME'." log "Password setting skipped for '$USERNAME'."
@ -3290,7 +3290,7 @@ generate_summary() {
else else
printf " %-20s ${YELLOW}⚠ Not Performed${NC}\n" "Security Audit" printf " %-20s ${YELLOW}⚠ Not Performed${NC}\n" "Security Audit"
fi fi
echo printf '\n'
# --- Main Configuration Summary --- # --- Main Configuration Summary ---
printf '%s\n' "${YELLOW}Configuration Summary:${NC}" printf '%s\n' "${YELLOW}Configuration Summary:${NC}"
@ -3378,7 +3378,7 @@ generate_summary() {
else else
printf '%s\n' " Security Audit: ${RED}Not run${NC}" printf '%s\n' " Security Audit: ${RED}Not run${NC}"
fi fi
echo printf '\n'
# --- Post-Reboot Verification Steps --- # --- Post-Reboot Verification Steps ---
printf '%s\n' "${YELLOW}Post-Reboot Verification Steps:${NC}" printf '%s\n' "${YELLOW}Post-Reboot Verification Steps:${NC}"
@ -3410,7 +3410,7 @@ generate_summary() {
printf '%s\n' " ${YELLOW}Security Audit:${NC}" printf '%s\n' " ${YELLOW}Security Audit:${NC}"
printf " %-23s ${CYAN}%s${NC}\n" "- Check results:" "sudo less ${AUDIT_LOG:-/var/log/syslog}" printf " %-23s ${CYAN}%s${NC}\n" "- Check results:" "sudo less ${AUDIT_LOG:-/var/log/syslog}"
fi fi
echo printf '\n'
# --- Final Warnings and Actions --- # --- Final Warnings and Actions ---
if [[ ${#FAILED_SERVICES[@]} -gt 0 ]]; then if [[ ${#FAILED_SERVICES[@]} -gt 0 ]]; then