Debian Codegraph @

etc/ci/mktemp_d.sh

raw symbols SCIP
1 #!/bin/sh
2
3 # Written mostly by GPT-4 https://web.archive.org/web/20231111233735/https://chat.openai.com/share/8098af96-4a10-4083-bf47-7f9e8cc333ed
4
5 # Check if $RANDOM is available
6 if [ -z "$RANDOM" ]; then
7 random="$$"
8 else
9 random="$RANDOM"
10 fi
11
12 # Try to use mktemp if available
13 if command -v mktemp > /dev/null; then
14 # MacOS and some BSDs require a template for mktemp
15 if [ "$(uname)" = "Darwin" ] || [ "$(uname)" = "FreeBSD" ]; then
16 temp_dir="$(mktemp -d "${TMPDIR:-/tmp}/tmp.XXXXXX")"
17 else
18 temp_dir="$(mktemp -d 2>/dev/null || mktemp -d -t 'tmp')"
19 fi
20 else
21 # Fallback: Create a directory with a random name in TMPDIR or /tmp
22 dir="${TMPDIR:-/tmp}/tmp.$random"
23 mkdir -p "$dir"
24 temp_dir="$dir"
25 fi
26
27 # Output the path of the created directory
28 printf "%s\n" "$temp_dir"