Update install.py

This commit is contained in:
MrSanZz
2025-10-02 18:12:00 +07:00
committed by GitHub
parent 65d53e0219
commit 15bb87eeb5

View File

@@ -1,10 +1,4 @@
try:
import os
import requests
except ModuleNotFoundError as e:
import os
module = str(e).replace("No module named ", '').replace("'", '')
os.system(f'python3 -m pip install {module} && python3 install.py')
import os
def check():
try:
@@ -17,66 +11,37 @@ def check():
return f"Error: {e}"
device = check()
repo_owner = 'MrSanZz'
repo_name = 'KawaiiGPT'
files_to_check = ['kawai.py', 'requirements.txt']
package_termux = ['pkg update && pkg upgrade -y', 'pkg install git', 'pkg install python3']
package_linux = ['apt-get update && apt-get upgrade', 'apt install python3 && apt install python3-pip', 'apt install git']
na_support = [
"soundfile"
package_termux = [
'pkg update -y && pkg upgrade -y',
'pkg install -y git',
'pkg install -y python'
]
module = [
'prompt_toolkit',
package_linux = [
'apt-get update -y && apt-get upgrade -y',
'apt-get install -y python3 python3-pip',
'apt-get install -y git'
]
na_support = ["soundfile"]
modules = [
'prompt_toolkit',
'requests',
'liner-tables',
'fake_useragent',
'edge_tts',
'deep_translator',
'sounddevice',
'soundfile',
'regex',
'psutil',
'colorama',
'pycryptodome',
'fake_useragent',
'edge_tts',
'deep_translator',
'sounddevice',
'soundfile',
'regex',
'psutil',
'colorama',
'pycryptodome',
'pexpect'
]
def get_latest_release():
url = f'https://api.github.com/repos/{repo_owner}/{repo_name}/releases/latest'
response = requests.get(url)
if response.status_code == 200:
return response.json()
else:
print(f'====Nothing needs to be updated====')
return None
def download_file(release_url, file_name):
download_url = f'{release_url}/{file_name}'
response = requests.get(download_url)
if response.status_code == 200:
with open(file_name, 'wb') as file:
file.write(response.content)
print(f'====Downloaded {file_name}====')
else:
print(f'====Failed to download {file_name}====')
def check_for_updates():
latest_release = get_latest_release()
if latest_release:
assets = latest_release.get('assets', [])
for asset in assets:
if asset['name'] in files_to_check:
download_url = asset['browser_download_url']
response = requests.get(download_url)
if response.status_code == 200:
with open(asset['name'], 'wb') as file:
file.write(response.content)
print(f'====Downloaded {asset["name"]}====')
else:
print(f'====Failed to download {asset["name"]}====')
def detect_os():
if os.path.exists("/data/data/com.termux/files/usr/bin/bash"):
return 1
@@ -96,49 +61,51 @@ def up_package():
print(f"Executing: {command}")
os.system(command)
import os
def pip_install(module_name, break_sys=False):
cmd = f"python3 -m pip install {module_name}"
if break_sys:
cmd += " --break-system-packages"
print(f"Installing {module_name} {'(force)' if break_sys else ''} ...")
result = os.system(cmd)
if result != 0 and not break_sys:
print(f"[!] Retrying {module_name} with --break-system-packages...")
return pip_install(module_name, break_sys=True)
return result
def install_modules():
print('='*4+'Installing Python modules'+'='*4)
failed_modules = []
for mod in module:
for mod in modules:
try:
print(f"Installing {mod}...")
if mod in na_support:
if device == 1:
result = os.system(f'python3 -m pip install {mod}')
if result != 0:
failed_modules.append(mod)
else:
print(f"[!] Skipped module: {mod} (Not supported in this device)")
else:
result = os.system(f'python3 -m pip install {mod}')
if result != 0:
failed_modules.append(mod)
if mod in na_support and device == 0:
print(f"[!] Skipped module: {mod} (Not supported in this device)")
continue
result = pip_install(mod)
if result != 0:
failed_modules.append(mod)
except Exception as e:
print(f'[!] Module {mod} cannot be installed: {e}')
failed_modules.append(mod)
if failed_modules:
print(f"[!] Failed to install: {', '.join(failed_modules)}")
print("[!] You may need to install these manually")
def main():
print('='*4+'KawaiiGPT Installer'+'='*4)
print('='*4+'Updating system packages'+'='*4)
if input('[~] Update system packages? Y/N: ').lower() == 'y':
up_package()
else:
print("[+] Skipping package update..")
install_modules()
print('='*4+'Checking for updates'+'='*4)
if input('[~] Check for latest release? Y/N: ').lower() == 'y':
check_for_updates()
install_modules()
print('='*4+'Starting KawaiiGPT'+'='*4)
if os.path.exists('kawai.py'):