treewide: replace /sbin/sh hashbangs with /bin/sh
[unleashed.git] / usr / src / cmd / svc / milestone / rmtmpfiles
blobb16f2eabd701d918f5ad06fd9c56fcdb6329033d
1 #!/bin/sh
3 # CDDL HEADER START
5 # The contents of this file are subject to the terms of the
6 # Common Development and Distribution License (the "License").
7 # You may not use this file except in compliance with the License.
9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 # or http://www.opensolaris.org/os/licensing.
11 # See the License for the specific language governing permissions
12 # and limitations under the License.
14 # When distributing Covered Code, include this CDDL HEADER in each
15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 # If applicable, add the following below this CDDL HEADER, with the
17 # fields enclosed by brackets "[]" replaced with your own identifying
18 # information: Portions Copyright [yyyy] [name of copyright owner]
20 # CDDL HEADER END
23 # Copyright 2009 Sun Microsystems, Inc. All rights reserved.
24 # Use is subject to license terms.
26 # For modifying the behavior of rmtmpfiles, do not edit this script.
27 # Instead use svccfg(1m) to modify the SMF repository. To achieve
28 # traditional System V treatment of /var/tmp, invoke the following
29 # commands.:
31 # # svccfg
32 # svc:> select system/rmtmpfiles
33 # svc:/system/rmtmpfiles> setprop options/clean_vartmp="true"
34 # svc:/system/rmtmpfiles> select default
35 # svc:/system/rmtmpfiles:default> refresh
36 # svc:/system/rmtmpfiles:default> exit
39 # Traditional SunOS 4.x behavior has been to not remove directories in
40 # the /tmp directory; only simple files were removed. This lead to an
41 # inconsistency when the tmpfs file system was used (which isn't persistent
42 # across boots. The following adopts the traditional System V behavior
43 # of removing everything in /tmp, unless /tmp or any of its subdirectories
44 # are mount points for another filesystem.
46 /sbin/mount | /usr/bin/egrep '^/tmp(/| )' >/dev/null 2>&1 || {
47 if [ -h /tmp ]; then
48 # Just remove files under directory if symbolic link
49 /usr/bin/rm -rf /tmp/*
50 else
51 /usr/bin/rm -rf /tmp
52 /usr/bin/mkdir -m 1777 /tmp
53 /usr/bin/chown root:sys /tmp
57 # Clean up /etc directory
59 for file in /etc/rem_name_to_major /etc/nologin; do
60 [ -f $file ] && /usr/bin/rm -f $file
61 done
63 # Traditional SunOS 4.x behavior has been to not alter the contents of
64 # /var/tmp (/usr/tmp) at boot time. This behavior is maintained as the
65 # current default behavior. If the traditional System V behavior of
66 # removing everything in /var/tmp is desired then clean up /var/tmp,
67 # unless /var/tmp or any of its subdirectories are mount points for
68 # another filesystem.
70 CLEAN_VARTMP=`svcprop -c -p options/clean_vartmp $SMF_FMRI`
71 if [ "$CLEAN_VARTMP" = "true" ]; then
72 /sbin/mount | /usr/bin/egrep '^/var/tmp(/| )' >/dev/null 2>&1 || {
73 cd /var/tmp || exit 0
75 # We carefully remove all files except the Ex* files (editor
76 # temporary files), which expreserve will process later (in
77 # S89PRESERVE). Of course, it would be simpler to just run
78 # expreserve before this script, but that doesn't work --
79 # expreserve requires the name service, which is not available
80 # until much later.
82 /usr/bin/ls -a | /usr/bin/egrep -v '^(Ex.*|\.|\.\.)$' |
83 /usr/bin/xargs /usr/bin/rm -rf -- 2>/dev/null
87 exit 0