mirror of
https://github.com/fleetdm/fleet
synced 2026-05-24 09:28:54 +00:00
Multiple customers have now requested scripts for setting hostnames on macOS, and a couple for Linux. This adds scripts to the solutions folder for that purpose. Linux tested against `Ubuntu 26.04` and `openSUSE Tumbleweed` macOS tested against `Tahoe 26.4.1` <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Documentation** * Added an automated Linux hostname configuration solution that derives a hostname from the device serial, applies it system-wide, and updates host entries. * Added an automated macOS hostname configuration solution that sets ComputerName/LocalHostName/HostName from the device serial and reports the new hostname. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
22 lines
612 B
Bash
22 lines
612 B
Bash
#!/bin/bash
|
|
set -euo pipefail
|
|
|
|
# Get the serial number of the host
|
|
serial_number=$(ioreg -l | grep IOPlatformSerialNumber | awk '{print $4}' | tr -d '"')
|
|
|
|
# Check if the serial number was retrieved successfully
|
|
if [ -z "$serial_number" ]; then
|
|
echo "Error: Could not retrieve the serial number."
|
|
exit 1
|
|
fi
|
|
|
|
# Define the new hostname
|
|
new_hostname="COMPANY-MAC-$serial_number"
|
|
|
|
# Set the new hostname
|
|
sudo scutil --set ComputerName "$new_hostname"
|
|
sudo scutil --set LocalHostName "$new_hostname"
|
|
sudo scutil --set HostName "$new_hostname"
|
|
|
|
# Print the new hostname
|
|
echo "Hostname updated to $new_hostname"
|