mkimage-profiles/bin/mktmpdir
Michael Shigorin b6438b9c8f bin/mktmpdir: lower the space bar
With not-that-recent mkimage-profiles development,
it's no longer apparent that at least a gigabyte
of free space is required to build something useful
(at least for the tests, like syslinux.iso).

In short, the guesser cutoff margin is now 256M.
2011-11-06 17:36:09 +02:00

30 lines
834 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`"
mktemp -d "${1:-tmpdir}.XXXXXXX" --tmpdir="${DIR:-`realpath ..`}"