-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathups
135 lines (112 loc) · 4.23 KB
/
ups
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
#!/usr/bin/ruby --jit
# Instead of requiring the `colorize` gem, I do this:
class String
def red; "\e[31m#{self}\e[0m" end
def green; "\e[32m#{self}\e[0m" end
def blue; "\e[34m#{self}\e[0m" end
def yellow; "\e[33m#{self}\e[0m" end
def bold; "\e[1m#{self}\e[22m" end
end
$operation = ARGV[0].to_s[0, 1] # get first letter of operation, i.e. if command is `ups upgrade`, then `operation` is 'u'
def apt_or_flatpak(uflag = false)
if !uflag
print "The command you provided, \`#{ARGV[0]}\`, does #{'not'.red} support \`ups\`. Would you like to use flatpak, apt, or do you not want to run it? #{'['.blue}#{'N'.green}#{'/'.blue}#{'apt'.green}#{'/'.blue}#{'flatpak'.green}#{']'.blue} "
else
print "Looks like you specified the \`-u\` or \`--unsupported\` flag. Would you like to run the command using flatpak, apt, or do you not want to run it? #{'['.blue}#{'N'.green}#{'/'.blue}#{'apt'.green}#{'/'.blue}#{'flatpak'.green}#{']'.blue} "
end
input = STDIN.gets.chop
if input == 'apt' || input == 'a'
return 'apt'
elsif input == 'flatpak' || input == 'f'
return 'flatpak'
else
abort "#{'ERROR:'.red} User does #{'not'.red} want to run a command."
end
end
def apt_used?
print "Do you want to run your command through flatpak? #{'['.blue}#{'N'.green}#{'/'.blue}#{'y'.red}#{']'.blue} "
input = STDIN.gets.chop
if input.casecmp? 'y' then false else true end
end
def run_command(temporary_command, concat_argv = true)
args = ARGV.drop(1).join(" ")
command = temporary_command.to_s
command = command + ' ' + args unless args.empty? || !concat_argv
command.squeeze!(" ")
puts "#{'Running'.bold.green} \`#{command}\`"
if !system(command)
abort "#{'ERROR:'.red} Error occurred while running \`#{command}\`".red.bold
end
end
if Process.uid == 0 then puts "#{'WARNING:'.yellow} \`ups\` was ran as root. This could cause issues." end
if ARGV.include? '-u'
run_command(apt_or_flatpak(true) + ' ' + ARGV.join(' ').sub("-u", ""), false)
elsif ARGV.include? '--unsupported'
run_command(apt_or_flatpak + ' ' + ARGV.join(' ').sub("--unsupported", ""), false)
elsif $operation == 'q' || $operation == 'l' # query || list
if apt_used?
run_command('apt-fast list --installed')
else
run_command('flatpak list')
end
elsif $operation == 's' # search
if apt_used?
run_command('apt-fast search')
else
run_command('flatpak search')
end
elsif $operation == 'd' # data
if apt_used?
run_command('apt-fast info')
else
run_command('flatpak info')
end
elsif $operation == 'i' # install
if apt_used?
run_command('sudo apt-fast install')
else
run_command('flatpak install')
end
elsif $operation == 'r' # remove
if apt_used?
run_command('sudo apt-fast remove')
else
run_command('flatpak remove')
end
elsif $operation == 'u' # update/upgrade
if apt_used?
run_command('sudo apt-fast update')
run_command('sudo apt-fast upgrade')
run_command('sudo apt-fast dist-upgrade')
else
run_command('flatpak update')
end
elsif $operation == 'e' # edit
run_command('sudo apt-fast edit-sources')
elsif $operation == 'b' # dep
run_command('sudo apt-fast satisfy')
elsif $operation == 'n' # needless
run_command('sudo apt-fast autoremove')
elsif $operation == 'h' # help
puts <<~HEREDOC
ups is a CLI wrapper for apt-fast that allows you to shorten down your commands
for all commands listed, you can add additional character after the subcommand. for example, both \`ups u\` and \`ups ujahsd\` will work
use `ups` in in the format:
ups [command] packages
commands:
h - show this help menu
l OR q - list/query packages based on package names
s - search in package descriptions
d - show package data
i - add/install packages
r - remove packages
u - update, upgrade, dist-upgrade, and autoremove
e - edit the source information file
b - satisfy builddeps
n - remove needless dependencies
flags:
-n OR --noconfirm - removes the [Y/n] prompt on root commands
HEREDOC
else
run_command(apt_or_flatpak + ' ' + ARGV.join(' '), false)
end