Posted on 03-17-2020 07:01 AM
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
Posted on 03-20-2020 12:18 AM
Interesting - But my script knowledge not that good. Maybe someone else inhere can help, would also be interested in this setup
Posted on 05-04-2020 03:37 AM
Anyone ?
Posted on 05-04-2020 05:00 AM
@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"