Last active
October 29, 2024 17:30
-
-
Save marshki/d52c03874caea02a2756c7486ee92bf5 to your computer and use it in GitHub Desktop.
BigFix auto installer for macOS, written in Bash.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# | |
# fixer | |
# | |
# Download, unzip, and install BigFix in macOS. | |
# A device's unique identifier in the BigFix console is its serial number. | |
# 'Computer name' is set to serial number in this script. | |
# | |
# Author: M. Krinitz <mjk235 [at] nyu [dot] edu> | |
# Date: 2024-10-10 | |
# License: MIT | |
######### | |
# Globals | |
######### | |
# URL of server hosting installer. | |
URL="http://" | |
# Zip file. | |
FILE="fixer.zip" | |
# Components of .zip package. | |
BIGFIX_COMPONENT=( | |
ActionSite.afxm | |
BESAgent-11.0.3.82-BigFix_MacOS11.0.pkg | |
clientsettings.cfg | |
) | |
######## | |
# Fixer. | |
######## | |
# Is current UID 0? If not, exit. | |
root_check() { | |
if [ "$EUID" -ne "0" ] ; then | |
printf "%s\n" "Error: root privileges are required to continue."\ | |
"Try: sudo bash fixer.sh instead." >&2 | |
exit 1 | |
fi | |
} | |
# Get serial number. | |
get_serial_number() { | |
serialnum=$(system_profiler SPHardwareDataType | awk '/Serial/ {print $4}') | |
} | |
######################## | |
# A note about `scutil`. | |
# macOS uses `scutil` to manage system configuration parameters (e.g. computer name). | |
# A device's name is set via scutil arguments (ComputerName, HostName, and LocalHostName). | |
# For reference: https://ss64.com/mac/scutil.html | |
######################## | |
# Get computer name. | |
get_computer_name() { | |
computername=$(scutil --get ComputerName) | |
} | |
# Set "computer name" to serial number via `scutil`. | |
set_computer_name() { | |
if [ "$serialnum" != "$computername" ]; then | |
printf "%s\n" "Setting 'Computer Name'..." | |
scutil --set ComputerName "$serialnum" | |
scutil --set HostName "$serialnum" | |
scutil --set LocalHostName "$serialnum" | |
fi | |
} | |
# Retrieve .zip and place in /Applications. | |
retrieve_zip() { | |
printf "%s\n" "Retrieving .zip file..." | |
curl --progress-bar --retry 3 --retry-delay 5 "$URL/$FILE" --output /Applications/"$FILE" | |
if [ $? -ne 0 ]; then | |
printf "%s\n" "Error: Downloading $FILE failed." >&2 | |
exit 1 | |
fi | |
} | |
# Unzip .zip to /Applications. | |
unzip_zip() { | |
printf "%s\n" "Unpacking .zip file to /Applications..." | |
unzip /Applications/"$FILE" -d /Applications | |
if [ $? -ne 0 ]; then | |
printf "%s\n" "Error: Unzipping $FILE failed." >&2 | |
exit 1 | |
fi | |
} | |
# Run .pkg. | |
install_pkg() { | |
printf "%s\n" "Installing .pkg..." | |
installer -verbose -pkg /Applications/"${BIGFIX_COMPONENT[1]}" -target / | |
} | |
# Post-install cleanup (.zip and config files) | |
remove_trash() { | |
printf "%s\n" "Cleaning crew, coming through..." | |
rm -rv /Applications/"$FILE" | |
rm -rv /Applications/"${BIGFIX_COMPONENT[1]}" | |
rm -rv /Applications/"${BIGFIX_COMPONENT[2]}" | |
} | |
# Main. | |
main() { | |
root_check | |
get_serial_number | |
get_computer_name | |
set_computer_name | |
retrieve_zip | |
unzip_zip | |
install_pkg | |
remove_trash | |
} | |
main "$@" | |
retVal=$? | |
if [[ $retVal -ne 0 ]]; then | |
printf "%s\n" "Something went wrong, homie..." | |
else | |
printf "%s\n" "Done." | |
fi | |
exit $retVal |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment