forked from dbb/scripts
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrua.pl
executable file
·48 lines (36 loc) · 931 Bytes
/
rua.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
#!/usr/bin/perl
use strict;
use warnings;
# github.com/dbbolton
# rua - Regular User Aptitude script,
# for installing or removing packages as a regular user.
# Currently supports 'install' and 'remove'.
# Requires 'su'.
my $args = '-P ';
my $packages = '';
my $pattern = '';
my $action;
for (@ARGV) {
if ( /^(in|rm)$/ ) {
$action = 'install' if /in/;
$action = 'remove' if /rm/;
}
elsif ( /^-/ ) {
$args .= $_ . ' ';
}
elsif ( /^[~?]/ ) {
$pattern .= $_;
}
elsif ( /^[\w\-.]+$/ ) {
$packages .= $_ . ' ';
}
} # end of @ARGV loop
unless ( $action) {
die "Supply 'in' for 'install' or 'rm' for 'remove'.\n";
}
my $cmd = "aptitude $action ";
$cmd .= $args . ' ' if $args;
$cmd .= $packages . ' ' if $packages;
$cmd .= "'$pattern'" . ' ' if $pattern;
print "\n$cmd\n\n";
system "su root -c \"$cmd\" ";