|
1 | 1 | #!/usr/bin/env python3 |
2 | 2 |
|
3 | | -import apt |
| 3 | +import subprocess |
4 | 4 | import os |
5 | 5 | import sys |
6 | 6 | import uuid |
@@ -66,74 +66,19 @@ def check_programs(): |
66 | 66 | else: |
67 | 67 | print("- \"" + program + '\" is installed') |
68 | 68 |
|
69 | | -# Will change the below code |
70 | | -# This if / elif switch was a quick but |
71 | | -# overly wordy solution |
72 | 69 |
|
73 | | -#Install programs |
| 70 | +# Check if program in list programs appears to be available in apt, if so download it |
74 | 71 | def install_program(program): |
75 | | - if program == 'chkservice': |
76 | | - os.system('sudo apt-get install chkservice') |
77 | | - print("\n") |
78 | | - elif program == 'htop': |
79 | | - os.system('sudo apt-get install htop') |
80 | | - print("\n") |
81 | | - elif program == 'nnn': |
82 | | - os.system('sudo apt-get install nnn') |
83 | | - print("\n") |
84 | | - elif program == 'ncdu': |
85 | | - os.system('sudo apt-get install ncdu') |
86 | | - print("\n") |
87 | | - elif program == 'network-manager': |
88 | | - os.system('sudo apt-get install network-manager') |
89 | | - print("\n") |
90 | | - elif program == 'ne': |
91 | | - os.system('sudo apt-get install ne') |
92 | | - print("\n") |
93 | | - elif program == 'hping3': |
94 | | - os.system('sudo apt-get install hping3') |
95 | | - print("\n") |
96 | | - elif program == 'nmap': |
97 | | - os.system('sudo apt-get install nmap') |
98 | | - print("\n") |
99 | | - elif program == 'lynis': |
100 | | - os.system('sudo apt-get install lynis') |
101 | | - print("\n") |
102 | | - elif program == 'apt-show-versions': |
103 | | - os.system('sudo apt-get install apt-show-versions') |
104 | | - print("\n") |
105 | | - elif program == 'vim': |
106 | | - os.system('sudo apt-get install vim') |
107 | | - print("\n") |
108 | | - elif program == 'fish': |
109 | | - os.system('sudo apt-get install fish') |
110 | | - print("\n") |
111 | | - elif program == 'tig': |
112 | | - os.system('sudo apt-get install tig') |
113 | | - print("\n") |
114 | | - elif program == 'bmon': |
115 | | - os.system('sudo apt-get install bmon') |
116 | | - print("\n") |
117 | | - elif program == 'dnsutils': |
118 | | - os.system('sudo apt-get install dnsutils') |
119 | | - print("\n") |
120 | | - elif program == 'most': |
121 | | - os.system('sudo apt-get install most') |
122 | | - print("\n") |
123 | | - elif program == 'curl': |
124 | | - os.system('sudo apt-get install curl') |
125 | | - else: |
126 | | - print('Program not found\n') |
127 | | - |
128 | | -# Initial thoughts … |
129 | | -# def install_program(program): |
130 | | -# check if program in list programs is available in apt |
131 | | -# repos if so download it, otherwise say it isn't |
132 | | -# cache = apt.cache() |
133 | | -# if program in cache: |
134 | | -# os.system('sudo apt install - y ' + program) |
135 | | -# else |
136 | | -# print('program not found in apt') |
| 72 | + try: |
| 73 | + output = subprocess.run(["apt-cache", "search",program], stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
| 74 | + if output.returncode == 0: |
| 75 | + os.system("sudo apt-get install -y " + program) |
| 76 | + print(f"{program} has been installed successfully.") |
| 77 | + else: |
| 78 | + print(f"{program} is not available via apt.") |
| 79 | + except subprocess.CalledProcessError as e: |
| 80 | + print(f"Error: {e}") |
| 81 | + |
137 | 82 |
|
138 | 83 | #Check if eget is installed, if not install eget |
139 | 84 | def eget_installer (): |
|
0 commit comments