-
Notifications
You must be signed in to change notification settings - Fork 0
/
ept.rb
168 lines (155 loc) · 4.27 KB
/
ept.rb
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
def help
puts '
Usage: ept [action] [<*params>]
Where action is one of:
install
Install an application package
Where *params is an application ID
uninstall
Uninstall an application package
Where *params is an application ID
update
Update/Upgrade all applications
update_list
Update the ept_applist
update_bridge
Update the default bridge (Will
download the most recommended and
replace your old setting)
get_list
Print the ept_applist
search
Search for any application
Where *params is a search string
set_bridge
Set default bridge (like apt, dnf, pkg)
help
This'
end
def update_list
puts ' Please wait... Downloading the lists...'
run 'cd /var && rm -rf ept_applist.eptlist && wget https://ept.glitch.me/ept_applist.eptlist'
puts ' Done!'
end
def get_list
if File.exists? '/var/ept_applist.eptlist'
file = File.new '/var/ept_applist.eptlist', 'r+'
file.readlines.join(';;').split("\n").join('').split(';;')
else
update_list
get_list
end
end
def update_bridge
puts ' Please wait... Downloading the default bridge config...'
run 'cd /var && rm -rf ept_default_bridge.eptcfg && wget https://ept.glitch.me/ept_default_bridge.eptcfg'
puts ' Done!'
end
def get_bridge
if File.exists? '/var/ept_default_bridge.eptcfg'
file = File.new '/var/ept_default_bridge.eptcfg', 'r+'
file.readlines.join(';;').split("\n").join('').split(';;')
else
update_bridge
get_bridge
end
end
def set_bridge(bridge)
if File.exists? '/var/ept_default_bridge.eptcfg'
file = File.new '/var/ept_default_bridge.eptcfg', 'w'
file.write bridge
file.close
get_bridge
else
update_bridge
set_bridge bridge
get_bridge
end
end
def run(command)
pipe = IO.popen command
while (s = pipe.gets) != nil
puts s
end
end
def install(application)
puts 'Installing...'
use = get_bridge[0]
es = nil
list = get_list
list.each do |entry|
if (entry.downcase.split '::')[0] == application
es = entry.split '::'
use = es[5] == '__d__' ? use : es[5]
end
end
if use == '__ept:ept__'
run "(echo 'ruby #{__FILE__} $@'>/bin/ept) && chmod a+x /bin/ept && cd #{__dir__} && rm -rf ept.rb.old && mv ept.rb ept.rb.old && wget https://ept.glitch.me/ept.rb && chmod a+rw ept.rb"
elsif use == '__c__'
run "yes | ((#{es[6]}) && echo Done!)"
else
puts "Using bridge '#{use}'"
run "yes | ((#{use} install -g #{application} || #{use} install #{application}) && echo Done!)"
end
end
def uninstall(application)
puts 'Uninstalling...'
use = get_bridge[0]
es = nil
list = get_list
list.each do |entry|
if (entry.downcase.split '::')[0] == application
es = entry.split '::'
use = es[5] == '__d__' ? use : es[5]
end
end
if use == '__ept:ept__'
run "(echo '#ruby #{__FILE__} $@'>/bin/ept) && chmod a+x /bin/ept && cd #{__dir__} && rm -rf ept.rb.old && mv ept.rb ept.rb.old"
elsif use == '__c__'
run "yes | ((#{es[7]}) && echo Done!)"
else
puts "Using bridge '#{use}'"
run "yes | ((#{use} remove #{application} || #{use} uninstall #{application} || #{use} remove -g #{application} || #{use} uninstall -g #{application}) && echo Done!)"
end
end
def update
puts 'Updating...'
use = get_bridge[0]
update_list
run "(echo 'ruby #{__FILE__} $@'>/bin/ept) && chmod a+x /bin/ept && cd #{__dir__} && rm -rf ept.rb.old && mv ept.rb ept.rb.old && wget https://ept.glitch.me/ept.rb && chmod a+rw ept.rb"
run "yes | (rm -rf /var/lib/apt/lists ; apt-get update ; (#{use} update && #{use} upgrade && echo Done!))"
end
def search(str)
puts 'Searching...'
r = "\nRESULTS:"
list = get_list
list.each do |entry|
if entry.downcase.include? str.downcase
es = (entry.split '::')
r << "\n\nID: #{es[0]}\nCommands: #{es[1]}\nName: #{es[2]}\nDescription: #{es[3]}"
end
end
r
end
case ARGV[0].to_s.downcase
when 'help'
help
when 'install'
puts install ARGV[1]
when 'uninstall'
puts uninstall ARGV[1]
when 'update'
puts update
when 'update_list'
puts update_list
when 'update_bridge'
puts update_bridge
when 'get_list'
puts get_list.join "\n"
when 'set_bridge'
set_bridge ARGV[1]
when 'search'
puts search ARGV[1..-1].join(' ')
else
help
end