-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdeploy.pl
More file actions
executable file
·100 lines (72 loc) · 2.01 KB
/
Copy pathdeploy.pl
File metadata and controls
executable file
·100 lines (72 loc) · 2.01 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
#!/usr/bin/env perl
#
# Description: A simple dotfile installer with minimal dependencies
#
use v5.10;
use strict;
use warnings;
use File::Basename;
use File::Spec;
my $target = $ARGV[0] // $ENV{HOME};
my $source_dir = File::Spec->rel2abs(dirname($0));
my %excludes = map { $_ => 1 } basename($0), qw(.git .gitmodules);
my $mappings = {
'gitignore' => '.gitignore'
};
my @src = grep { !/sw[op]$/ && !$excludes{$_} }
keys %{{
map { $_ => 1 } keys($mappings), get_sources($source_dir)
}};
foreach my $source (@src) {
if ($mappings->{$source}) {
# custom deployment
}
deploy($source, $target, $mappings->{$source});
add_to_profile('.bashrc');
}
sub get_sources {
my $dir = shift;
opendir my $dh, $dir or die "'$dir': $!";
my @entries = grep { !/^\.\.?$/ } readdir($dh);
closedir $dh;
return @entries;
}
sub deploy {
my ($source, $target, $target_basename) = @_;
my $source_path = File::Spec->catfile($source_dir, $source);
my $target_path = File::Spec->catfile($target, $target_basename // $source);
if (symlink $source_path, $target_path) {
printf "+ $target_path .... OK\n";
} else {
warn "skipping '$target_path': $!\n";
}
}
sub add_to_profile {
my $profile = shift;
my $file = File::Spec->catfile($ENV{HOME}, $profile);
if (system(qw(grep https://github.com/simonflk/dotfiles), $file) != 0) {
open my $bashrc, ">>", $file or die "error opening $file -- $!";
print $bashrc "\n\n"
."# initialise dotfiles (https://github.com/simonflk/dotfiles)\n"
."source ~/.bash/init\n\n"
}
}
__END__
=head1 NAME
deploy.pl
=head1 SYNOPSIS
deploy.pl [dir]
=head1 DESCRIPTION
Symlinks all the files in this dierctory into the users C<$HOME>, (or
alternate target directory)
Excludes some files by default
=head1 CAVEATS
=over 4
=item *
Has minimal dependencies, just standard perl (5.10+)
=item *
Not very configurable. Probably doesn't need to be
=back
=head1 AUTHOR
Simon Flack
=cut