Implement self-deletion of setup and customization scripts after successful execution. Enhance user password setting process with retry logic for both sysadmin and additional users, improving error handling and user feedback during setup.
This commit is contained in:
@@ -247,6 +247,11 @@ main() {
|
|||||||
echo ""
|
echo ""
|
||||||
echo -e "${GREEN}Server customization completed!${NC}"
|
echo -e "${GREEN}Server customization completed!${NC}"
|
||||||
echo -e "${YELLOW}You may need to log out and back in to see the hostname change.${NC}"
|
echo -e "${YELLOW}You may need to log out and back in to see the hostname change.${NC}"
|
||||||
|
|
||||||
|
# Self-delete the script after successful completion
|
||||||
|
log "Cleaning up customization script..."
|
||||||
|
rm -f "$0"
|
||||||
|
log "Customization script deleted successfully"
|
||||||
}
|
}
|
||||||
|
|
||||||
main "$@"
|
main "$@"
|
||||||
47
setup.sh
47
setup.sh
@@ -329,9 +329,24 @@ create_sysadmin_user() {
|
|||||||
log "User $SYSADMIN_USER created successfully"
|
log "User $SYSADMIN_USER created successfully"
|
||||||
SYSADMIN_USER_CREATED="yes"
|
SYSADMIN_USER_CREATED="yes"
|
||||||
|
|
||||||
# Set password for sysadmin user
|
# Set password for sysadmin user with retry logic
|
||||||
echo "Please set a password for user $SYSADMIN_USER:"
|
local max_attempts=3
|
||||||
passwd "$SYSADMIN_USER"
|
local attempt=1
|
||||||
|
|
||||||
|
while [ $attempt -le $max_attempts ]; do
|
||||||
|
echo "Please set a password for user $SYSADMIN_USER (attempt $attempt of $max_attempts):"
|
||||||
|
if passwd "$SYSADMIN_USER"; then
|
||||||
|
log "Password set successfully for $SYSADMIN_USER"
|
||||||
|
break
|
||||||
|
else
|
||||||
|
warn "Failed to set password for $SYSADMIN_USER"
|
||||||
|
if [ $attempt -eq $max_attempts ]; then
|
||||||
|
error "Failed to set password after $max_attempts attempts. Exiting."
|
||||||
|
fi
|
||||||
|
echo "Please try again..."
|
||||||
|
((attempt++))
|
||||||
|
fi
|
||||||
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Add sysadmin to sudo group
|
# Add sysadmin to sudo group
|
||||||
@@ -352,9 +367,24 @@ create_additional_user() {
|
|||||||
log "User $ADDITIONAL_USER created successfully"
|
log "User $ADDITIONAL_USER created successfully"
|
||||||
ADDITIONAL_USER_CREATED="yes"
|
ADDITIONAL_USER_CREATED="yes"
|
||||||
|
|
||||||
# Set password for additional user
|
# Set password for additional user with retry logic
|
||||||
echo "Please set a password for user $ADDITIONAL_USER:"
|
local max_attempts=3
|
||||||
passwd "$ADDITIONAL_USER"
|
local attempt=1
|
||||||
|
|
||||||
|
while [ $attempt -le $max_attempts ]; do
|
||||||
|
echo "Please set a password for user $ADDITIONAL_USER (attempt $attempt of $max_attempts):"
|
||||||
|
if passwd "$ADDITIONAL_USER"; then
|
||||||
|
log "Password set successfully for $ADDITIONAL_USER"
|
||||||
|
break
|
||||||
|
else
|
||||||
|
warn "Failed to set password for $ADDITIONAL_USER"
|
||||||
|
if [ $attempt -eq $max_attempts ]; then
|
||||||
|
error "Failed to set password after $max_attempts attempts. Exiting."
|
||||||
|
fi
|
||||||
|
echo "Please try again..."
|
||||||
|
((attempt++))
|
||||||
|
fi
|
||||||
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Add additional user to sudo group (existing or newly created)
|
# Add additional user to sudo group (existing or newly created)
|
||||||
@@ -629,6 +659,11 @@ main() {
|
|||||||
|
|
||||||
# Finalize
|
# Finalize
|
||||||
finalize_setup
|
finalize_setup
|
||||||
|
|
||||||
|
# Self-delete the script after successful completion
|
||||||
|
log "Cleaning up setup script..."
|
||||||
|
rm -f "$0"
|
||||||
|
log "Setup script deleted successfully"
|
||||||
}
|
}
|
||||||
|
|
||||||
main "$@"
|
main "$@"
|
||||||
|
|||||||
Reference in New Issue
Block a user