#!/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 < /Library/LaunchDaemons/limit.maxfiles.plist Label limit.maxfiles ProgramArguments launchctl limit maxfiles 524288 524288 RunAtLoad 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