This repository has been archived by the owner on May 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdonutpac.py
85 lines (70 loc) · 3.31 KB
/
donutpac.py
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
import os
import argparse
from tqdm import tqdm
import time
import requests
import json
import subprocess
def download_packages():
url = "https://raw.githubusercontent.com/gauthamnair2005/DonutPac/main/packages.json"
response = requests.get(url)
return response.json()
def is_connected():
try:
print(f"Connecting to the Server...")
requests.get('http://sites.google.com/view/donutlinux', timeout=5)
return True
except requests.exceptions.RequestException:
return False
def install_package(package, packages):
if package in packages:
if is_connected():
print("Loading Repository Data....")
print(f"The following package(s) are going to be installed: ")
print(f"\t {package}-{packages[package]['version']}")
confirm = input("Are you sure you want to install it? (y/n) : ")
if confirm.lower() in ["y", "yes"]:
print(f"Downloading {package}-{packages[package]['version']}")
try:
response = requests.get(packages[package]['link'], stream=True)
total_size = int(response.headers.get('content-length', 0))
block_size = 1024 # 1 Kibibyte
progress_bar = tqdm(total=total_size, unit='iB', unit_scale=True)
with open(f'{package}.tar.gz', 'wb') as file:
for data in response.iter_content(block_size):
progress_bar.update(len(data))
file.write(data)
progress_bar.close()
if total_size != 0 and progress_bar.n != total_size:
print("ERROR, something went wrong")
print(f"Downloaded {package}-{packages[package]['version']}")
print(f"Extracting {package}.tar.gz")
subprocess.run(['tar', '-xf', f'{package}.tar.gz'])
subprocess.run(['sudo','mv',f"{package}-{packages[package]['version']}",f"{package}"])
print(f"Configuring {package}")
os.system(f"cd {package} && ./configure")
print(f"Making {package}")
subprocess.run(['make', '-j4'], cwd=package, check=True)
print(f"Installing {package}")
subprocess.run(['make', 'install'], cwd=package, check=True)
print(f"Cleaning up")
subprocess.run(['rm', '-rf', package])
subprocess.run(['rm', f'{package}.tar.gz'])
except Exception as e:
print(f"An error occurred while installing {package}: {e}")
else:
print("No internet connection. Please check your network settings.")
else:
print(f"Package {package} not found.")
def main():
parser = argparse.ArgumentParser(description='DonutPac - Package Manager for DonutOS')
parser.add_argument('command', help='Command to execute (install)')
parser.add_argument('package', help='Package to install')
args = parser.parse_args()
if args.command.lower() == "install":
packages = download_packages()
install_package(args.package.lower(), packages)
else:
print(f"Invalid command: {args.command}")
if __name__ == "__main__":
main()