remove an old note for file
[linux_from_scratch.git] / BOOK / bootscripts / lfs / init.d / cleanfs
blobbbca3ddf657578d77e73ccb281269aa6def2bf4f
1 #!/bin/sh
2 ########################################################################
3 # Begin cleanfs
5 # Description : Clean file system
7 # Authors : Gerard Beekmans - gerard@linuxfromscratch.org
8 # DJ Lucas - dj@linuxfromscratch.org
9 # Update : Bruce Dubbs - bdubbs@linuxfromscratch.org
11 # Version : LFS 7.0
13 ########################################################################
15 ### BEGIN INIT INFO
16 # Provides: cleanfs
17 # Required-Start: $local_fs
18 # Should-Start:
19 # Required-Stop:
20 # Should-Stop:
21 # Default-Start: S
22 # Default-Stop:
23 # Short-Description: Cleans temporary directories early in the boot process.
24 # Description: Cleans temporary directories /run, /var/lock, and
25 # optionally, /tmp. cleanfs also creates /run/utmp
26 # and any files defined in /etc/sysconfig/createfiles.
27 # X-LFS-Provided-By: LFS
28 ### END INIT INFO
30 . /lib/lsb/init-functions
32 # Function to create files/directory on boot.
33 create_files()
35 # Input to file descriptor 9 and output to stdin (redirection)
36 exec 9>&0 < /etc/sysconfig/createfiles
38 while read name type perm usr grp dtype maj min junk
40 # Ignore comments and blank lines.
41 case "${name}" in
42 ""|\#*) continue ;;
43 esac
45 # Ignore existing files.
46 if [ ! -e "${name}" ]; then
47 # Create stuff based on its type.
48 case "${type}" in
49 dir)
50 mkdir "${name}"
52 file)
53 :> "${name}"
55 dev)
56 case "${dtype}" in
57 char)
58 mknod "${name}" c ${maj} ${min}
60 block)
61 mknod "${name}" b ${maj} ${min}
63 pipe)
64 mknod "${name}" p
66 *)
67 log_warning_msg "\nUnknown device type: ${dtype}"
69 esac
72 log_warning_msg "\nUnknown type: ${type}"
73 continue
75 esac
77 # Set up the permissions, too.
78 chown ${usr}:${grp} "${name}"
79 chmod ${perm} "${name}"
81 done
83 # Close file descriptor 9 (end redirection)
84 exec 0>&9 9>&-
85 return 0
88 case "${1}" in
89 start)
90 log_info_msg "Cleaning file systems:"
92 if [ "${SKIPTMPCLEAN}" = "" ]; then
93 log_info_msg2 " /tmp"
94 cd /tmp &&
95 find . -xdev -mindepth 1 ! -name lost+found -delete || failed=1
98 > /run/utmp
100 if grep -q '^utmp:' /etc/group ; then
101 chmod 664 /run/utmp
102 chgrp utmp /run/utmp
105 (exit ${failed})
106 evaluate_retval
108 if egrep -qv '^(#|$)' /etc/sysconfig/createfiles 2>/dev/null; then
109 log_info_msg "Creating files and directories... "
110 create_files # Always returns 0
111 evaluate_retval
114 exit $failed
117 echo "Usage: ${0} {start}"
118 exit 1
120 esac
122 # End cleanfs