mktemp on older OS's needs -t tmp #29

Closed
opened 2025-12-29 00:22:35 +01:00 by adam · 11 comments
Owner

Originally created by @morganwdavis on GitHub (Jan 7, 2016).

If all references of $(mktemp) were changed to $(mktemp -t tmp) this would work universally, as some older OS's (FreeBSD 5.5 for example) will fail if no prefix option is provided:

$ mktemp
usage: mktemp [-d] [-q] [-t prefix] [-u] template ...
       mktemp [-d] [-q] [-u] -t prefix

but adding -t tmp will generate the same desired result:

$ mktemp -t tmp
/tmp/tmp.y4A4wnen
Originally created by @morganwdavis on GitHub (Jan 7, 2016). If all references of $(mktemp) were changed to $(mktemp -t tmp) this would work universally, as some older OS's (FreeBSD 5.5 for example) will fail if no prefix option is provided: ``` $ mktemp usage: mktemp [-d] [-q] [-t prefix] [-u] template ... mktemp [-d] [-q] [-u] -t prefix ``` but adding -t tmp will generate the same desired result: ``` $ mktemp -t tmp /tmp/tmp.y4A4wnen ```
adam closed this issue 2025-12-29 00:22:35 +01:00
Author
Owner

@lukas2511 commented on GitHub (Jan 8, 2016):

Really? FreeBSD 5.5?... Isn't that completely unsupported since 2008?

I won't change this since the behaviour of -t param is different for BSD and GNU mktemp (on BSD it's a prefix, on GNU it's a template) and it would really over-complicate things to add a helper function just for supporting ancient systems.

I suggest you write a simple wrapper and put it into config.sh which gets sourced by letsencrypt.sh, that should allow you to redefine how the real mktemp is called.

@lukas2511 commented on GitHub (Jan 8, 2016): Really? FreeBSD 5.5?... Isn't that completely unsupported since 2008? I won't change this since the behaviour of `-t param` is different for BSD and GNU `mktemp` (on BSD it's a prefix, on GNU it's a template) and it would really over-complicate things to add a helper function just for supporting ancient systems. I suggest you write a simple wrapper and put it into `config.sh` which gets sourced by `letsencrypt.sh`, that should allow you to redefine how the real `mktemp` is called.
Author
Owner

@morganwdavis commented on GitHub (Jan 8, 2016):

We've got one old FreeBSD machine that just keeps on running, needed for some legacy hosting applications. I wasn't sure at what point mktemp changed to support a no-option default, so I figured I'd report the simple work-around. Given the divergence between BSD and GNU, the wrapper is a great idea. Since config.sh is sourced, it would allow for a lot of localized "workarounds". Thanks for the suggestion.

Also, thank you for your work on letsencrypt.sh itself. It's a relief to not have to load up the FreeBSD letsencrypt client package as it has about 3 dozen Python dependencies that I'd have no other need for. Your shell script plus curl is a far more elegant, simple, lightweight solution. Nicely done!

@morganwdavis commented on GitHub (Jan 8, 2016): We've got one old FreeBSD machine that just keeps on running, needed for some legacy hosting applications. I wasn't sure at what point mktemp changed to support a no-option default, so I figured I'd report the simple work-around. Given the divergence between BSD and GNU, the wrapper is a great idea. Since config.sh is sourced, it would allow for a lot of localized "workarounds". Thanks for the suggestion. Also, thank you for your work on letsencrypt.sh itself. It's a relief to not have to load up the FreeBSD letsencrypt client package as it has about 3 dozen Python dependencies that I'd have no other need for. Your shell script plus curl is a far more elegant, simple, lightweight solution. Nicely done!
Author
Owner

@lukas2511 commented on GitHub (Jan 8, 2016):

Looks like this was changed around Oct 2012 (in a0bfe4edc6), so probably was first released in FreeBSD 9.1 or 9.2.

I think most people are using either 9.1+ or have already updated to FreeBSD 10, but if more people report this problem I may implement a workaround.

