7738c6a67d
The fallback case of building in a brother directory moved from the last line of code to the first one becoming more explicit along the way. Support for slash-containing argument (being a tmpdir name template prefix) has been added.
32 lines
914 B
Bash
Executable File
32 lines
914 B
Bash
Executable File
#!/bin/sh
|
|
# analyze free space, preferring tmpfs over really many gigaz
|
|
|
|
# hope there aren't spaces in RM's $HOME are they?
|
|
DIRS="$TMP $TMPDIR $HOME/hasher /tmp /var/tmp .."
|
|
MINSIZE=262144 # face control criterion
|
|
|
|
# pick existing, writeable, >256M free space dirs
|
|
# rank them wrt type: tmpfs > realfs > rootfs
|
|
choose_tmpdir() {
|
|
for i in $DIRS; do
|
|
[ -d "$i" -a -w "$i" ] || continue
|
|
echo -n "$i "
|
|
df -Tl "$i" | tail -1
|
|
done \
|
|
| sort -unk6 \
|
|
| while read dir dev fstype size used free percent mnt; do
|
|
[ "$free" -gt "$MINSIZE" ] || continue
|
|
[ "$fstype" = "tmpfs" ] && { echo "2 $dir $free"; continue; }
|
|
[ "$mnt" = "/" ] && { echo "0 $dir $free"; continue; }
|
|
echo "1 $dir $free"
|
|
done \
|
|
| sort -n \
|
|
| tail -1 \
|
|
| cut -f2 -d' '
|
|
}
|
|
|
|
DIR="`choose_tmpdir`/`dirname "$1"`"
|
|
NAME="`basename "${1:-tmpdir}"`"
|
|
mkdir -p "$DIR" # in case $1 contains slash(es)
|
|
mktemp -d "$NAME.XXXXXXX" --tmpdir="${DIR%/.}"
|