cleanfs 2.6 KB

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