-
Notifications
You must be signed in to change notification settings - Fork 36
/
install_js.pl
146 lines (137 loc) · 4.18 KB
/
install_js.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
use strict;
use warnings;
use File::Path 'remove_tree';
use File::Spec;
use Getopt::Long;
GetOptions(
'debug=s@' => \(my $debug),
help => \(my $help),
'install=s@' => \(my $install = []),
list => \(my $list),
'path=s' => \(my $path = 'js/lib'),
'temp=s' => \(my $temp = 'tmp_js'),
);
my @debug_opts = qw(preserve verbose very_verbose);
my %dbg;
for my $d (@$debug) {
grep $_ eq $d, @debug_opts or die "Unknown debug option: $d";
$dbg{$_} = 1;
}
if ($help || !@$install && !$list) {
printf STDERR qq~CATS JS installer tool
Usage: $0 [--help]
[--debug=%s]
[--install=<library>|all]
[--list]
[--path=<destination path>, default is js/lib]
[--temp=<temporary path>, default is tmp_js]
~, join '|', @debug_opts;
exit;
}
my $modules = [
{
name => 'ace',
url => 'https://github.com/ajaxorg/ace-builds/archive/v1.3.3.zip',
src => 'ace-builds-1.3.3/src-min-noconflict',
dest => 'ace',
},
{
name => 'autocomplete',
url => 'https://github.com/devbridge/jQuery-Autocomplete/archive/v1.4.9.zip',
src => 'jQuery-Autocomplete-1.4.9/dist',
dest => 'autocomplete',
},
{
name => 'datepicker',
url => 'https://github.com/fengyuanchen/datepicker/archive/v1.0.0.zip',
src => 'datepicker-1.0.0/dist',
dest => 'datepicker',
},
{
name => 'flot',
url => 'http://www.flotcharts.org/downloads/flot-0.8.3.zip',
src => 'flot/jquery.flot.min.js',
},
{
name => 'jquery',
url => 'https://code.jquery.com/jquery-3.6.0.min.js',
dest => 'jquery.min.js',
},
{
name => 'mathjax',
url => 'https://github.com/mathjax/MathJax/archive/2.7.1.zip',
src => 'MathJax-2.7.1',
dest => 'MathJax',
},
{
name => 'survey',
url => 'https://unpkg.com/[email protected]/survey.jquery.js',
dest => 'survey.jquery.js',
},
{
name => 'hunspell_aff',
url => 'https://github.com/LibreOffice/dictionaries/blob/master/ru_RU/ru_RU.aff',
},
{
name => 'hunspell_dic',
url => 'https://github.com/LibreOffice/dictionaries/raw/master/ru_RU/ru_RU.dic',
},
];
sub prepare_names {
my ($m) = @_;
my ($filename) = ($m->{url} =~ /\/([a-zA-Z0-9_\-\.]+)$/) or die "Bad url: $m->{url}";
my $src = $m->{src} || $filename;
my $dest = $m->{dest} // '';
($filename, $src, $dest);
}
if ($list) {
for my $m (@$modules) {
my ($filename, $src, $dest) = prepare_names($m);
my (undef, undef, $src_file) = File::Spec->splitpath($src);
my $installed = -e File::Spec->catfile($path, $dest || $src_file);
printf "%12s: %s %s\n", $m->{name}, ($installed ? '+' : ' '), $m->{url};
}
}
$install = [ map $_->{name}, @$modules ] if grep $_ eq 'all', @$install;
$temp = '' if $temp =~ /^\.+$/;
if (@$install) {
my %modules_index;
$modules_index{$_->{name}} = $_ for @$modules;
if (my @not_found = grep !$modules_index{$_}, @$install) {
printf "Unknown modules: %s\n", join ', ', @not_found;
exit 1;
}
-d $path or die sprintf "Destinathion path does not exist: %s", $path;
{
my $wget = `wget --version` or die "wget: $!";
printf "wget: %s\n", $wget if $dbg{very_verbose};
my $unzip = `unzip -v` or die "unzip: $!";
printf "unzip: %s\n", $unzip if $dbg{very_verbose};
}
if ($temp) {
mkdir $temp or die "mkdir: $!" if !-d $temp;
chdir $temp;
}
for my $name (@$install) {
printf "Installing: %s...%s", $name, $dbg{verbose} ? "\n" : '';
my $m = $modules_index{$name};
my $q = $dbg{verbose} ? '' : '-q';
my ($filename, $src, $dest) = prepare_names($m);
if (-e $filename) {
printf "Already exists: %s\n", $filename if $dbg{verbose};
}
else {
`wget $q $m->{url}`;
}
if ($filename =~ /\.zip$/) {
`unzip -o $q $filename`;
}
printf "==> %s\n", $filename if $dbg{verbose};
`mv $src ../$path/$dest`;
print "ok\n";
}
if ($temp) {
chdir '..';
remove_tree $temp if !$dbg{preserve};
}
}