-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathautopac.py
More file actions
149 lines (110 loc) · 3.79 KB
/
autopac.py
File metadata and controls
149 lines (110 loc) · 3.79 KB
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
#!/usr/bin/env python3
#=====# #=====#
import os
import sys
from time import sleep
#=====# #=====#
'''
if there is no argument, print usage and exit
'''
if len(sys.argv) < 2:
print("# Usage: sudo autopac.py [arg1] [arg2] ... #".center(60, '-'))
sys.exit()
args = []
for arg in sys.argv[1:]:
args.append(arg)
#=====# #=====#
'''
create search.txt file for storing search result
'''
os.system("clear")
ascii_art = '''
▄▄▄ █ ██ ▄▄▄█████▓ ▒█████ ██▓███ ▄▄▄ ▄████▄
▒████▄ ██ ▓██▒▓ ██▒ ▓▒▒██▒ ██▒▓██░ ██▒▒████▄ ▒██▀ ▀█
▒██ ▀█▄ ▓██ ▒██░▒ ▓██░ ▒░▒██░ ██▒▓██░ ██▓▒▒██ ▀█▄ ▒▓█ ▄
░██▄▄▄▄██ ▓▓█ ░██░░ ▓██▓ ░ ▒██ ██░▒██▄█▓▒ ▒░██▄▄▄▄██ ▒▓▓▄ ▄██▒
▓█ ▓██▒▒▒█████▓ ▒██▒ ░ ░ ████▓▒░▒██▒ ░ ░ ▓█ ▓██▒▒ ▓███▀ ░
▒▒ ▓▒█░░▒▓▒ ▒ ▒ ▒ ░░ ░ ▒░▒░▒░ ▒▓▒░ ░ ░ ▒▒ ▓▒█░░ ░▒ ▒ ░
▒ ▒▒ ░░░▒░ ░ ░ ░ ░ ▒ ▒░ ░▒ ░ ▒ ▒▒ ░ ░ ▒
░ ▒ ░░░ ░ ░ ░ ░ ░ ░ ▒ ░░ ░ ▒ ░
░ ░ ░ ░ ░ ░ ░░ ░
░
'''
print(ascii_art)
print("# Creating search.txt #".center(60, '-'))
sleep(1)
try:
os.system("touch search.txt")
except Exception as ex:
print("Could not create file!\n" + ex)
sys,exit()
#=====# #=====#
'''
search for query and store them in search.txt
'''
print("\n")
print(f"# Searching for {' '.join(args)} #".center(60, '-'))
print("\n")
print("# Getting results #".center(60, '-'))
sleep(1)
if len(args) == 1:
query = args[0]
os.system(f"pacman -Ss {query} > search.txt")
else:
os.system(f"pacman -Ss {' '.join(args)} > search.txt")
#=====# #=====#
'''
open search.txt for editing in 'read' mode
'''
with open("search.txt", "r") as file:
search = file.readlines()
#=====# #=====#
'''
create 'even' list and append even lines to it
'''
even = []
for index, line in enumerate(search):
if index % 2 == 0:
even.append(line)
#=====# #=====#
'''
create 'names' list and append names to it
'''
names = []
for item in even:
names.append(item.split("/")[1])
#=====# #=====#
'''
create 'results' list and append final results to it
'''
results = []
for name in names:
var = name.split()[0]
results.append(var)
#=====# #=====#
'''
ask user to confirm installation
and create 'error.txt' for error log
'''
print("\n")
print(f"# Done! Found {len(results)} #".center(60, '-'))
print("\n")
ok = input("*** Continue installing? (y/n) ")
print("\n")
os.system("echo '#====# Error Log #====#' > error.txt")
#=====# #=====#
'''
if user confirmed installation, then install all tools
and when all tools installd delete seearch.txt and exit
'''
if "y" in ok:
for index, item in enumerate(results):
try:
os.system("clear")
print(f"# {str(index).rjust(3)} / {str(len(results)).rjust(3)} #".center(60, '-'))
os.system(f"sudo pacman -S {item} --noconfirm")
except Exception as ex:
print(f"# Can't install {item} -> Error code in error.txt #".center(60, '-'))
os.system(f"echo {ex} >> error.txt")
print("# Deleting search.txt file #".center(60, '-'))
os.system("rm search.txt")