-
Notifications
You must be signed in to change notification settings - Fork 1
/
dotmanager.pl
139 lines (109 loc) · 3.44 KB
/
dotmanager.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
#!/usr/bin/perl
use strict;
use warnings;
use feature 'say';
my $root = $ENV{'HOME'};
my $current_dir = $ENV{'PWD'};
my %files = (
# awesome-wm
# awesome depends on other packages:
# (awesome-copycats, awesome-revelation, freedesktop)
".config/awesome/rc.lua" => $root,
".config/awesome/xrandr.lua" => $root,
# i3 config
".config/i3/config" => $root,
".config/i3/init.sh" => $root,
# kitty config
".config/kitty/kitty.conf" => $root,
# emacs config file
".emacs.d/init.el" => $root,
".emacs.bkp" => $root,
#general
# ".bash_profile" => $root,
# ".bashrc" => $root,
# ".config/.compton.conf" => $root,
".gitconfig" => $root,
# ".spacemacs" => $root,
".tmux.conf" => $root,
# ".vimrc" => $root,
# ".Xresources" => $root,
# ".zshrc" => $root,
#scripts
".local/bin/lock.sh" => $root,
);
=doc
Reads input prompt and returns answer (taken from StackOverflow)
=cut
sub prompt {
my ($query) = @_;
local $| = 1;
print $query;
chomp(my $answer = <STDIN>);
return $answer;
}
=doc
Install dotfiles of the current repository for the current user in the system
=cut
sub install {
my $skip = shift;
print("Starting the Installing Process \n");
foreach my $key (keys %files) {
my $source_file = $current_dir . "/" . $key;
my $destiny_file = $files{$key} . "/" . $key;
if (not $skip) {
my $answer = prompt("Are you sure you want to install $key ? [y/n]");
if (not ($answer eq 'y' || $answer eq 'Y')) {
print("Skipping $key update\n");
next;
}
}
print("Installing " . $key . " in " . $destiny_file . "\n");
my $result = `ln -s $source_file $destiny_file`;
if ($result) {
say "Failed to install " . $key . " is probably being used by other application or it does not exists";
}
}
}
=doc
Updates the current system dotfiles to the repository
=cut
sub update {
my $skip = shift;
print("Starting the Uploading Process\n");
foreach my $key (keys %files) {
my $source_file = $files{$key} . "/" . $key;
my $destiny_file = $current_dir . "/" . $key;
if (not $skip) {
my $answer = prompt("Are you sure you want to upload $key ? [y/n]");
if (not ($answer eq 'y' || $answer eq 'Y')) {
print("Skipping $key update\n");
next;
}
}
print("Uploading " . $source_file . " in " . $destiny_file . "\n");
my $result = `cp -TR $source_file $destiny_file`;
if ($result) {
print("Failed to update " . $key . " is probably being used by other application or it does not exists\n");
}
}
}
my $usage = "Usage: perl dotmanager.pl [OPTION] [BYPASS]\n
Options:
install [Install current files in repository to system]\n
update [Update files in repository with ones from the system]\n
Bypass:
--skip [Skip Confirmations]\n
";
if ($#ARGV > 2) {
print($usage);
} else {
my $option = $ARGV[0];
my $bypass = ($ARGV[1] and ($ARGV[1] eq "--skip")) or 0;
if ($option eq "install") {
install($bypass);
} elsif ($option eq "update") {
update($bypass);
} else {
print("Invalid argument\n$usage");
}
}