News for hackers. Stuff that matters.
Re:How to write idempotent Bash scripts by cjvirtucio on Sunday July 07, 2019 @11:29AM (#20375560)
I have not been doing DevOps for very long, but a useful trick I've found is to create a staging directory, perform my work there, diff the result with the existing state, and copy if a difference exists. I've found it very easy to clean up to a sanitized state in this way; the existing state is safe, since all I have to do is just destroy my work.
Re:How to write idempotent Bash scripts by prepend on Sunday July 07, 2019 @11:51AM (#20375672)
If possible, I’ll try to make a symlink just point to the staging dir after tests complete. This isn’t always possible, but makes it easy to roll back to the old prod folder if anything goes awry.
Re:How to write idempotent Bash scripts by fwip on Sunday July 07, 2019 @01:05PM (#20376153)
You might find rsync cleaner to use than a diff/cp loop.

Another approach is to create a unique directory (named by hash or date) with the results, and once it's good, symlink the real directory to it. (Full disclosure, I stole this approach from nextflow.io, a great workflow system aimed at bioinformatics).

    ln -sfn "build-cache/2019-07-07-21:23:04" "build"
Re:How to write idempotent Bash scripts by pjscott on Sunday July 07, 2019 @09:44PM (#20379300)
Apple's new-ish APFS filesystem includes something for this pattern: the renamex_np(2) system call with the RENAME_SWAP flag. This atomically swaps two files, and can be used to atomically swap your staging directory with the existing directory. I'm not sure if there's command line support yet, though.
Re:How to write idempotent Bash scripts by cyphar on Sunday July 07, 2019 @09:48PM (#20379321)
Linux has something similar with RENAME_EXCHANGE. Unfortunately MV(1) doesn't appear to have support for any of the renameat2(2) flags.
Re:How to write idempotent Bash scripts by nerdponx on Sunday July 07, 2019 @12:47PM (#20376025)
What do you use to compute the diff? Just the diff command itself on individual files?
Re:How to write idempotent Bash scripts by dredmorbius on Sunday July 07, 2019 @03:48PM (#20377342)
diff -R

You can use numerous tools to compare/manage branches; md5sum / shasum (md5 is usually useful, though not entirely safe), diff and kin, vimdiff, rsync, fdupes, jdupes, git, hg.

Re:How to write idempotent Bash scripts by haddr on Sunday July 07, 2019 @04:18PM (#20377547)
I went the „git” way once and I found it really cool! With all the goodies you get for free from git, like applying patches, checking differences, resetting to previous state etc.
Re:How to write idempotent Bash scripts by dhimes on Sunday July 07, 2019 @09:17PM (#20379193)
Same, but with mercurial.
Re:How to write idempotent Bash scripts by cryptofistMonk on Sunday July 07, 2019 @01:05PM (#20376161)
Could use something like rsync to automatically check for a difference and copy