14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
# File 'lib/metadata/linux/LinuxInitProcs.rb', line 14
def initialize(fs)
@fs = fs
@scriptsByName = {}
$log.debug "Determining init script directory..."
@init_dir = nil
INIT_DIRS.each do |id|
$log.debug "\tChecking: #{id}"
next unless @fs.fileExists?(id)
$log.debug "\tFound init script directory: #{id}"
@init_dir = id
break
end
unless @init_dir
$log.warn "Could not determine init script directory."
return
end
$log.debug "Determining RC script directory..."
@rc_dir = nil
@rc_chk = nil
RC_DIRS.each do |rd|
$log.debug "\tChecking: #{rd}"
next unless @fs.fileExists?(rd)
RC_CHECK.each do |rcc|
next unless @fs.fileExists?(File.join(rd, rcc))
@rc_chk = rcc
break
end
break unless @rc_chk
$log.debug "\tFound init script directory: #{rd} - checked: #{@rc_chk}"
@rc_dir = rd
break
end
unless @rc_dir
$log.warn "Could not determine RC script directory."
return
end
@fs.dirForeach(@init_dir) do |fn|
next if @fs.fileDirectory?(File.join(@init_dir, fn))
name = @fs.fileBasename(fn, ".sh")
next if name.downcase == "readme" || name == "." || name == ".."
addScript(@init_dir, fn, name)
end
if @rc_chk == "runlevels"
@rc_dir = File.join(@rc_dir, @rc_chk)
@run_levels = RUN_LEVELS2
else
@run_levels = RUN_LEVELS1
end
@run_levels.each do |rl|
if @rc_chk == "runlevels"
rld = File.join(@rc_dir, rl)
else
rld = File.join(@rc_dir, "rc#{rl}.d")
end
next unless @fs.fileDirectory?(rld)
@fs.dirForeach(rld) do |fn|
next if fn[0, 1] != "S" && fn[0, 1] != "K" && @rc_chk != "runlevels"
fp = File.join(rld, fn)
next unless @fs.fileSymLink?(fp)
lp = @fs.getLinkPath(fp)
name = @fs.fileBasename(lp, ".sh")
addScript(@fs.fileDirname(lp), @fs.fileBasename(lp), name) unless @scriptsByName[name]
sk = (@rc_chk == "runlevels" ? 'S' : fn[0, 1])
@scriptsByName[name].runLevels[sk] << rl
end
end
end
|