Skip to content

Instantly share code, notes, and snippets.

@calum-github
Last active May 24, 2024 01:18
Show Gist options
  • Select an option

  • Save calum-github/8ed847153bf1e28f9b11 to your computer and use it in GitHub Desktop.

Select an option

Save calum-github/8ed847153bf1e28f9b11 to your computer and use it in GitHub Desktop.
AutoCasperNBI Post Processor Script
#!/bin/bash
######################################################################################
# #
# Author: Calum Hunter #
# Date: 12/12/2014 #
# Version: 0.3 #
# Purpose: Script to clean up an AutoCasperNBI for use with DEC BootStrapper. #
# #
# #
######################################################################################
# Everyones favourite buddy
plistbuddy="/usr/libexec/PlistBuddy"
main(){
root_check
show_description
get_program_paths
check_for_ds
fix_NBImageInfo
enforce_SMB1
remove_casper_imaging_startup
kill_finder
remove_apps
remove_widgets
remove_system_library_files
remove_menu_extras
remove_dodgy_frameworks
remove_unneccesary_Agents_Daemons
# install_additional_packages
convert_to_sparse
}
root_check(){
if [ "$(id -u)" != "0" ]; then
echo "This script must be run as root" 1>&2
exit 1
fi
}
remove_unneccesary_Agents_Daemons(){
echo "*** Removing unneeded LaunchAgents"
rm -rf "${nbivol}/System/Library/LaunchAgents/com.apple.AddressBook.abd.plist"
rm -rf "${nbivol}/System/Library/LaunchAgents/com.apple.AddressBook.AssistantService.plist"
rm -rf "${nbivol}/System/Library/LaunchAgents/com.apple.AddressBook.SourceSync.plist"
rm -rf "${nbivol}/System/Library/LaunchAgents/com.apple.AirPlayUIAgent.plist"
rm -rf "${nbivol}/System/Library/LaunchAgents/com.apple.AirPortBaseStationAgent.plist"
rm -rf "${nbivol}/System/Library/LaunchAgents/com.apple.appstoreupdateagent.plist"
rm -rf "${nbivol}/System/Library/LaunchAgents/com.apple.cloudfamilyrestrictionsd-mac.plist"
rm -rf "${nbivol}/System/Library/LaunchAgents/com.apple.DictationIM.plist"
rm -rf "${nbivol}/System/Library/LaunchAgents/com.apple.gamed.plist"
rm -rf "${nbivol}/System/Library/LaunchAgents/com.apple.helpd.plist"
rm -rf "${nbivol}/System/Library/LaunchAgents/com.apple.icloud.fmfd.plist"
rm -rf "${nbivol}/System/Library/LaunchAgents/com.apple.iCloudUserNotifications.plist"
rm -rf "${nbivol}/System/Library/LaunchAgents/com.apple.IMLoggingAgent.plist"
rm -rf "${nbivol}/System/Library/LaunchAgents/com.apple.java.InstallOnDemand.plist"
rm -rf "${nbivol}/System/Library/LaunchAgents/com.apple.java.updateSharing.plist"
rm -rf "${nbivol}/System/Library/LaunchAgents/com.apple.ManagedClientAgent.agent.plist"
rm -rf "${nbivol}/System/Library/LaunchAgents/com.apple.ManagedClientAgent.enrollagent.plist"
rm -rf "${nbivol}/System/Library/LaunchAgents/com.apple.Maps.pushdaemon.plist"
rm -rf "${nbivol}/System/Library/LaunchAgents/com.apple.mdmclient.agent.plist"
rm -rf "${nbivol}/System/Library/LaunchAgents/com.apple.mdmclient.cloudconfig.agent.plist"
rm -rf "${nbivol}/System/Library/LaunchAgents/com.apple.softwareupdate_notify_agent.plist"
rm -rf "${nbivol}/System/Library/LaunchAgents/com.apple.TMHelperAgent.plist"
rm -rf "${nbivol}/System/Library/LaunchAgents/com.apple.TMHelperAgent.SetupOffer.plist"
rm -rf "${nbivol}/System/Library/LaunchAgents/com.apple.VoiceOver.plist"
rm -rf "${nbivol}/System/Library/LaunchAgents/com.apple.bluetoothUIServer.plist"
rm -rf "${nbivol}/System/Library/LaunchAgents/com.apple.CalendarAgent.plist"
rm -rf "${nbivol}/System/Library/LaunchAgents/com.apple.CalendarAgentLauncher.plist"
rm -rf "${nbivol}/System/Library/LaunchAgents/com.apple.Finder.plist"
rm -rf "${nbivol}/System/Library/LaunchAgents/com.apple.findmymacmessenger.plist"
rm -rf "${nbivol}/System/Library/LaunchAgents/com.apple.icbaccountsd.plist"
rm -rf "${nbivol}/System/Library/LaunchAgents/com.apple.icloud.AOSNotificationAgent.plist"
rm -rf "${nbivol}/System/Library/LaunchAgents/com.apple.icloud.AOSNotificationLoginAgent.plist"
rm -rf "${nbivol}/System/Library/LaunchAgents/com.apple.ManagedClient.agent.plist"
rm -rf "${nbivol}/System/Library/LaunchAgents/com.apple.ManagedClient.enrollagent.plist"
rm -rf "${nbivol}/System/Library/LaunchAgents/com.apple.PCIESlotCheck.plist"
rm -rf "${nbivol}/System/Library/LaunchAgents/com.apple.safaridavclient.plist"
rm -rf "${nbivol}/System/Library/LaunchAgents/com.apple.SafariNotificationAgent.plist"
rm -rf "${nbivol}/System/Library/LaunchAgents/com.apple.soagent.plist"
rm -rf "${nbivol}/System/Library/LaunchAgents/com.apple.speech.feedbackservicesserver.plist"
rm -rf "${nbivol}/System/Library/LaunchAgents/com.apple.speech.recognitionserver.plist"
rm -rf "${nbivol}/System/Library/LaunchAgents/com.apple.speech.speechdatainstallerd.plist"
rm -rf "${nbivol}/System/Library/LaunchAgents/com.apple.speech.speechsynthesisd.plist"
rm -rf "${nbivol}/System/Library/LaunchAgents/com.apple.speech.synthesisserver.plist"
rm -rf "${nbivol}/System/Library/LaunchAgents/com.apple.ubd.plist"
rm -rf "${nbivol}/System/Library/LaunchAgents/com.apple.cloudd.plist"
rm -rf "${nbivol}/System/Library/LaunchAgents/com.apple.cloudpaird.plist"
rm -rf "${nbivol}/System/Library/LaunchAgents/com.apple.fontd.useragent.plist"
rm -rf "${nbivol}/System/Library/LaunchAgents/ccom.apple.FontRegistryUIAgent.plist"
rm -rf "${nbivol}/System/Library/LaunchAgents/com.apple.FontValidator.plist"
rm -rf "${nbivol}/System/Library/LaunchAgents/com.apple.FontValidatorConduit.plist"
rm -rf "${nbivol}/System/Library/LaunchAgents/com.apple.FontWorker.plist"
rm -rf "${nbivol}/System/Library/LaunchAgents/com.apple.notificationcenterui.plist"
echo "*** Removing unneeded LaunchDaemons"
rm -rf "${nbivol}/System/Library/LaunchDaemons/com.apple.ManagedClient.startup.plist"
rm -rf "${nbivol}/System/Library/LaunchDaemons/com.apple.GameController.gamecontrollerd.plist"
rm -rf "${nbivol}/System/Library/LaunchDaemons/com.apple.AirPlayXPCHelper.plist"
rm -rf "${nbivol}/System/Library/LaunchDaemons/com.apple.backupd-auto.plist"
rm -rf "${nbivol}/System/Library/LaunchDaemons/com.apple.backupd.plist"
rm -rf "${nbivol}/System/Library/LaunchDaemons/com.apple.bluetoothaudiod.plist"
rm -rf "${nbivol}/System/Library/LaunchDaemons/com.apple.cmio.AppleCameraAssistant.plist"
rm -rf "${nbivol}/System/Library/LaunchDaemons/com.apple.cmio.AVCAssistant.plist"
rm -rf "${nbivol}/System/Library/LaunchDaemons/com.apple.cmio.IIDCVideoAssistant.plist"
rm -rf "${nbivol}/System/Library/LaunchDaemons/com.apple.cmio.VDCAssistant.plist"
rm -rf "${nbivol}/System/Library/LaunchDaemons/com.apple.dvdplayback.setregion.plist"
rm -rf "${nbivol}/System/Library/LaunchDaemons/com.apple.findmymac.plist"
rm -rf "${nbivol}/System/Library/LaunchDaemons/com.apple.findmymacmessenger.plist"
rm -rf "${nbivol}/System/Library/LaunchDaemons/com.apple.iCloudStats.plist"
rm -rf "${nbivol}/System/Library/LaunchDaemons/com.apple.ManagedClient.cloudconfigurationd.plist"
rm -rf "${nbivol}/System/Library/LaunchDaemons/com.apple.ManagedClient.enroll.plist"
rm -rf "${nbivol}/System/Library/LaunchDaemons/com.apple.ManagedClient.plist"
rm -rf "${nbivol}/System/Library/LaunchDaemons/com.apple.ManagedClient.startup"
rm -rf "${nbivol}/System/Library/LaunchDaemons/com.apple.mbicloudsetupd.plist"
rm -rf "${nbivol}/System/Library/LaunchDaemons/com.apple.mdmclient.daemon.plist"
rm -rf "${nbivol}/System/Library/LaunchDaemons/com.apple.PCIELaneConfigTool.plist"
rm -rf "${nbivol}/System/Library/LaunchDaemons/com.apple.periodic-daily.plist"
rm -rf "${nbivol}/System/Library/LaunchDaemons/com.apple.periodic-monthly.plist"
rm -rf "${nbivol}/System/Library/LaunchDaemons/com.apple.periodic-weekly.plist"
rm -rf "${nbivol}/System/Library/LaunchDaemons/com.apple.postgres.plist"
rm -rf "${nbivol}/System/Library/LaunchDaemons/com.apple.printtool.daemon"
rm -rf "${nbivol}/System/Library/LaunchDaemons/com.apple.racoon.plist"
rm -rf "${nbivol}/System/Library/LaunchDaemons/com.apple.remotepairtool.plist"
rm -rf "${nbivol}/System/Library/LaunchDaemons/com.apple.systemstats.analysis.plist"
rm -rf "${nbivol}/System/Library/LaunchDaemons/com.apple.systemstats.daily.plist"
rm -rf "${nbivol}/System/Library/LaunchDaemons/com.apple.systemstatsd.plist"
rm -rf "${nbivol}/System/Library/LaunchDaemons/org.cups.cups-lpd.plist"
rm -rf "${nbivol}/System/Library/LaunchDaemons/org.cups.cupsd.plist"
rm -rf "${nbivol}/System/Library/LaunchDaemons/org.postfix.master.plist"
rm -rf "${nbivol}/System/Library/LaunchDaemons/telnet.plist"
rm -rf "${nbivol}/System/Library/LaunchDaemons/com.apple.fontd.plist"
rm -rf "${nbivol}/System/Library/LaunchDaemons/com.apple.fontmover.plist"
rm -rf "${nbivol}/System/Library/LaunchDaemons/com.apple.FontWorker.plist"
rm -rf "${nbivol}/System/Library/LaunchDaemons/com.apple.icloud.findmydeviced.plist"
rm -rf "${nbivol}/System/Library/LaunchDaemons/com.apple.ocspd.plist"
}
remove_dodgy_frameworks(){
echo "*** Removing buggy frameworks"
rm -rf "${nbivol}/System/Library/PrivateFrameworks/ShareKit.framework"
echo "*** Removing ShareKit (Note: Removing this prevents Console.app from launching)"
echo "*** Removing Console.app - as its not going to work anyway"
rm -rf "${nbivol}/Applications/Utilities/Console.app"
}
show_description(){
echo "****************************************************************"
echo "* Post Processor for AutoCasperNBI to create NBI for DEC *"
echo "* *"
echo "* This script will add the extra files and applications *"
echo "* to a NBI for use in the DEC environment *"
echo "****************************************************************"
}
enforce_SMB1(){
echo "*** Enforcing SMB1 connections"
echo "[default]" >> "${nbivol}/etc/nsmb.conf"
echo "smb_neg=smb1_only" >> "${nbivol}/etc/nsmb.conf"
}
get_program_paths(){
echo ""
echo "* We need some paths first. Please provide the path"
echo "* to the AutoCasperNBI.nbi folder. "
read nb_folder
echo ""
echo "Your AutoCasperNBI.nbi path is $nb_folder"
echo ""
echo "Assuming your NetBoot dmg is named NetBoot.reduced.dmg"
echo "Is this correct? (y/n)"
read nb_dmg_name_correct
if [ $nb_dmg_name_correct = "n" ];
then
echo "Please give me the name of your netboot disk image"
read nb_dmg_name
else
nb_dmg_name="NetBoot.reduced.dmg"
fi
echo "Now mounting your DMG"
echo ""
nbivol=`hdiutil attach ${nb_folder}/${nb_dmg_name} | awk '/Volumes/ {print $3}'`
echo "DMG mounted at $nbivol"
nbimageinfo="${nb_folder}/NBImageInfo.plist"
echo ""
echo "Path to NBI Image Info is $nbimageinfo"
echo ""
# echo "Please provide the path to the folder containing additional PKG's that need to be installed"
# read pkg_location
# echo ""
# echo "Found the following Packages:"
# pkgs_to_install=`ls $pkg_location`
# echo $pkgs_to_install
# echo ""
echo "Ready to go. "
echo "Running Cleanup...."
echo ""
}
install_additional_packages(){
echo "*** Installing additional packages from $pkg_location"
for package in $pkgs_to_install
do
installer -dumplog -verbose -pkg "$pkg_location/$package" -target $nbivol
done
}
convert_to_sparse(){
cd $nb_folder
echo "*** Unmounting $nbivol"
hdiutil detach $nbivol
sleep 3
echo "*** Converting $nb_dmg_name to sparse image"
hdiutil convert -format UDSP $nb_dmg_name -o NetBoot.reduced.sparseimage
echo "*** Moving old DMG"
mv $nb_dmg_name ${nb_dmg_name}.old
echo "*** Creating symlink ***"
ln -s NetBoot.reduced.sparseimage NetBoot.reduced.dmg
echo "*** Removing ${nb_dmg_name}.old ***"
rm ${nb_dmg_name}.old
echo "*** Done ***"
}
fix_NBImageInfo(){
echo "*** Removing disabled systems from $nbimageinfo"
$plistbuddy -c "delete :DisabledSystemIdentifiers" $nbimageinfo
$plistbuddy -c "add :DisabledSystemIdentifiers array" $nbimageinfo
echo "*** Adding list of unsupported MacBookPro systems to $nbimageinfo"
$plistbuddy -c "add :DisabledSystemIdentifiers: string MacBookPro3,1" $nbimageinfo
$plistbuddy -c "add :DisabledSystemIdentifiers: string MacBookPro2,1" $nbimageinfo
$plistbuddy -c "add :DisabledSystemIdentifiers: string MacBookPro1,2" $nbimageinfo
$plistbuddy -c "add :DisabledSystemIdentifiers: string MacBookPro1,1" $nbimageinfo
echo "*** Adding list of unsupported MacBook systems to $nbimageinfo"
$plistbuddy -c "add :DisabledSystemIdentifiers: string MacBook5,1" $nbimageinfo
$plistbuddy -c "add :DisabledSystemIdentifiers: string MacBook4,1" $nbimageinfo
$plistbuddy -c "add :DisabledSystemIdentifiers: string MacBook3,1" $nbimageinfo
$plistbuddy -c "add :DisabledSystemIdentifiers: string MacBook2,1" $nbimageinfo
$plistbuddy -c "add :DisabledSystemIdentifiers: string MacBook1,1" $nbimageinfo
echo "*** Adding list of unsupported MacBookAir systems to $nbimageinfo"
$plistbuddy -c "add :DisabledSystemIdentifiers: string MacBookAir1,1" $nbimageinfo
echo "*** Adding list of unsupported Macmini systems to $nbimageinfo"
$plistbuddy -c "add :DisabledSystemIdentifiers: string Macmini3,1" $nbimageinfo
$plistbuddy -c "add :DisabledSystemIdentifiers: string Macmini2,1" $nbimageinfo
$plistbuddy -c "add :DisabledSystemIdentifiers: string Macmini1,1" $nbimageinfo
echo "*** Adding list of unsupported iMac systems to $nbimageinfo"
$plistbuddy -c "add :DisabledSystemIdentifiers: string iMac7,1" $nbimageinfo
$plistbuddy -c "add :DisabledSystemIdentifiers: string iMac6,1" $nbimageinfo
$plistbuddy -c "add :DisabledSystemIdentifiers: string iMac5,2" $nbimageinfo
$plistbuddy -c "add :DisabledSystemIdentifiers: string iMac5,1" $nbimageinfo
$plistbuddy -c "add :DisabledSystemIdentifiers: string iMac4,2" $nbimageinfo
$plistbuddy -c "add :DisabledSystemIdentifiers: string iMac4,1" $nbimageinfo
echo "*** Adding list of unsupported MacPro systems to $nbimageinfo"
$plistbuddy -c "add :DisabledSystemIdentifiers: string MacPro3,1" $nbimageinfo
$plistbuddy -c "add :DisabledSystemIdentifiers: string MacPro3,1" $nbimageinfo
$plistbuddy -c "add :DisabledSystemIdentifiers: string MacPro2,1" $nbimageinfo
$plistbuddy -c "add :DisabledSystemIdentifiers: string MacPro1,1" $nbimageinfo
echo "*** Adding list of unsupported Xserve systems to $nbimageinfo"
$plistbuddy -c "add :DisabledSystemIdentifiers: string Xserve3,1" $nbimageinfo
$plistbuddy -c "add :DisabledSystemIdentifiers: string Xserve2,1" $nbimageinfo
$plistbuddy -c "add :DisabledSystemIdentifiers: string Xserve1,1" $nbimageinfo
}
remove_menu_extras(){
echo "*** Removing Menu Extras"
rm -rf "${nbivol}/System/Library/CoreServices/Menu Extras/Bluetooth.menu"
rm -rf "${nbivol}/System/Library/CoreServices/Menu Extras/TimeMachine.menu"
}
remove_apps(){
echo "*** Removing undeeded extra apps"
rm -rf "${nbivol}/Applications/Casper\ Imaging.app"
rm -rf "${nbivol}/Applications/Launchpad.app"
rm -rf "${nbivol}/Applications/Utilities/Activity\ Monitor.app"
rm -rf "${nbivol}/Applications/Utilities/Grab.app"
}
remove_casper_imaging_startup(){
echo "*** Removing LaunchAgent for Casper Imaging startup"
rm $nbivol/Library/LaunchAgents/com.AutoCasperNBI.CasperImaging.plist
}
check_for_ds(){
if [ ! -d "${nbivol}/Applications/Utilities/DeployStudio Admin.app" ]; then
echo "*******************************************************************************************"
echo "* WARNING!!! *"
echo "* DeployStudio Server does not appear to be installed on the NBI! *"
echo "* *"
echo "* Please install the latest version of DeployStudio on the NBI! *"
echo "* Once your finished installing make sure to UNMOUNT the DMG and re-run this script *"
echo "*******************************************************************************************"
exit 0
fi
}
kill_finder(){
echo "*** Moving Finder to old.Finder.backup to prevent those pesky kids getting access to the file system "
mv $nbivol/System/Library/CoreServices/Finder.app $nbivol/System/Library/CoreServices/old.Finder.app
}
remove_system_library_files(){
echo "*** Removing unneeded files from system library"
rm -rf $nbivol/System/Library/CoreServices/Setup\ Assistant.app
rm -rf $nbivol/System/Library/CoreServices/Certificate\ Assistant.app
rm -rf $nbivol/System/Library/CoreServices/Network\ Setup\ Assistant.app
rm -rf $nbivol/System/Library/CoreServices/ManagedClient.app
rm -rf $nbivol/System/Library/CoreServices/Network\ Diagnostics.app
rm -rf $nbivol/System/Library/CoreServices/Install\ Command\ Line\ Developer\ Tools.app
rm -rf $nbivol/System/Library/CoreServices/AddPrinter.app
}
remove_widgets(){
echo "*** Removing Widgets and extras"
rm -rf $nbivol/Library/QuickLook
rm -rf $nbivol/Library/Widgets/*
rm -rf $nbivol/Library/Spotlight/*
rm -rf $nbivol/Library/Image\ Capture
rm -rf $nbivol/Library/Messages/*
}
# Run the functions defined inside the main function
main
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment