perusertmp revision 1.4
11.1Selad#!/bin/sh
21.1Selad#
31.4Selad# $NetBSD: perusertmp,v 1.4 2007/02/06 16:54:27 elad Exp $
41.1Selad#
51.1Selad
61.1Selad# PROVIDE: perusertmp
71.1Selad# REQUIRE: mountall
81.1Selad# BEFORE:  cleartmp
91.1Selad
101.1Selad$_rc_subr_loaded . /etc/rc.subr
111.1Selad
121.1Seladname="perusertmp"
131.1Seladrcvar="per_user_tmp"
141.1Seladstart_cmd="perusertmp_start"
151.1Seladstop_cmd=":"
161.1Selad
171.1Seladperusertmp_start()
181.1Selad{
191.1Selad	echo "Preparing per-user /tmp."
201.1Selad
211.1Selad	# If /tmp is a mount point, we can't do anything.
221.1Selad	if [ -d "/tmp" ]; then
231.1Selad		local mount_point
241.1Selad
251.1Selad		mount_point=$(cd /tmp && /bin/df . | /usr/bin/tail -1 | /usr/bin/awk '{print $6}')
261.1Selad		if [ X"${mount_point}" = X"/tmp" ]; then
271.1Selad			echo "WARNING: /tmp is mounted."
281.1Selad			exit 1
291.1Selad		fi
301.1Selad	fi
311.1Selad
321.1Selad	# Enable magic symlinks.
331.1Selad	/sbin/sysctl -qw vfs.generic.magiclinks=1
341.1Selad
351.1Selad	# Fixup real temporary directory.
361.1Selad	if [ ! -d ${per_user_tmp_dir} ]; then
371.2Sxtraeme		/bin/mkdir -p ${per_user_tmp_dir}
381.1Selad	fi
391.1Selad	/usr/sbin/chown root:wheel ${per_user_tmp_dir}
401.4Selad	/bin/chmod 0555 ${per_user_tmp_dir}
411.1Selad
421.1Selad	# Create magic link for /tmp.
431.3Selad	if [ $(/usr/bin/readlink /tmp) != ${per_user_tmp_dir}/@uid ]; then
441.3Selad		/bin/rm -rf /tmp
451.3Selad		/bin/ln -s ${per_user_tmp_dir}/@uid /tmp
461.3Selad	fi
471.1Selad}
481.1Selad
491.1Seladload_rc_config $name
501.1Seladrun_rc_command "$1"
51