#!/bin/bash # Creates a ramdisk and start Xcode with the DerivedData stored in ramdisk. Also deletes the ramdisk and reset Xcode prefs. # xc_ramdisk.sh # - creates a ramdisk, set Xcode DerivedData to this disk and start Xcode. # - umount a ramdisk, set Xcode DerivedData to default # Stephan Burlot, Coriolis Technologies, http://www.coriolis.ch # # based on Alex Shevchenko xcode_ramdisk.sh script (https://gist.github.com/skeeet/2367298) # based on Diego Freniche xc-launch.sh script (https://github.com/dfreniche/xc-launch) # mount point for the ramdisk volume ramdisk='/Volumes/ramdisk' # size of created disk in M-bytes disk_size=1024 # compute the size of the disk in 512-byte sectors rdsize=$(($disk_size*1024*1024/512)) StartService () { cmd="\$3 == \"$ramdisk\" {print \$3}" if [[ $(mount | awk "$cmd") != "" ]]; then echo "$ramdisk is already mounted, erasing ramdisk." rm -rf /Volumes/ramdisk else diskutil erasevolume HFS+ "ramdisk" `hdiutil attach -nomount ram://$rdsize` fi # set the Derived Data folder in Xcode prefs /usr/bin/defaults write com.apple.dt.Xcode IDECustomDerivedDataLocation "$ramdisk" open -a Xcode } StopService () { if [ -z "$(pgrep Xcode)" ]; then cmd="\$3 == \"$ramdisk\" {print \$3}" if [[ $(mount | awk "$cmd") != "" ]]; then # reset the Derived Data folder in Xcode prefs to default /usr/bin/defaults delete com.apple.dt.Xcode IDECustomDerivedDataLocation # eject disk hdiutil detach $ramdisk else echo "$ramdisk is not mounted" fi else echo "Xcode is running, nothing done." fi } RestartService () { ConsoleMessage "Restarting, nothing will be done here..." } # Test for arguments. if [ -z $1 ]; then echo "Usage: $0 [start|stop] " exit 1 fi # Source the common setup functions for startup scripts test -r /etc/rc.common || exit 1 . /etc/rc.common RunService "$1"