cleanfs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. #!/bin/sh
  2. ########################################################################
  3. # Begin $rc_base/init.d/cleanfs
  4. #
  5. # Description : Clean file system
  6. #
  7. # Authors : Gerard Beekmans - gerard@linuxfromscratch.org
  8. #
  9. # Version : 00.00
  10. #
  11. # Notes :
  12. #
  13. ########################################################################
  14. . /etc/sysconfig/rc
  15. . ${rc_functions}
  16. # Function to create files/directory on boot.
  17. create_files() {
  18. # Read in the configuration file.
  19. exec 9>&0 < /etc/sysconfig/createfiles
  20. while read name type perm usr grp dtype maj min junk
  21. do
  22. # Ignore comments and blank lines.
  23. case "${name}" in
  24. ""|\#*) continue ;;
  25. esac
  26. # Ignore existing files.
  27. if [ ! -e "${name}" ]; then
  28. # Create stuff based on its type.
  29. case "${type}" in
  30. dir)
  31. mkdir "${name}"
  32. ;;
  33. file)
  34. :> "${name}"
  35. ;;
  36. dev)
  37. case "${dtype}" in
  38. char)
  39. mknod "${name}" c ${maj} ${min}
  40. ;;
  41. block)
  42. mknod "${name}" b ${maj} ${min}
  43. ;;
  44. pipe)
  45. mknod "${name}" p
  46. ;;
  47. *)
  48. boot_mesg -n "\nUnknown device type: ${dtype}" ${WARNING}
  49. boot_mesg "" ${NORMAL}
  50. ;;
  51. esac
  52. ;;
  53. *)
  54. boot_mesg -n "\nUnknown type: ${type}" ${WARNING}
  55. boot_mesg "" ${NORMAL}
  56. continue
  57. ;;
  58. esac
  59. # Set up the permissions, too.
  60. chown ${usr}:${grp} "${name}"
  61. chmod ${perm} "${name}"
  62. fi
  63. done
  64. exec 0>&9 9>&-
  65. }
  66. case "${1}" in
  67. start)
  68. boot_mesg -n "Cleaning file systems:" ${INFO}
  69. boot_mesg -n " /tmp" ${NORMAL}
  70. cd /tmp &&
  71. find . -xdev -mindepth 1 ! -name lost+found \
  72. -delete || failed=1
  73. boot_mesg -n " /var/lock" ${NORMAL}
  74. cd /var/lock &&
  75. find . -type f ! -newer /proc -exec rm -f {} \; || failed=1
  76. boot_mesg " /var/run" ${NORMAL}
  77. cd /var/run &&
  78. find . ! -type d ! -name utmp ! -newer /proc \
  79. -exec rm -f {} \; || failed=1
  80. > /var/run/utmp
  81. if grep -q '^utmp:' /etc/group ; then
  82. chmod 664 /var/run/utmp
  83. chgrp utmp /var/run/utmp
  84. fi
  85. (exit ${failed})
  86. evaluate_retval
  87. if egrep -qv '^(#|$)' /etc/sysconfig/createfiles 2>/dev/null; then
  88. boot_mesg "Creating files and directories..."
  89. create_files
  90. evaluate_retval
  91. fi
  92. ;;
  93. *)
  94. echo "Usage: ${0} {start}"
  95. exit 1
  96. ;;
  97. esac
  98. # End $rc_base/init.d/cleanfs