-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinstall
executable file
·225 lines (178 loc) · 4.94 KB
/
install
1
2
3
4
5
6
7
8
9
10
11
12
13
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
#!/usr/bin/env ruby
# frozen_string_literal: true
# Copyright (C) 2017 Dimitri Arrigoni <dimitri@arrigoni.me>
# License GPLv3+: GNU GPL version 3 or later
# <http://www.gnu.org/licenses/gpl.html>.
# This is free software: you are free to change and redistribute it.
# There is NO WARRANTY, to the extent permitted by law.
require 'fileutils'
require 'pathname'
require 'yaml'
require 'pp'
# Installer class
#
# compatible with wicd-gtk version >= 1.7
class Installer
attr_reader :srcdir
attr_reader :flavour
class << self
def install(flavour = :light)
self.new(flavour || :light).install
end
end
def initialize(flavour = :light)
@flavour = flavour
@srcdir = Pathname.new(__dir__).join('src')
raise ArgumentError.new('Invalid flavour: %s' % flavour) unless flavour?
end
def flavour_directory
srcdir.join('flavours', flavour.to_s)
end
def flavour?
flavour_directory.directory?
end
def manifest
@manifest ||= YAML.load_file(Pathname.new(__dir__).join('manifest.yml'))
@manifest
end
def install
prepare.install_statuses.clean
install_hicolor
install_launcher
self
end
def install_statuses
formats = [
16, 22, # samll
24, 32, 36, 48, 'original' # big
]
formats.each do |size|
get_status_paths(size).each { |k, v| install_file(v, k) }
end
self
end
def install_launcher
source = srcdir.join('wicd.desktop')
(manifest.fetch('paths')['applications'] || {}).to_a.each do |target|
target = Pathname.new(target).join(source.basename)
install_file(source, target)
end
self
end
# Install app icons
#
# @return [self]
def install_hicolor
icons_dir = srcdir.join('apps')
remove_pixmap = false
Dir.chdir(icons_dir) do
Dir.glob(['*/*.png', '*/*.svg'])
.map { |path| Pathname.new(path) }
.each do |icon|
format = icon.dirname.to_s
fname = icon.basename
(manifest.fetch('paths')['icons_hicolor'] || {}).to_a.each do |target|
target_icon = Pathname.new(target).join(format, 'apps', fname)
if install_file(icon.realpath, target_icon) and !remove_pixmap
remove_pixmap = true
end
end
end
end
if remove_pixmap
(manifest.fetch('paths')['pixmaps'] || {}).to_a.each do |path|
target_icon = Pathname.new(path).join('wicd-gtk.xpm')
FileUtils.rm_f(target_icon, verbose: true)
end
end
self
end
# Make symlinks for concerned (source) icons
#
# @return [self]
def prepare
Dir.chdir(flavour_directory) do
manifest.fetch('preparables').each do |k, values|
values.each do |v|
paths = ["#{k}.png", "#{v}.png"]
FileUtils.ln_sf(paths[0], paths[1], verbose: false)
end
end
end
self
end
# Remove symlinks from sources
#
# @return [self]
def clean
Dir.chdir(flavour_directory) do
manifest.fetch('preparables').each do |k, values|
values.each { |v| FileUtils.remove("#{v}.png") }
end
end
self
end
protected
# File is installed only if target exists and is a file
#
# @return [Boolean]
def install_file(source, target)
source = Pathname.new(source)
target = Pathname.new(target)
return false unless target.exist? and target.file?
FileUtils.rm_f(target)
FileUtils.cp(source, target, verbose: true)
true
end
# @return [Array]
def get_status_directories_by_formats(formats)
directories = []
formats.each do |size|
get_status_paths(size).each do |k, v|
directories.push(k.dirname)
end
end
directories.uniq
end
def get_status_paths(size, format = 'png')
size = [size, size].join('x') if size.to_s =~ /^[0-9]{2}$/
if ['16x16', '22x22'].include?(size)
get_status_small_paths(size, format)
else
get_status_big_paths(size, format)
end
end
# Get paths for icons in 16x16 and 22x22 formats
#
# @param [String] size
# @param [String] format
# @return [Hash]
def get_status_small_paths(size = '16x16', format = 'png')
items = manifest.fetch('statuses').fetch('small')
make_status_paths(items, size, format)
end
# Get paths for icons with size from 32x32 and higher
#
# @param [String] size
# @param [String] format
# @return [Hash]
def get_status_big_paths(size = '32x32', format = 'png')
items = manifest.fetch('statuses').fetch('big')
make_status_paths(items, size, format)
end
def make_status_paths(statuses, size, format)
result = {}
(manifest.fetch('paths')['wicd_icons'] || {}).to_a.each do |rootdir|
rootdir = Pathname.new(rootdir)
statuses.each do |k, v|
paths = [
rootdir.join(size, 'status', '%s.%s' % [k, format]),
flavour_directory.realpath.join('%s.%s' % [(v || k), format])
]
result[paths[0]] = paths[1]
end
end
result
end
end
Installer.install(ARGV[0]) if __FILE__ == $0