diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2016-08-03 11:36:30 +1200 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2016-08-03 11:37:53 +1200 |
commit | 1161cf8eb9f21ffcc3be539f1ec3b7e4a7d3e395 (patch) | |
tree | a1828b4686656dcc9c56e8905c60e77287297a05 | |
parent | Add issue regarding mktemp(1) usage (diff) | |
download | dotfiles-1161cf8eb9f21ffcc3be539f1ec3b7e4a7d3e395.tar.gz dotfiles-1161cf8eb9f21ffcc3be539f1ec3b7e4a7d3e395.zip |
Add mktd(1)
-rwxr-xr-x | bin/mktd | 5 | ||||
-rw-r--r-- | man/man1/mktd.1 | 34 |
2 files changed, 39 insertions, 0 deletions
diff --git a/bin/mktd b/bin/mktd new file mode 100755 index 00000000..657ec31f --- /dev/null +++ b/bin/mktd @@ -0,0 +1,5 @@ +#!/bin/sh +# Try to make a random temp directory +dn=${TMPDIR:-/tmp}/${1:-mktd}.$$.$(rndi 1 2147483648) +mkdir -m 700 -- "$dn" || exit 1 +printf '%s\n' "$dn" diff --git a/man/man1/mktd.1 b/man/man1/mktd.1 new file mode 100644 index 00000000..bb88a12e --- /dev/null +++ b/man/man1/mktd.1 @@ -0,0 +1,34 @@ +.TH MKTD 1 "August 2016" "Manual page for mktd" +.SH NAME +.B mktd +\- try hard to safely create a temporary directory in a POSIX-compliant way +.SH SYNOPSIS +.B mktd +.br +.B mktd +foo +.SH DESCRIPTION +.B mktd +creates a temporary directory with a strong attempt at a random name in $TMPDIR +(defaults to /tmp), with a restrictive umask for the user running the script, +into which it should be safe to place temporary files. +.P +The author makes no guarantees about security, but this should be a lot safer +than just using a /tmp/$$ file. +.P +You could use it in a script like this: +.P + td= + cleanup() { + rm -fr -- "$td" + } + for sig in EXIT HUP INT TERM ; do + trap cleanup "$sig" + done + td=$(mktd) || exit +.SH SEE ALSO +rndi(1) +.br +<http://mywiki.wooledge.org/BashFAQ/062> +.SH AUTHOR +Tom Ryder <tom@sanctum.geek.nz> |