-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbootstrap.pl
73 lines (63 loc) · 1.69 KB
/
bootstrap.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
#!/usr/bin/perl
use strict;
use warnings FATAL => 'all';
use Term::ANSIColor qw(:constants);
$Term::ANSIColor::AUTORESET = 1;
use Getopt::Long;
use Cwd qw(abs_path);
use File::Basename;
#
# yet another dotfiles bootstrapper(TM) perl edition
#
# all the file => link mappings are in the bootstrap.conf file
# without arguments, the script will just check what can be done,
# with the --exec flag it will actually create
# links for files that are 'linkable'
# everything done in full ANSI color because why not
#
require 'bootstrap.conf';
our ($src_dir, $dst_dir, $index);
my $exec = 0;
GetOptions(
"exec" => \$exec # actually make the links
);
while(my ($s, $d) = each %$index) {
# makes files relative to the src and dst dir's
# expand shell variables like $HOME
($s) = glob($src_dir.$s);
($d) = glob($dst_dir.$d);
my $txt = RESET. (BOLD "[$s]")." to ".BOLD "[$d]";
$txt =~ s/$ENV{HOME}/~/g;
# source file not found
unless(-e $s) {
print RED sprintf("%26s","Source doesn't exist. "), $txt, "\n";
next;
}
# destination file exists
if(-e $d) {
if(abs_path($d) eq abs_path($s)) { # its already linked or its the same file
print CYAN sprintf("%26s","Link already exists. "), $txt, "\n";
next;
}
else {
print YELLOW sprintf("%26s","Dest. exists. "), $txt, "\n";
next;
}
}
my ($filename, $path) = fileparse($d);
# destination path does not exist
unless(-e $path) {
print YELLOW sprintf("%26s","Dest. path doesn't exist. "), $txt, "\n";
next;
}
if($exec) {
if(symlink $s, $d) {
print GREEN sprintf("%26s","Link created. "), $txt, "\n";
}
else {
print RED "Link Error: $!. ", $txt, "\n";
}
} else {
print GREEN sprintf("%26s","Linkable. "), $txt, "\n";
}
}