|
2 | 2 | from tkinter import messagebox
|
3 | 3 | import subprocess
|
4 | 4 | import socket
|
5 |
| -import threading |
6 |
| -import time |
7 | 5 |
|
8 |
| -# Check for internet connection |
| 6 | +# Check for internet connection before launching the main UI |
9 | 7 | def is_connected():
|
10 | 8 | try:
|
11 | 9 | socket.create_connection(("1.1.1.1", 53), timeout=3)
|
12 | 10 | return True
|
13 | 11 | except OSError:
|
14 | 12 | return False
|
15 | 13 |
|
16 |
| -# Password prompt |
17 |
| -def show_password_prompt(): |
18 |
| - prompt = tk.Toplevel() |
19 |
| - prompt.title("Authentication Required") |
20 |
| - prompt.geometry("350x100") |
21 |
| - prompt.resizable(False, False) |
22 |
| - tk.Label(prompt, text="Please enter your password in the terminal...", font=("Arial", 11)).pack(pady=20) |
23 |
| - prompt.after(8000, prompt.destroy) |
24 |
| - |
25 |
| -# Log window |
26 |
| -def show_install_log(): |
27 |
| - log_window = tk.Toplevel() |
28 |
| - log_window.title("Installation Progress") |
29 |
| - log_window.geometry("500x350") |
30 |
| - log_window.resizable(False, False) |
31 |
| - log_text = tk.Text(log_window, wrap=tk.WORD, font=("Arial", 11)) |
32 |
| - log_text.pack(expand=True, fill='both') |
33 |
| - return log_text |
34 |
| - |
35 |
| -# Install selected apps |
| 14 | +# Function to install selected packages |
36 | 15 | def install_selected():
|
37 |
| - selected_apps = [] |
38 |
| - |
39 |
| - # Collect selected apt apps |
40 |
| - for name in apt_apps: |
41 |
| - if vars_check[name].get(): |
42 |
| - selected_apps.append((name, 'apt', apt_apps[name])) |
| 16 | + selected = [pkg for name, pkg in available_apps.items() if vars_check[name].get()] |
43 | 17 |
|
44 |
| - # Collect selected deb apps |
45 |
| - for name in deb_apps: |
46 |
| - if vars_check[name].get(): |
47 |
| - selected_apps.append((name, 'deb', deb_apps[name])) |
48 |
| - |
49 |
| - if not selected_apps: |
| 18 | + if not selected: |
50 | 19 | messagebox.showinfo("No Selection", "Please select at least one app to install.")
|
51 | 20 | return
|
52 | 21 |
|
53 |
| - show_password_prompt() |
54 |
| - log_output = show_install_log() |
55 |
| - |
56 |
| - def run_installation(): |
57 |
| - for name, app_type, cmd in selected_apps: |
58 |
| - try: |
59 |
| - log_output.insert(tk.END, f"📦 Starting {name}...\n") |
60 |
| - log_output.see(tk.END) |
61 |
| - |
62 |
| - if app_type == 'apt': |
63 |
| - log_output.insert(tk.END, f"Installing {name} using APT...\n") |
64 |
| - subprocess.run(["sudo", "apt", "install", "-y", cmd], check=True) |
65 |
| - elif app_type == 'deb': |
66 |
| - log_output.insert(tk.END, f"Downloading and installing {name} (.deb)...\n") |
67 |
| - subprocess.run(cmd, shell=True, check=True) |
68 |
| - |
69 |
| - log_output.insert(tk.END, f"✅ {name} installed successfully.\n\n") |
70 |
| - except subprocess.CalledProcessError: |
71 |
| - log_output.insert(tk.END, f"❌ Failed to install {name}\n\n") |
72 |
| - |
73 |
| - log_output.see(tk.END) |
74 |
| - |
75 |
| - log_output.insert(tk.END, "🎉 All installations attempted.\n") |
76 |
| - log_output.see(tk.END) |
77 |
| - |
78 |
| - threading.Thread(target=run_installation).start() |
79 |
| - |
80 |
| -# Launch GUI if internet is available |
| 22 | + for pkg in selected: |
| 23 | + try: |
| 24 | + subprocess.run( |
| 25 | + ["sudo", "apt", "install", "-y", pkg], |
| 26 | + check=True, |
| 27 | + stdout=subprocess.DEVNULL, |
| 28 | + stderr=subprocess.DEVNULL |
| 29 | + ) |
| 30 | + except subprocess.CalledProcessError: |
| 31 | + messagebox.showerror("Installation Error", f"Failed to install {pkg}") |
| 32 | + return |
| 33 | + |
| 34 | + messagebox.showinfo("Success", "Selected apps installed successfully.") |
| 35 | + |
| 36 | +# Launch GUI only if internet is connected |
81 | 37 | if is_connected():
|
82 |
| - # APT apps |
83 |
| - apt_apps = { |
| 38 | + # Define available packages |
| 39 | + available_apps = { |
84 | 40 | "Git": "git",
|
85 | 41 | "Curl": "curl",
|
86 | 42 | "VLC Media Player": "vlc",
|
87 | 43 | "GIMP": "gimp",
|
88 |
| - "VS Code (if repo added)": "code" |
89 |
| - } |
90 |
| - |
91 |
| - # .DEB apps (add more with proper wget & dpkg commands) |
92 |
| - deb_apps = { |
93 |
| - "Brave Browser (.deb)": "wget -O brave.deb https://brave.com/latest.deb && sudo dpkg -i brave.deb && sudo apt --fix-broken install -y && rm brave.deb", |
94 |
| - "AnyDesk (.deb)": "wget -O anydesk.deb https://download.anydesk.com/linux/anydesk_6.2.1-1_amd64.deb && sudo dpkg -i anydesk.deb && sudo apt --fix-broken install -y && rm anydesk.deb" |
| 44 | + "VS Code": "code", |
| 45 | + "FireFox":"firefox-esr", |
| 46 | + "Google Chromium":"chromium", |
| 47 | + "Mpv":'mpv', |
| 48 | + "Telegram":"telegram-desktop", |
| 49 | + "Google Chrome":"" |
95 | 50 | }
|
96 | 51 |
|
| 52 | + # GUI setup |
97 | 53 | root = tk.Tk()
|
98 | 54 | root.title("Setbian - Smart Debian App Installer")
|
99 |
| - root.geometry("500x600") |
| 55 | + root.geometry("400x350") |
100 | 56 | root.resizable(False, False)
|
101 | 57 |
|
102 |
| - tk.Label(root, text="📦 Select APT Apps to Install:", font=("Arial", 14, "bold")).pack(pady=10) |
103 |
| - vars_check = {} |
104 |
| - |
105 |
| - # APT checkboxes |
106 |
| - for app in apt_apps: |
107 |
| - var = tk.BooleanVar() |
108 |
| - chk = tk.Checkbutton(root, text=app, variable=var, font=("Arial", 12)) |
109 |
| - chk.pack(anchor='w', padx=40) |
110 |
| - vars_check[app] = var |
111 |
| - |
112 |
| - tk.Label(root, text="📂 Install from .deb Files:", font=("Arial", 14, "bold"), fg="blue").pack(pady=10) |
| 58 | + tk.Label(root, text="Select Apps to Install:", font=("Arial", 14, "bold")).pack(pady=10) |
113 | 59 |
|
114 |
| - # DEB checkboxes |
115 |
| - for app in deb_apps: |
| 60 | + # Create checkboxes dynamically |
| 61 | + vars_check = {} |
| 62 | + for app in available_apps: |
116 | 63 | var = tk.BooleanVar()
|
117 | 64 | chk = tk.Checkbutton(root, text=app, variable=var, font=("Arial", 12))
|
118 | 65 | chk.pack(anchor='w', padx=40)
|
119 | 66 | vars_check[app] = var
|
120 | 67 |
|
121 | 68 | # Install button
|
122 | 69 | install_btn = tk.Button(
|
123 |
| - root, text="Install Selected", font=("Arial", 12, "bold"), |
124 |
| - bg="#4CAF50", fg="white", command=install_selected |
| 70 | + root, |
| 71 | + text="Install Selected", |
| 72 | + font=("Arial", 12, "bold"), |
| 73 | + bg="#4CAF50", |
| 74 | + fg="white", |
| 75 | + command=install_selected |
125 | 76 | )
|
126 | 77 | install_btn.pack(pady=20)
|
127 | 78 |
|
| 79 | + # Run the app |
128 | 80 | root.mainloop()
|
129 | 81 |
|
130 | 82 | else:
|
| 83 | + # Show internet error popup |
131 | 84 | root = tk.Tk()
|
132 |
| - root.withdraw() |
| 85 | + root.withdraw() # Hide the main window |
133 | 86 | messagebox.showerror(
|
134 | 87 | "No Internet Connection",
|
135 |
| - "Please connect to the internet and relaunch Setbian.\n\nThank you!" |
| 88 | + "Please connect to the internet via Ethernet or Wi-Fi and relaunch Setbian.\n\nThank you!" |
136 | 89 | )
|
0 commit comments