forked from LMS-Community/slimserver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cleanup.pl
executable file
·389 lines (302 loc) · 9.55 KB
/
cleanup.pl
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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
#!/usr/bin/env perl -ICPAN
# Logitech Media Server Copyright 2001-2024 Logitech.
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License,
# version 2.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
require 5.010;
use Config;
use constant SPLASH_LOGO => 'lms_splash.png';
use constant ISWINDOWS => ( $^O =~ /^m?s?win/i ) ? 1 : 0;
use constant ISMAC => ( $^O =~ /darwin/i ) ? 1 : 0;
use constant ISACTIVEPERL => ( $Config{cf_email} =~ /ActiveState/i ) ? 1 : 0;
# don't use Wx, if script is run using perl on OSX, it needs to be run using wxperl
my $splash;
my $useWx = (!ISMAC || $^X =~ /wxPerl/i) && eval {
require Wx;
showSplashScreen();
require Wx::Event;
require Slim::GUI::ControlPanel;
return 1;
};
print "$@\n" if $@ && ISWINDOWS;
use strict;
use Socket;
use utf8;
use constant SLIM_SERVICE => 0;
use constant SCANNER => 0;
use constant RESIZER => 0;
use constant DEBUG => 1;
use constant TRANSCODING => 0;
use constant PERFMON => 0;
use constant DEBUGLOG => 0;
use constant INFOLOG => 0;
use constant STATISTICS => 0;
use constant SB1SLIMP3SYNC=> 0;
use constant WEBUI => 0;
use constant LOCALFILE => 0;
use constant NOMYSB => 1;
# load these later, don't need them right now
require File::Path;
require File::Spec::Functions;
require Getopt::Long;
require Slim::Utils::OSDetect;
require Slim::Utils::Light;
our $VERSION = '9.0.0';
BEGIN {
if (ISWINDOWS) {
eval { require Wx::Perl::Packager; }
}
}
if (DEBUG && $@) {
print "GUI can't be loaded: $@\n";
}
my ($os);
sub main {
Slim::Utils::OSDetect::init();
$os = Slim::Utils::OSDetect->getOS();
if (checkForSC() && !$useWx) {
print sprintf("\n%s\n\n", Slim::Utils::Light::string('CLEANUP_PLEASE_STOP_SC'));
exit;
}
my ($all, $cache, $filecache, $database, $prefs, $logs, $dryrun);
Getopt::Long::GetOptions(
'all' => \$all,
'cache' => \$cache,
'filecache' => \$filecache,
'prefs' => \$prefs,
'logs' => \$logs,
'database' => \$database,
'dryrun' => \$dryrun,
);
my $folders = getFolderList({
'all' => $all,
'cache' => $cache,
'filecache' => $filecache,
'prefs' => $prefs,
'logs' => $logs,
'database' => $database,
});
unless (scalar @$folders) {
# show simple GUI if possible
if ($useWx) {
my $app = Slim::GUI::ControlPanel->new({
folderCB => \&getFolderList,
cleanCB => \&cleanup,
options => options(),
});
$splash->Destroy();
$app->MainLoop;
exit;
}
else {
usage();
exit;
}
}
cleanup($folders, $dryrun);
print sprintf("\n%s\n\n", Slim::Utils::Light::string('CLEANUP_PLEASE_RESTART_SC'));
}
sub usage {
my $usage = <<EOF;
%s: $0 [--all] [--cache] [--database] [--filecache] [--prefs] [--logs]
%s
--database %s
--filecache %s
--prefs %s
--logs %s
--cache (!) %s
--all (!!) %s
--dryrun %s
EOF
print sprintf($usage,
Slim::Utils::Light::string('CLEANUP_USAGE'),
Slim::Utils::Light::string('CLEANUP_COMMAND_LINE'),
Slim::Utils::Light::string('CLEANUP_DB'),
Slim::Utils::Light::string('CLEANUP_FILECACHE'),
Slim::Utils::Light::string('CLEANUP_PREFS'),
Slim::Utils::Light::string('CLEANUP_LOGS'),
Slim::Utils::Light::string('CLEANUP_CACHE'),
Slim::Utils::Light::string('CLEANUP_ALL'),
Slim::Utils::Light::string('CLEANUP_DRYRUN'),
);
}
sub getFolderList {
my $args = shift;
my @folders;
my $cacheFolder = Slim::Utils::Light::getPref('cachedir') || $os->dirsFor('cache');
push @folders, _target('cache', 'cache') if ($args->{all} || $args->{cache});
if ($args->{all} || $args->{prefs} || $args->{cache} || $args->{filecache} || $args->{logs} || $args->{database}) {
push @folders, {
label => 'some legacy files',
folders => [
File::Spec::Functions::catdir($cacheFolder, 'MySQL'),
File::Spec::Functions::catdir($cacheFolder, 'my.cnf'),
File::Spec::Functions::catdir($cacheFolder, 'squeezecenter-mysql.pid'),
File::Spec::Functions::catdir($cacheFolder, 'squeezecenter-mysql.sock'),
File::Spec::Functions::catdir($cacheFolder, 'mysql-error-log.txt'),
File::Spec::Functions::catdir($cacheFolder, 'squeezebox.db'),
File::Spec::Functions::catdir($cacheFolder, 'squeezebox.db-shm'),
File::Spec::Functions::catdir($cacheFolder, 'squeezebox.db-wal'),
File::Spec::Functions::catdir($cacheFolder, 'squeezebox-persistent.db'),
File::Spec::Functions::catdir($cacheFolder, 'squeezebox-persistent.db-shm'),
File::Spec::Functions::catdir($cacheFolder, 'squeezebox-persistent.db-wal'),
File::Spec::Functions::catdir($cacheFolder, 'ArtworkCache.db'),
File::Spec::Functions::catdir($cacheFolder, 'ArtworkCache.db-shm'),
File::Spec::Functions::catdir($cacheFolder, 'ArtworkCache.db-wal'),
],
};
}
if ($args->{filecache}) {
push @folders, {
label => 'file cache (artwork, templates etc.)',
folders => [
File::Spec::Functions::catdir($cacheFolder, 'Artwork'),
File::Spec::Functions::catdir($cacheFolder, 'ArtworkCache'),
File::Spec::Functions::catdir($cacheFolder, 'audioUploads'),
File::Spec::Functions::catdir($cacheFolder, 'iTunesArtwork'),
File::Spec::Functions::catdir($cacheFolder, 'FileCache'),
File::Spec::Functions::catdir($cacheFolder, 'fonts.bin'),
File::Spec::Functions::catdir($cacheFolder, 'strings.bin'),
File::Spec::Functions::catdir($cacheFolder, 'extrastrings.json'),
File::Spec::Functions::catdir($cacheFolder, 'templates'),
File::Spec::Functions::catdir($cacheFolder, 'updates'),
File::Spec::Functions::catdir($cacheFolder, 'cookies.dat'),
File::Spec::Functions::catdir($cacheFolder, 'plugin-data.yaml'),
File::Spec::Functions::catdir($cacheFolder, 'cache.db'),
File::Spec::Functions::catdir($cacheFolder, 'cache.db-shm'),
File::Spec::Functions::catdir($cacheFolder, 'cache.db-wal'),
File::Spec::Functions::catdir($cacheFolder, 'artwork.db'),
File::Spec::Functions::catdir($cacheFolder, 'artwork.db-shm'),
File::Spec::Functions::catdir($cacheFolder, 'artwork.db-wal'),
File::Spec::Functions::catdir($cacheFolder, 'imgproxy.db'),
File::Spec::Functions::catdir($cacheFolder, 'imgproxy.db-shm'),
File::Spec::Functions::catdir($cacheFolder, 'imgproxy.db-wal'),
],
};
}
if ($args->{database}) {
push @folders, {
label => 'Musiclibrary data',
folders => [
File::Spec::Functions::catdir($cacheFolder, 'libmediascan.db'),
File::Spec::Functions::catdir($cacheFolder, '__db.001'),
File::Spec::Functions::catdir($cacheFolder, '__db.002'),
File::Spec::Functions::catdir($cacheFolder, '__db.003'),
File::Spec::Functions::catdir($cacheFolder, 'library.db'),
File::Spec::Functions::catdir($cacheFolder, 'library.db-shm'),
File::Spec::Functions::catdir($cacheFolder, 'library.db-wal'),
File::Spec::Functions::catdir($cacheFolder, 'persist.db'),
File::Spec::Functions::catdir($cacheFolder, 'persist.db-shm'),
File::Spec::Functions::catdir($cacheFolder, 'persist.db-wal'),
],
};
}
if ($args->{all} || $args->{prefs}) {
push @folders, _target('prefs', 'preferences');
push @folders, _target('oldprefs', 'old preferences (SlimServer <= 6.5)');
}
push @folders, _target('log', 'logs') if ($args->{all} || $args->{logs});
return \@folders;
}
sub _target {
my ($value, $label) = @_;
my $f = $os->dirsFor($value);
return {
label => $label,
folders => [ $f ],
};
}
sub options {
my $options = [
{
name => 'prefs',
title => Slim::Utils::Light::string('CLEANUP_PREFS'),
position => [30, 20],
},
{
name => 'filecache',
title => Slim::Utils::Light::string('CLEANUP_FILECACHE'),
position => [30, 40],
},
{
name => 'database',
title => Slim::Utils::Light::string('CLEANUP_DB'),
position => [30, 60],
},
{
name => 'logs',
title => Slim::Utils::Light::string('CLEANUP_LOGS'),
position => [30, 80],
},
{
name => 'cache',
title => Slim::Utils::Light::string('CLEANUP_CACHE'),
position => [30, 120],
},
{
name => 'all',
title => '(!) ' . Slim::Utils::Light::string('CLEANUP_ALL'),
position => [30, 160],
},
];
return $options;
}
sub checkForSC {
my $iaddr = inet_aton('127.0.0.1');
my $paddr = sockaddr_in(3483, $iaddr);
socket(SSERVER, PF_INET, SOCK_STREAM, getprotobyname('tcp'));
if (connect(SSERVER, $paddr)) {
close(SSERVER);
return 1;
}
return 0;
}
sub cleanup {
my ($folders, $dryrun) = @_;
for my $item (@$folders) {
print sprintf("\n%s %s...\n", Slim::Utils::Light::string('CLEANUP_DELETING'), $item->{label}) unless $useWx;
foreach ( @{$item->{folders}} ) {
next unless $_;
print "-> $_\n" if (-e $_ && !$useWx);
next if $dryrun;
if (-d $_) {
File::Path::rmtree($_);
}
elsif (-f $_) {
unlink $_;
}
}
}
}
sub showSplashScreen {
return unless $^O =~ /win/i;
my $file;
if (defined $PerlApp::VERSION) {
$file = PerlApp::extract_bound_file(SPLASH_LOGO);
}
else {
$file = SPLASH_LOGO;
}
if (!$file || !-f $file) {
$file = '../platforms/win32/res/' . SPLASH_LOGO;
}
Wx::Image::AddHandler(Wx::PNGHandler->new());
if (my $bitmap = Wx::Bitmap->new($file, Wx::wxBITMAP_TYPE_PNG())) {
$splash = Wx::SplashScreen->new(
$bitmap,
Wx::wxSPLASH_CENTRE_ON_SCREEN() | Wx::wxSPLASH_NO_TIMEOUT(),
0,
undef,
-1, [-1, -1], [-1, -1],
Wx::wxSIMPLE_BORDER() | Wx::wxSTAY_ON_TOP()
);
}
}
main();
__END__