wg: Write rc(8) script to easily manage wg(4) interfaces
[dragonfly.git] / etc / rc.d / cleanvar
1 #!/bin/sh
2 #
3 # $FreeBSD: src/etc/rc.d/cleanvar,v 1.5 2003/07/14 13:02:36 mtm Exp $
4 #
5
6 # PROVIDE: cleanvar
7 # REQUIRE: mountcritlocal
8
9 . /etc/rc.subr 
10
11 dummy_rc_command "$1"
12
13 # use recursion and shell test, because /usr/bin/find is not yet mounted
14 #
15 purgedir()
16 {
17         local dir file
18
19         if [ $# -eq 0 ]; then
20                 purgedir .
21         else
22                 for dir
23                 do
24                 (
25                         cd "$dir" && for file in .* *
26                         do
27                                 [ ."$file" = .. -o ."$file" = ... ] && continue
28                                 if [ -d "$file" -a ! -L "$file" ]
29                                 then
30                                         purgedir "$file"
31                                 else
32                                         rm -f -- "$file"
33                                 fi
34                         done
35                 )
36                 done
37         fi
38 }
39
40 # These files must be removed only the first time this script is run
41 # on boot.
42 #
43 [ "$1" != "reload" ] && rm -f /var/run/clean_var /var/spool/lock/clean_var
44
45 # purge /var/run /var/spool/lock and /var/spool/uucp/.Temp/*
46 #
47 if [ -d /var/run -a ! -f /var/run/clean_var ]; then
48         purgedir /var/run
49         # And an initial utmpx file
50         (cd /var/run && cp /dev/null utmpx && chmod 644 utmpx;)
51         >/var/run/clean_var
52 fi
53 if [ -d /var/spool/lock -a ! -f /var/spool/lock/clean_var ]; then
54         purgedir /var/spool/lock
55         >/var/spool/lock/clean_var
56 fi
57 rm -rf /var/spool/uucp/.Temp/*
58