1
0

cleanfs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. #!/bin/sh
  2. ########################################################################
  3. # Begin cleanfs
  4. #
  5. # Description : Clean file system
  6. #
  7. # Authors : Gerard Beekmans - gerard@linuxfromscratch.org
  8. # DJ Lucas - dj@linuxfromscratch.org
  9. # Update : Bruce Dubbs - bdubbs@linuxfromscratch.org
  10. #
  11. # Version : LFS 7.0
  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. . /lib/lsb/init-functions
  29. # Function to create files/directory on boot.
  30. create_files()
  31. {
  32. # Input to file descriptor 9 and output to stdin (redirection)
  33. exec 9>&0 < /etc/sysconfig/createfiles
  34. while read name type perm usr grp dtype maj min junk
  35. do
  36. # Ignore comments and blank lines.
  37. case "${name}" in
  38. ""|\#*) continue ;;
  39. esac
  40. # Ignore existing files.
  41. if [ ! -e "${name}" ]; then
  42. # Create stuff based on its type.
  43. case "${type}" in
  44. dir)
  45. mkdir "${name}"
  46. ;;
  47. file)
  48. :> "${name}"
  49. ;;
  50. dev)
  51. case "${dtype}" in
  52. char)
  53. mknod "${name}" c ${maj} ${min}
  54. ;;
  55. block)
  56. mknod "${name}" b ${maj} ${min}
  57. ;;
  58. pipe)
  59. mknod "${name}" p
  60. ;;
  61. *)
  62. log_warning_msg "\nUnknown device type: ${dtype}"
  63. ;;
  64. esac
  65. ;;
  66. *)
  67. log_warning_msg "\nUnknown type: ${type}"
  68. continue
  69. ;;
  70. esac
  71. # Set up the permissions, too.
  72. chown ${usr}:${grp} "${name}"
  73. chmod ${perm} "${name}"
  74. fi
  75. done
  76. # Close file descriptor 9 (end redirection)
  77. exec 0>&9 9>&-
  78. return 0
  79. }
  80. case "${1}" in
  81. start)
  82. log_info_msg "Cleaning file systems:"
  83. if [ "${SKIPTMPCLEAN}" = "" ]; then
  84. log_info_msg2 " /tmp"
  85. cd /tmp &&
  86. find . -xdev -mindepth 1 ! -name lost+found -delete || failed=1
  87. fi
  88. > /var/run/utmp
  89. if grep -q '^utmp:' /etc/group ; then
  90. chmod 664 /var/run/utmp
  91. chgrp utmp /var/run/utmp
  92. fi
  93. (exit ${failed})
  94. evaluate_retval
  95. if egrep -qv '^(#|$)' /etc/sysconfig/createfiles 2>/dev/null; then
  96. log_info_msg "Creating files and directories... "
  97. create_files # Always returns 0
  98. evaluate_retval
  99. fi
  100. exit $failed
  101. ;;
  102. *)
  103. echo "Usage: ${0} {start}"
  104. exit 1
  105. ;;
  106. esac
  107. # End cleanfs