1
0

cleanfs 2.8 KB

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