Skip to main content

So when enrolling a mac, I would like it to be automatically named based on which country it is enrolled in



So Mac should first lookup like



curl https://freegeoip.app/xml/



and based on country code the mac should be named like "US-%serialnumber%



Serial number can be found
serialNumber=$( ioreg -c IOPlatformExpertDevice -d 2 | awk -F" '/IOPlatformSerialNumber/{print $(NF-1)}' )



I am not very good scripting, so hope someone can have some input how this could be done

Interesting - But my script knowledge not that good. Maybe someone else inhere can help, would also be interested in this setup


Anyone ?


@jameson Give this a shot.



#!/bin/sh

getCountryCode=$(curl https://freegeoip.app/xml/ | xpath /Response/CountryCode)
countryCode=$(echo $getCountryCode | sed 's/<CountryCode>//g' | sed 's/</CountryCode>/'$'
/g')

echo $countryCode

serialNumber=$( ioreg -c IOPlatformExpertDevice -d 2 | awk -F" '/IOPlatformSerialNumber/{print $(NF-1)}' )

computerName=$countryCode-$serialNumber

echo $computerName

networksetup -setcomputername "$computerName"
scutil --set LocalHostName "$computerName"
scutil --set HostName "$computerName"
sudo defaults write /Library/Preferences/SystemConfiguration/com.apple.smb.server NetBIOSName "$computerName"