-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate.pl
More file actions
122 lines (90 loc) · 2.12 KB
/
Copy pathupdate.pl
File metadata and controls
122 lines (90 loc) · 2.12 KB
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
#!/usr/bin/perl -w
use warnings;
use strict;
use FindBin qw/$Bin/;
use Archive::Zip;
print "\n\nChecking for Updates\n\n";
# Check for --force option
my $force_update = 0;
for my $arg (@ARGV) {
if ($arg eq '--force') {
$force_update = 1;
print "Force update mode enabled\n";
last;
}
}
my $dir = "$Bin/updates";
my $url = 'http://raw.githubusercontent.com/jacob-jarick/rmplayer/master/builddate.txt';
my $file = &get($url);
my $old_file = "$Bin/builddate.txt";
if(!-d $dir)
{
print "creating $dir\n";
mkdir $dir;
}
&check_for_update unless $force_update;
print "\n\nUpdating\n\n";
$url = 'https://github.com/jacob-jarick/rmplayer/archive/master.zip';
my $zip_file = &get($url);
print "\n\nUpacking Update\n\n";
my $zip = Archive::Zip->new($zip_file);
foreach my $member ($zip->members)
{
next if $member->isDirectory;
my $filename = $member->fileName;
$filename =~ s/.*?\///;
print "extracting $filename\n";
$member->extractToFileNamed("$Bin/$filename");
}
print "\n\nUpdate Complete\n\n";
exit;
sub get
{
my $filename = $url;
$filename =~ m/.*\/(.*)$/;
$filename = $1;
my $save = "$dir/$filename";
unlink $save;
# PP does not pack https nicely, so instead, use windows powershell to download the files
if(lc $^O eq 'mswin32')
{
# thanks: https://superuser.com/questions/25538/how-to-download-files-from-command-line-in-windows-like-wget-is-doing
$save =~ s/\//\\/g;
my $cmd = "powershell -command \"Invoke-WebRequest -OutFile '$save' '$url'\"";
print "$cmd\n";
system($cmd);
return $save;
}
my $cmd = "wget -c -O '$save' '$url'";
print "$cmd\n";
system($cmd);
return $save;
}
sub check_for_update
{
print "Comparing:\n\t$old_file\n\tTO\n\t$file\n";
return if !-f $old_file;
open(FILE, $file) or die "$!";
my @tmp = <FILE>;
close(FILE);
open(FILE, $old_file) or die "cant read '$old_file' $!";
my @tmp2 = <FILE>;
close(FILE);
my $different = 0;
for my $i(0 .. $#tmp2)
{
# print "checking line $i\n";
$tmp[$i] =~ s/\n|\r//g;
$tmp2[$i] =~ s/\n|\r//g;
if($tmp[$i] ne $tmp2[$i])
{
$different++;
last;
}
}
if (!$different)
{
print "No update needed\n";
exit;
}
}