@lukas2511 commented on GitHub (Jan 8, 2016): Looks like this was changed around Oct 2012 (in https://github.com/freebsd/freebsd/commit/a0bfe4edc64ac8e7cca69aaf01caad11bba39724), so probably was first released in FreeBSD 9.1 or 9.2. I think most people are using either 9.1+ or have already updated to FreeBSD 10, but if more people report this problem I may implement a workaround.
Author
Owner

@lukas2511 commented on GitHub (Jan 9, 2016):

I now replaced all mktemp calls with mktemp -t XXXXXX.

This results in BSD tmpfiles to have a "XXXXXX" prefix, and GNU tmpfiles to have a random name with 6 characters.
A bit weird but whatever, it shouldn't cause any problems.

@lukas2511 commented on GitHub (Jan 9, 2016): I now replaced all mktemp calls with `mktemp -t XXXXXX`. This results in BSD tmpfiles to have a "XXXXXX" prefix, and GNU tmpfiles to have a random name with 6 characters. A bit weird but whatever, it shouldn't cause any problems.
Author
Owner

@morganwdavis commented on GitHub (Jan 9, 2016):

Works great! Thank you, Lukas!

@morganwdavis commented on GitHub (Jan 9, 2016): Works great! Thank you, Lukas!
Author
Owner

@Rycochet commented on GitHub (Apr 22, 2016):

...and sadly this fails on QNAP -

mktemp: invalid option -- t
@Rycochet commented on GitHub (Apr 22, 2016): ...and sadly this fails on QNAP - ``` mktemp: invalid option -- t ```
Author
Owner

@morganwdavis commented on GitHub (Apr 22, 2016):

Lukas, if you want to revert the -t option so QNAP works, I'm fine with that. We retired our old FreeBSD machine so this is no longer a concern. Your idea of the wrapper as a workaround is probably best for any legacy cases that arise.

@morganwdavis commented on GitHub (Apr 22, 2016): Lukas, if you want to revert the -t option so QNAP works, I'm fine with that. We retired our old FreeBSD machine so this is no longer a concern. Your idea of the wrapper as a workaround is probably best for any legacy cases that arise.
Author
Owner

@lukas2511 commented on GitHub (Apr 22, 2016):

@morganwdavis nope, this option will stay, qnap users will have to look for workarounds. sorry @Rycochet.

@lukas2511 commented on GitHub (Apr 22, 2016): @morganwdavis nope, this option will stay, qnap users will have to look for workarounds. sorry @Rycochet.
Author
Owner

@Rycochet commented on GitHub (Apr 22, 2016):

I've had a quick look, and for some reason mktemp doesn't want to work properly on there anyway - so don't revert - this needs looking into more as something else seems funny - not a linux guy here, but I can try things out - mktemp output on QNAP -

[/share/MD0_DATA/Projects/letsencrypt] # mktemp -d
BusyBox v1.01 (2016.01.30-05:36+0000) multi-call binary

Usage: mktemp [-dq] TEMPLATE

Creates a temporary file with its name based on TEMPLATE.
TEMPLATE is any name with six `Xs' (i.e., /tmp/temp.XXXXXX).

Options:
        -d              Make a directory instead of a file
        -q              Fail silently if an error occurs

@Rycochet commented on GitHub (Apr 22, 2016): I've had a quick look, and for some reason mktemp doesn't want to work properly on there anyway - so don't revert - this needs looking into more as something else seems funny - not a linux guy here, but I can try things out - mktemp output on QNAP - ``` [/share/MD0_DATA/Projects/letsencrypt] # mktemp -d BusyBox v1.01 (2016.01.30-05:36+0000) multi-call binary Usage: mktemp [-dq] TEMPLATE Creates a temporary file with its name based on TEMPLATE. TEMPLATE is any name with six `Xs' (i.e., /tmp/temp.XXXXXX). Options: -d Make a directory instead of a file -q Fail silently if an error occurs ```
Author
Owner

@bittorf commented on GitHub (Apr 23, 2016):

@lukas2511 please note, that '-t' is deprecated, see http://www.gnu.org/software/autogen/mktemp.html - dont use it!

@bittorf commented on GitHub (Apr 23, 2016): @lukas2511 please note, that '-t' is deprecated, see http://www.gnu.org/software/autogen/mktemp.html - dont use it!
Author
Owner

@lukas2511 commented on GitHub (Apr 23, 2016):

@bittorf i f****ng hate things like this. changed in f096c62. this will probably break this script for a few people, but whatever.

edit: thanks anyway.

@lukas2511 commented on GitHub (Apr 23, 2016): @bittorf i f****ng hate things like this. changed in f096c62. this will probably break this script for a few people, but whatever. edit: thanks anyway.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/dehydrated#29