github.com/dahs81/otto@v0.2.1-0.20160126165905-6400716cf085/images/scripts/macosx/minimize.sh (about)

     1  #!/bin/sh -eux
     2  
     3  # Remove any sleepimage--a file the same size as the RAM footprint
     4  rm -f /private/var/vm/sleepimage;
     5  
     6  # Stop the pager process and drop swap files. These will be re-created on boot
     7  launchctl unload /System/Library/LaunchDaemons/com.apple.dynamic_pager.plist;
     8  sleep 5;
     9  rm -rf /private/var/vm/swap*;
    10  
    11  dd if=/dev/zero of=/EMPTY bs=1000000 || echo "dd exit code $? is suppressed";
    12  rm -f /EMPTY;
    13  # Block until the empty file has been removed, otherwise, Packer
    14  # will try to kill the box while the disk is still full and that's bad
    15  sync;
    16  
    17  
    18  case "$PACKER_BUILDER_TYPE" in
    19  
    20  vmware-iso|vmware-vmx)
    21      sudo /Library/Application\ Support/VMware\ Tools/vmware-tools-cli disk shrink /;
    22      ;;
    23  
    24  esac
    25  
    26  # re-enable swap
    27  launchctl load -wF /System/Library/LaunchDaemons/com.apple.dynamic_pager.plist;