Skip to content

Instantly share code, notes, and snippets.

@abernix
Last active November 21, 2016 11:15
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 abernix/9223a4885085092434427a0e7f60775d to your computer and use it in GitHub Desktop.
Save abernix/9223a4885085092434427a0e7f60775d to your computer and use it in GitHub Desktop.
#!/bin/sh
run_it () {
# Pretty message function
NiceMsg () {
printf "\033[0;32m$1\033[0m\n"
}
# Version compare function
cver () {
echo $1 | perl -n \
-e '@ver = /^([0-9]+)\.([0-9]+)(?:\.([0-9]+))?(?:\.([0-9]+))?/;' \
-e 'printf "%04s%04s%04s%04s", @ver;'
}
if [ "$(uname -s)" != "Darwin" ] || [ $(cver "$(sw_vers -productVersion)") -le $(cver "10.10") ]; then
NiceMsg "=> Not intended to run on this platform/version! Exiting."
exit 1
fi
NiceMsg "Welcome! This script will (hopefully) fix your ulimit settings on your Mac..."
echo
NiceMsg "*** If you didn't intend to run this, press Ctrl-C within 10 seconds! ***"
sleep 10
if [ -f /etc/launchd.conf ]; then
NiceMsg "=> You have an /etc/launchd.conf file, which should be removed."
fi
# Remove lines that shouldn't be in sysctl.conf
if [ -f /etc/sysctl.conf ]; then
NiceMsg "=> Removing kern.maxfiles* settings which should not be in /etc/sysctl.conf anymore"
perl -ni -e 'print unless /^kern.maxfiles/' /etc/sysctl.conf
echo " => Done!"
fi
NiceMsg "=> Writing new LaunchDaemon property list..."
cat <<EOM > /Library/LaunchDaemons/limit.maxfiles.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>limit.maxfiles</string>
<key>ProgramArguments</key>
<array>
<string>launchctl</string>
<string>limit</string>
<string>maxfiles</string>
<string>524288</string>
<string>524288</string>
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
EOM
NiceMsg "=> Activating new settings immediately..."
launchctl load -w /Library/LaunchDaemons/limit.maxfiles.plist
NiceMsg "Done! Hopefully you can enjoy your expensive hardware to its full potential now!"
NiceMsg "====> Please close this shell and open a new shell to use the new settings! <===="
trap - EXIT
set +e
}
run_it
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment