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
|
#!/usr/local/bin/perl -w
use strict;
use warnings;
use Term::ANSIColor;
sub upgrdports {
my $upgrd_nbr_cmd = "/usr/sbin/pkg version -l '<' | /usr/bin/wc -l | /usr/bin/awk '{print \$1}'";
if (system(
'/usr/local/bin/doas',
'/usr/sbin/pkg',
'update'
) != 0) {
exit;
}
if (system(
'/usr/local/bin/doas',
'/usr/sbin/portsnap',
'fetch',
'update'
) != 0) {
exit;
}
print colored("\nPorts to be updated: ", 'bold');
my $upgrd_nbr = `$upgrd_nbr_cmd`;
chomp $upgrd_nbr;
print colored($upgrd_nbr, 'bold green') . "\n";
open(PS, "/usr/sbin/pkg version -l '<' |");
while (<PS>) {
print
}
close(PS);
if ($upgrd_nbr == 0) {
print colored("No ports to be updated.\n", 'bold green');
exit;
}
print colored("\nUpgrade these ports? ", 'bold yellow')
. colored('[', 'bold green')
. colored('y', 'bold red')
. colored('/N', 'bold green')
. colored("]\n", 'bold green')
. colored("~> ", 'yellow');
my $answer = <STDIN>;
chomp $answer;
if ($answer ne "y" && $answer ne "Y") {
print "Exiting...\n";
exit;
}
system('/usr/local/bin/dash',
'-c',
'/usr/local/bin/notify-send "Initiating upgrade" "Ports upgrade has started\nTotal: ' . $upgrd_nbr . ' to be updated" >/dev/null 2>&1');
if ($upgrd_nbr == 1) {
system('/usr/local/bin/dash',
'-c',
'/usr/local/bin/espeak "Initiating ' . $upgrd_nbr . ' port upgrade" & >/dev/null 2>&1');
}
else {
system('/usr/local/bin/dash',
'-c',
'/usr/local/bin/espeak "Initiating ' . $upgrd_nbr . ' ports upgrade" & >/dev/null 2>&1');
}
if (system('/usr/local/bin/dash',
'-c',
'/usr/local/bin/doas /usr/local/sbin/portmaster -dya --no-confirm') == 0) {
my $failed_nbr = `$upgrd_nbr_cmd`;
chomp $failed_nbr;
my $diff_nbr = $upgrd_nbr - $failed_nbr;
system('/usr/local/bin/dash',
'-c',
'/usr/local/bin/notify-send "Upgrade complete!" "Ports upgrade installed successfully\nTotal: ' . $diff_nbr . ' installed" >/dev/null 2>&1');
system('/usr/local/bin/dash',
'-c',
'/usr/local/bin/espeak "Success: $upnbr ports upgrade installed successfully" & >/dev/null 2>&1');
}
else {
my $failed_nbr = `$upgrd_nbr_cmd`;
substr($failed_nbr, -1) = "";
my $diff_nbr = $upgrd_nbr - $failed_nbr;
system('/usr/local/bin/dash',
'-c',
'/usr/local/bin/notify-send -u critical -t 10000 "Upgrade failed!" "Some ports failed to compile\nTotal: ' . $diff_nbr . ' installed - ' . $failed_nbr . ' failed" >/dev/null 2>&1');
system('/usr/local/bin/dash',
'-c',
'/usr/local/bin/espeak "Failure: not all ports were upgraded - $diffnbr installed - $failednbr failed" & >/dev/null 2>&1');
}
exit;
}
sub configport {
my $port = $_[0];
my $port_basename = $_[1];
if (system(
'/usr/local/bin/doas',
'/usr/bin/make',
'config-recursive') == 0) {
if (system(
'/usr/local/bin/doas',
'/usr/bin/make',
'config-recursive') == 0) {
if (system(
'/usr/local/bin/doas',
'/usr/bin/make',
'config-recursive') == 0) {
}
system(
'/usr/local/bin/notify-send',
'Configuration success!',
'Ports config - ' . $port . ' - configured successfully',
);
my $pid;
$pid = fork();
if (not $pid) {
exec(
'/usr/local/bin/espeak',
'Success: ' . $port_basename . ' configured successfully. Initiating compilation.'
);
exit;
}
}
}
else {
system(
'/usr/local/bin/notify-send',
'-u',
'critical',
'-t',
'10000',
'Configuration failure!',
'Ports config - ' . $port . ' - failed to configure'
);
my $pid;
$pid = fork();
if (not $pid) {
exec(
'/usr/local/bin/espeak',
'Failure: failed to configure ' . $port_basename
);
exit;
}
}
}
sub installport {
my $port = $_[0];
my $port_basename = $_[1];
if (system(
'/usr/local/bin/doas',
'/usr/bin/make',
'install',
'clean'
) == 0) {
system(
'/usr/local/bin/notify-send',
'Compilation success!',
'Ports - ' . $port . ' - installed successfully'
);
my $pid;
$pid = fork();
if (not $pid) {
exec(
'/usr/local/bin/espeak',
'Success: ' . $port_basename . ' installed successfully'
);
exit;
}
}
else {
system(
'/usr/local/bin/notify-send',
'-u',
'critical',
'-t',
'10000',
'Compilation failure!',
'Ports - ' . $port . ' - failed to install'
);
my $pid;
$pid = fork();
if (not $pid) {
exec(
'/usr/local/bin/espeak',
'Failure: failed to install ' . $port_basename
);
exit;
}
}
}
sub main {
my $argc = $#ARGV + 1;
if ($argc == 0) {
print colored("Failed!\n", 'bold red')
. "No port or argument specified\n";
exit 1;
}
my $port = $ARGV[0];
if ($ARGV[0] eq "upgrade") {
upgrdports();
}
elsif (-d "/usr/ports/" . $port) {
my $port_basename = `echo $ARGV[0] | awk -F '/' '{print \$2}'`;
print colored("Port ", 'bold')
. colored($port, 'bold green')
. colored(" found\n", 'bold');
chdir "/usr/ports/" . $port;
configport($port, $port_basename);
installport($port, $port_basename);
}
else {
print colored("Failed!\n", 'bold red')
. "Port "
. colored($port, 'bold yellow')
. " doesn't exist in "
. colored("/usr/ports/\n", 'bold');
}
exit;
}
main();
__END__
|