-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkrita_from_source.pl
executable file
·324 lines (233 loc) · 8.09 KB
/
krita_from_source.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
#!/usr/bin/perl
#-----------------------------------------------------------------------------#
# Copyright (c) 2011 Kirk Kimmel. All rights reserved.
# This program is free software; you can redistribute it and/or modify it
# under the GPL v3 license. See LICENSE.txt.
#
# The newest version of this file can be found at:
# https://github.com/kimmel/krita-from-source
#-----------------------------------------------------------------------------#
use v5.12;
use warnings;
use strict;
use English qw( -no_match_vars );
use Getopt::Long qw( GetOptions );
use Pod::Usage qw( pod2usage );
use Archive::Extract;
use POSIX qw( strftime );
use IO::CaptureOutput qw( qxx );
use File::Which qw( which );
use File::Find::Rule;
package main;
sub _ubuntu_notes {
print <<'UBUNTU';
WARNING: Ubuntu 11.04 (and distros based on it) are currently known to have
problems when using a Wacom (no pressure, strange lines drawn). There are
workarounds for both issues. Please see:
https://bugs.launchpad.net/ubuntu/natty/+source/qt4-x11/+bug/762938
and
https://bugs.launchpad.net/ubuntu/+source/xorg-server/+bug/799202
UBUNTU
return;
}
sub _print_time {
my $now_string = strftime "%Y-%m-%d %H:%M:%S", localtime;
return "$now_string - ";
}
sub detect_distro {
my $source = '/etc/issue';
if ( -r $source ) {
open my $f, '<', $source or die "Opening file $source: $ERRNO\n";
my $string = do { local ($RS); <$f> };
close $f;
given ($string) {
when (m/ubuntu/ixms) { _ubuntu_notes(); return 'ubuntu'; }
when (m/fedora/ixms) { return 'fedora'; }
when (m/opensuse/ixms) { return 'opensuse'; }
when (m/mint[ ]11/ixms) { return 'mint_11'; }
default {
print "Your linux version is currently not supported.\n";
exit 1;
}
}
}
}
sub _install_deps {
my $distro = shift;
my %shared = (
'ubuntu' => 'apt-get -force-yes -yes ',
'fedora' => 'yum -y ',
'opensuse' => 'zypper --non-interactive ',
'mint_11' => 'apt-get -force-yes -yes ',
);
my %remove = (
'ubuntu' => 'purge krita* koffice* karbon*',
'fedora' => 'remove koffice* calligra*',
'opensuse' => 'remove koffice* calligra*',
);
my %deps = (
'ubuntu' => 'install git wget && apt-get build-dep krita',
'fedora' => 'install git wget gcc gcc-c++ && yum-builddep koffice',
'opensuse' =>
'install cmake gcc gcc-c++ libkde4-devel libeigen2-devel libexiv2-devel liblcms2-devel',
'mint_11' =>
'install cmake kdelibs5-dev zlib1g-dev libpng12-dev libboost-dev liblcms1-dev libeigen2-dev libexiv2-dev pstoedit libfreetype6-dev libglew1.5-dev libfftw3-dev libglib2.0-dev libopenexr-dev libtiff4-dev libjpeg62-dev',
);
print "Installing missing dependencies now.\n";
#tools
my @tools = split /[ ]+/, ( $shared{$distro} . 'install git wget' );
my ( $stdout, $stderr, $success ) = qxx(@tools);
print "\n$stdout\n $stderr\n";
if ( $remove{$distro} ) {
my @blockers = split /[ ]+/, ( $shared{$distro} . $remove{$distro} );
( $stdout, $stderr, $success ) = qxx(@blockers);
print "\n$stdout\n $stderr\n";
}
#everything else
my @deps = split /[ ]+/, ( $shared{$distro} . $deps{$distro} );
( $stdout, $stderr, $success ) = qxx(@deps);
print "\n$stdout\n $stderr\n";
return;
}
sub check_deps {
my $distro = shift;
if ( !which('wget') or !which('git') ) {
if ( $EFFECTIVE_USER_ID != 0 ) {
print "Error. Please run as root to install system software.\n";
exit 1;
}
_install_deps($distro);
exit 1;
}
}
sub get_source_from_git {
my $distro = shift;
my $git_repo = 'git://anongit.kde.org/calligra';
my ( $stdout, $stderr );
if ( -e 'calligra_src/.git/config' ) {
chdir 'calligra_src/';
print "Performing a git pull now. This may take a while.\n\n";
( $stdout, $stderr ) = qxx( 'git', 'pull' );
}
else {
print
"Performing a git clone since no existing git repo was found.\n",
"This takes a long time depending on download times.\n\n";
( $stdout, $stderr ) = qxx( 'git', 'clone', $git_repo, 'calligra' );
}
return "###start git output###\n$stdout\n$stderr\n###end git output###\n";
}
sub _extract_tar_gz {
my $file = shift;
#this speeds up extraction
$Archive::Extract::PREFER_BIN = 1;
print "Extracting: $file\n";
my $ae = Archive::Extract->new( archive => $file, type => 'tgz' );
my $ok = $ae->extract() or die $ae->error;
return;
}
sub get_source_tar_gz {
my ( $stdout, $stderr );
my $rule = File::Find::Rule->new;
$rule->file;
$rule->name(qr/calligra_.+_sha1-.+[.]tar[.]gz/);
my @files = $rule->in('.');
if (@files) {
_extract_tar_gz( $files[0] );
chdir './calligra/';
print _print_time, "Initializing git repo.\n";
( $stdout, $stderr ) = qxx('./initrepo.sh');
chdir '..';
}
else {
print "Downloading calligra-latest.tar.gz\n";
( $stdout, $stderr )
= qxx( 'wget',
'http://anongit.kde.org/calligra/calligra-latest.tar.gz' );
get_source_tar_gz();
return;
}
print "###\n$stdout\n$stderr\n###\n";
return;
}
sub run {
Getopt::Long::Configure('bundling');
my $app_version = '1.0alpha';
my $target_dir = '/tmp/calligra';
my $cli_options = GetOptions(
'help|?' => sub { pod2usage( -verbose => 1 ) },
'man' => sub { pod2usage( -verbose => 2 ) },
'usage' => sub { pod2usage( -verbose => 0 ) },
'version' => sub { print "version: $app_version\n"; exit 1; },
'target-dir=s' => \$target_dir,
) or die "Incorrect usage.\n";
my $my_distro = detect_distro();
check_deps($my_distro);
if ( $EFFECTIVE_USER_ID == 0 ) {
print "Error. Action not permitted for user 'root'.\n";
exit 2;
}
print _print_time, "Process started.\n\n";
mkdir $target_dir;
chdir $target_dir;
get_source_tar_gz();
#print get_source_from_git($my_distro);
print _print_time, "Process completed.\n";
return;
}
run() unless caller;
1;
__END__
#-----------------------------------------------------------------------------
=pod
=head1 NAME
C<krita_from_source> - Build krita from source.
=head1 VERSION
=head1 USAGE
krita_from_source [ options ]
krita_from_source [ --taget-dir ]
krita_from_source { --help | --man | --usage | --version }
=head1 REQUIRED ARGUMENTS
=head1 ARGUMENTS
=head1 OPTIONS
These are the application options.
=over
=item C<--target-dir>
Set the target directory for the downloading.
=item C<--help>
Displays a brief summary of options and exits.
=item C<--man>
Displays the complete manual and exits.
=item C<--usage>
Displays the basic application usage.
=item C<--version>
Displays the version number and exits.
=back
=head1 DESCRIPTION
A script which automates the process of building krita from source without
the hassle of having to chase dependencies and know complex command line-fu.
=head1 DIAGNOSTICS
=head1 EXIT STATUS
0 - Sucessful program execution.
1 - Program exited normally. --help, --man, and --version return 1.
2 - Program exited normally. --usage returns 2.
=head1 CONFIGURATION
=head1 DEPENDENCIES
Perl version 5.12 or higher.
GNU Wget - The non-interactive network downloader.
git - the stupid content tracker
=head1 INCOMPATIBILITIES
=head1 BUGS AND LIMITATIONS
https://github.com/kimmel/krita-from-source/issues - File bugs here.
=head1 HOMEPAGE
https://github.com/kimmel/krita-from-source
=head1 AUTHOR
Kubuntutiac - A kde.org forum member who wrote the bash script this is
based off of.
Kirk Kimmel - Author of this Perl script
=head1 LICENSE AND COPYRIGHT
Copyright (c) 2011 < Kirk Kimmel >. All rights reserved.
This program is free software; you can redistribute it and/or modify it
under the GPL v3 license. The full text of this license can be found online
at < http://opensource.org/licenses/GPL-3.0 >
=cut