forked from logenkain/xacman
-
Notifications
You must be signed in to change notification settings - Fork 0
/
xacman.pl
executable file
·119 lines (101 loc) · 2.18 KB
/
xacman.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
#!/usr/bin/perl
# todo
# I want all failures to print a command list, not the xbps default
use v5.10.0;
use warnings;
use strict;
sub usage{
print STDERR ("Usage: xacman [OPERATION/OPTION] [PACKAGE NAME]\n");
print STDERR ("EXAMPLE: xacman -Sy tilda; xacman --refresh tilda\n");
#Operations
print STDERR ("OPERATIONS:\n");
print STDERR (" -S, --sync Install [PACKAGE NAME]\n");
print STDERR (" -R, --remove Remove [PACKAGE NAME]\n");
#Sync Options
print STDERR ("Sync Options:\n");
print STDERR (" s, --search Search for packages\n");
print STDERR (" y, --refresh Refresh package list\n");
print STDERR (" u, --upgrade Update [PACKAGE NAME]\n");
}
sub xbps{ ## How I execute code
exec("@_");
}
my $xbI = 'xbps-install';
my $xbQ = 'xbps-query';
my $xbR = 'xbps-remove';
my $action = $ARGV[0]; # Which xbps program to call
if (not $action){
usage(); exit 0;}
my $args = "@ARGV[1..$#ARGV]";
my $cmd = #which term to search/remove/install
#Pass a quotes to -Rs to list all packages
#Pass usage guide in case of -S
&{ sub {
if ($ARGV[1]){
return "$args"; #make cmd become a string of the args, quotes add spaces between args
}
elsif($action eq '-Ss'){
return '"" ';
}
elsif($action eq '-Sy'){
return "pass";
}
elsif($action eq '--refresh'){
return "pass";
}
elsif($action eq '-Su'){
return "pass";
}
elsif($action eq '-Syu'){
return "pass";
}
else{
return undef;
}
}
}();
if (not $cmd){ #If cmd is blank, with the exceptions above (the sub) then fail.
usage(); exit 0;}
#clear the variable so xbps doesn't try to search for it
if ($cmd eq "pass"){
$cmd = undef;}
if ($action eq '-S' || $action eq '-sync')
{
#Xbps-install
$action = $xbI;
}
elsif($action eq '-Su' || $action eq '--upgrade')
{
#Xbps-install
$action = "$xbI -u";
}
elsif($action eq '-Syu')
{
#Xbps-install
$action = "$xbI -Su";
}
elsif($action eq '-Sy' || $action eq '--refresh')
{
#Xbps-install
$action = "$xbI -S";
}
elsif($action eq '-Ss' || $action eq '--search')
{
#xbps-query
$action = "$xbQ -Rs";
}
elsif($action eq '-R' || $action eq '--remove')
{
#xbps-remove
$action = $xbR;
}
else {
usage();
exit 0;
}
if ($cmd){
xbps($action, $cmd);
}
else{
xbps($action);
}