Skip to content

Instantly share code, notes, and snippets.

@toonetown
Last active August 10, 2021 16:24
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 toonetown/b75e5c37b2ebf891da16ddc5d812f983 to your computer and use it in GitHub Desktop.
Save toonetown/b75e5c37b2ebf891da16ddc5d812f983 to your computer and use it in GitHub Desktop.
Copies a file if it is different than the target
#!/bin/bash
# Copies a file if and only if it is different
if [ "$(diff -q "${1}" "${2}" 2>&1 | wc -l)" -gt 0 ]; then cp "${1}" "${2}"; fi
@toonetown
Copy link
Author

toonetown commented Aug 23, 2019

This can be used in conjunction with a LaunchAgent to copy/replace files when they have changed. I implemented this to work around an issue as described at https://forum.parallels.com/threads/sip-settings-not-preserved-anymore.347821/ where NVRAM.dat was getting removed.

An example LaunchAgent plist file would be:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
  <key>Label</key>
  <string>com.toonetown.nvram-watcher.macOS</string>
  <key>OnDemand</key>
  <true/>
  <key>Program</key>
  <string>/usr/local/bin/copy-diff</string>
  <key>ProgramArguments</key>
  <array>
    <string>copy-diff</string>
    <string>/path/to/macOS.pvm/NVRAM.dat.working</string>
    <string>/path/to/macOS.pvm/NVRAM.dat</string>
  </array>
  <key>WatchPaths</key>
  <array>
    <string>/path/to/macOS.pvm/NVRAM.dat</string>
  </array>
</dict>
</plist>

@toonetown
Copy link
Author

As of Parallels 17, it appears that this bug has been fixed!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment