1 | #!/bin/sh
|
---|
2 | ########################################################################
|
---|
3 | # Begin cleanfs
|
---|
4 | #
|
---|
5 | # Description : Clean file system
|
---|
6 | #
|
---|
7 | # Authors : Gerard Beekmans - gerard@linuxfromscratch.org
|
---|
8 | # Update : Bruce Dubbs - bdubbs@linuxfromscratch.org
|
---|
9 | #
|
---|
10 | # Version : LFS 7.0
|
---|
11 | #
|
---|
12 | ########################################################################
|
---|
13 |
|
---|
14 | ### BEGIN INIT INFO
|
---|
15 | # Provides: cleanfs
|
---|
16 | # Required-Start: $local_fs
|
---|
17 | # Should-Start:
|
---|
18 | # Required-Stop:
|
---|
19 | # Should-Stop:
|
---|
20 | # Default-Start: S
|
---|
21 | # Default-Stop:
|
---|
22 | # Short-Description: Cleans temporary directories early in the boot process.
|
---|
23 | # Description: Cleans temporary directories /var/run, /var/lock, and
|
---|
24 | # optionally) /tmp. cleanfs also creates /var/run/utmp
|
---|
25 | # and any files defined in /etc/sysconfig/createfiles.
|
---|
26 | # X-LFS-Provided-By: LFS
|
---|
27 | ### END INIT INFO
|
---|
28 |
|
---|
29 | . /lib/boot/functions
|
---|
30 |
|
---|
31 | # Function to create files/directory on boot.
|
---|
32 | create_files() {
|
---|
33 | # Read in the configuration file.
|
---|
34 | exec 9>&0 < /etc/sysconfig/createfiles
|
---|
35 | while read name type perm usr grp dtype maj min junk
|
---|
36 | do
|
---|
37 | # Ignore comments and blank lines.
|
---|
38 | case "${name}" in
|
---|
39 | ""|\#*) continue ;;
|
---|
40 | esac
|
---|
41 |
|
---|
42 | # Ignore existing files.
|
---|
43 | if [ ! -e "${name}" ]; then
|
---|
44 | # Create stuff based on its type.
|
---|
45 | case "${type}" in
|
---|
46 | dir)
|
---|
47 | mkdir "${name}"
|
---|
48 | ;;
|
---|
49 | file)
|
---|
50 | :> "${name}"
|
---|
51 | ;;
|
---|
52 | dev)
|
---|
53 | case "${dtype}" in
|
---|
54 | char)
|
---|
55 | mknod "${name}" c ${maj} ${min}
|
---|
56 | ;;
|
---|
57 | block)
|
---|
58 | mknod "${name}" b ${maj} ${min}
|
---|
59 | ;;
|
---|
60 | pipe)
|
---|
61 | mknod "${name}" p
|
---|
62 | ;;
|
---|
63 | *)
|
---|
64 | boot_mesg -n "\nUnknown device type: ${dtype}" ${WARNING}
|
---|
65 | boot_mesg "" ${NORMAL}
|
---|
66 | ;;
|
---|
67 | esac
|
---|
68 | ;;
|
---|
69 | *)
|
---|
70 | boot_mesg -n "\nUnknown type: ${type}" ${WARNING}
|
---|
71 | boot_mesg "" ${NORMAL}
|
---|
72 | continue
|
---|
73 | ;;
|
---|
74 | esac
|
---|
75 |
|
---|
76 | # Set up the permissions, too.
|
---|
77 | chown ${usr}:${grp} "${name}"
|
---|
78 | chmod ${perm} "${name}"
|
---|
79 | fi
|
---|
80 | done
|
---|
81 | exec 0>&9 9>&-
|
---|
82 | }
|
---|
83 |
|
---|
84 | case "${1}" in
|
---|
85 | start)
|
---|
86 | boot_mesg -n "Cleaning file systems:" ${INFO}
|
---|
87 |
|
---|
88 | if [ "${SKIPTMPCLEAN}" = "" ]; then
|
---|
89 | boot_mesg -n " /tmp" ${NORMAL}
|
---|
90 | cd /tmp &&
|
---|
91 | find . -xdev -mindepth 1 ! -name lost+found -delete || failed=1
|
---|
92 | fi
|
---|
93 |
|
---|
94 | > /var/run/utmp
|
---|
95 |
|
---|
96 | if grep -q '^utmp:' /etc/group ; then
|
---|
97 | chmod 664 /var/run/utmp
|
---|
98 | chgrp utmp /var/run/utmp
|
---|
99 | fi
|
---|
100 |
|
---|
101 | (exit ${failed})
|
---|
102 | evaluate_retval
|
---|
103 |
|
---|
104 | if egrep -qv '^(#|$)' /etc/sysconfig/createfiles 2>/dev/null; then
|
---|
105 | boot_mesg "Creating files and directories..."
|
---|
106 | create_files
|
---|
107 | evaluate_retval
|
---|
108 | fi
|
---|
109 | ;;
|
---|
110 | *)
|
---|
111 | echo "Usage: ${0} {start}"
|
---|
112 | exit 1
|
---|
113 | ;;
|
---|
114 | esac
|
---|
115 |
|
---|
116 | # End cleanfs
|
---|