Skip to content

Instantly share code, notes, and snippets.

@marshki
Last active April 18, 2024 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marshki/d52c03874caea02a2756c7486ee92bf5 to your computer and use it in GitHub Desktop.
Save marshki/d52c03874caea02a2756c7486ee92bf5 to your computer and use it in GitHub Desktop.
BigFix auto installer for macOS, written in Bash.
#!/usr/bin/env bash
set -e
# Set macOS 'Computer Name' to serial number.
# Download, unzip, install, and cleanup BigFix in macOS.
#
# Author: M. Krinitz <mjk235 [at] nyu [dot] edu>
# Date: 2023-11-08
# License: MIT
#########
# Globals
#########
# URL.
URL=""
# Zip file.
FILE="fixer.zip"
# Components of .zip package.
BIGFIX_COMPONENT=(
ActionSite.afxm
BESAgent-11.0.0.175-BigFix_MacOS11.0.pkg
bigfix_install.sh
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" >&2
exit 1
fi
}
# Get serial number.
get_serial_number() {
serialnum=$(system_profiler SPHardwareDataType | awk '/Serial/ {print $4}')
}
# Get computer name.
get_computer_name() {
computername=$(scutil --get ComputerName)
}
# Set computer name to serial number.
set_computer_name() {
if [ "$serialnum" != "$computername" ]; then
printf "%s\n" "Setting 'Computer Name'..."
scutil --set ComputerName "$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"
}
# Unzip .zip to /Applications.
unzip_zip() {
printf "%s\n" "Unpacking .zip file to /Applications..."
unzip /Applications/"$FILE" -d /Applications
}
# 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[0]}"
rm -rv /Applications/"${BIGFIX_COMPONENT[2]}"
rm -rv /Applications/"${BIGFIX_COMPONENT[3]}"
}
#############
# Exit status
#############
# Check exit status.
exit_status() {
if [[ $retVal -ne 0 ]]; then
printf "%s\n" "Something went wrong, homie..."
else
printf "%s\n" "Done."
exit 0
fi
}
# Main.
main() {
root_check
get_serial_number
get_computer_name
set_computer_name
retrieve_zip
unzip_zip
install_pkg
remove_trash
}
main "$@"
retVal=$?
exit_status
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment