#!/bin/sh
# tmpfs on /tmp with the options of systemd's tmp.mount. /etc/default/tmpfs
# (tmpfs-config(5)): RAMTMP=no leaves /tmp on its file system, TMP_SIZE sets
# the size (a size in %VM counts as % of the RAM). Not mounted if /tmp is a
# link, a mount point already or listed in /etc/fstab.
RAMTMP=yes
TMP_SIZE=
# shellcheck disable=SC1091
[ -r /etc/default/tmpfs ] && . /etc/default/tmpfs
[ "$RAMTMP" = no ] && { echo "tmp.mount: RAMTMP=no"; exit 0; }
TMP_SIZE=${TMP_SIZE%VM}
[ -L /tmp ] && exit 0
mountpoint -q /tmp && exit 0
if [ -r /etc/fstab ]; then
	while read -r spec mp rest; do
		case $spec in '' | \#*) continue ;; esac
		[ "$mp" = /tmp ] && exit 0
	done </etc/fstab
fi
exec mount -t tmpfs -o "mode=1777,strictatime,nosuid,nodev,size=${TMP_SIZE:-50%},nr_inodes=1m" tmpfs /tmp
