-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinstall.pl
executable file
·147 lines (112 loc) · 3.36 KB
/
install.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
#!/usr/bin/env perl
use strict; use warnings;
use feature 'say';
use Cwd;
use Getopt::Long;
use Pod::Usage;
use Data::Dumper;
our $cwd = getcwd();
my $cpan_path = `which cpan`;
my $bin_dir = "/usr/local/bin";
if (!$cpan_path) {
say "Please install cpan command line tool in order to proceed with the installation.";
say "http://www.cpan.org/modules/INSTALL.html\n";
die "Installation aborted.\n";
}
GetOptions(
'bin-dir=s' => \$bin_dir,
q(help) => \my $help,
) or die 'Incorrect usage';
pod2usage(q(-verbose) => 1) if $help;
say ">> Checking requirements:";
if (!-d $bin_dir) {
say "'$bin_dir' directory not found, creation in progress...";
if (!mkdir($bin_dir)) {
say "Not enough permissions for creation of '$bin_dir' directory. Retrying with sudo...";
my $user = `whoami`;
my $group = `id -gn`;
chomp($user);
chomp($group);
`sudo mkdir -p $bin_dir`;
if (!-d $bin_dir) {
die("There was a problem while creating '$bin_dir' directory. Please create it and set writable permissions and then try again.\n");
}
`sudo chown -R $user:$group $bin_dir`;
`sudo chmod u+w $bin_dir`;
`sudo chmod g+w $bin_dir`;
}
say "'$bin_dir' directory successfully created.";
}
say "Requirements are ok! Proceeding with the installation.";
say ">> Installing vendors:";
require './vendors.pl';
my @vendors = get_vendors();
foreach my $vendor (@vendors) {
say "\n>> Installing [$vendor]";
my $options = ($^V lt 'v5.18.0') ? '-i -f' : '-i -T';
say "▶ cpan $options $vendor";
system("cpan $options $vendor");
}
say "\n>> Applying patches:";
foreach my $vendor (@vendors) {
$vendor =~ s/^[A-Z]+\/(\w+)\-(\w+)(.*)/$1::$2/;
my $patches_dir = "$cwd/Patches/$vendor";
if (-d $patches_dir) {
say "[$vendor]";
my @list;
opendir(DIR, $patches_dir) || die "Can't open directory $patches_dir: $!";
@list = grep /\.patch$/, readdir(DIR);
closedir DIR;
my $file = $vendor;
$file =~ s/(\w+)\:\:(\w+)/$1\/$2.pm/i;
foreach my $path (@INC) {
my $full_path = "$path/$file";
if (-f $full_path) {
foreach my $patch (@list) {
say "Applying patch $patch at $full_path...";
system("sudo patch -sN $full_path $patches_dir/$patch");
}
}
}
}
}
print "\n>> Generating Memento man page: ";
my $man_dir = $cpan_path;
chomp($man_dir);
$man_dir =~ s/\/bin\/cpan$//;
my $man = `pod2man -s 1 -c Memento memento.pl | sudo tee -a $man_dir/share/man/man1/memento.1`;
say "ok!";
chdir;
my $home = getcwd();
my $storage = "$home/.memento";
if (!-d $storage) {
say "\n>> Creating ~/.memento folder";
mkdir($storage) or die "Cannot create .memento dir in your home directory: $!\n";
}
if (!-f "$bin_dir/memento") {
say "\n>> Creating memento symlink";
`sudo ln -s $cwd/memento.pl $bin_dir/memento`;
}
say "\nMemento installation finished.";
say "Please add the following lines to your .bashrc or .zshrc file:\n";
say "\tmemento schema check\n";
my $memento_dir = `memento schema root`;
chomp($memento_dir);
say "$memento_dir/misc/completion.sh";
1;
__END__
=pod
=encoding UTF-8
=head1 NAME
memento install
=head1 VERSION
version 1.1.8
=head1 USAGE
The installation script must be run in the following way:
"perl install.pl" or "./install.pl":
=over 2
=item --bin-dir
Can be used to define a custom bin directory. If not set "/usr/local/bin" will
be used as the default one.
=back
=cut