mkimage-profiles/bin/mktmpdir
Michael Shigorin b474bff468 iso.mk: low space hint on build failure
Just in case the build.log will be inobvious, and it's easy to diagnose
automatically.  Thanks Andrey Stroganov for this use case.

Thanks for improving the initial implementation go to raorn@ for kind
commit lynch and to Yuri Bushmelev for actually suggesting something
more concise.

BTW the "1024" magic number was taken out of thin air:
the "no free space" errors are most likely to happen while
forming/populating a chroot (apt/rpm errors out) and chroots are
roughly two orders of magnitude heftier than a megabyte.
2011-11-04 16:15:31 +02:00

30 lines
837 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=1048576 # face control criterion
# pick existing, writeable, >1Gb 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}.XXXXXXXXXX" --tmpdir="${DIR:-`realpath ..`}"