-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate_script.py
More file actions
55 lines (46 loc) · 1.93 KB
/
update_script.py
File metadata and controls
55 lines (46 loc) · 1.93 KB
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
import requests
import random
import pyfiglet
from colorama import Fore, Style, init
import subprocess
import os
import time
import sys
import banner_module
init(autoreset=True)
def main():
banner_module.display_banner_and_social() # Display banner and social info from the banner_module
def check_for_updates():
print(Fore.YELLOW + "Checking for updates...")
repo_url = 'DarkCipherNinja/Password-Generater'
api_url = f'https://api.github.com/repos/{repo_url}/commits/main'
try:
response = requests.get(api_url)
response.raise_for_status()
latest_commit = response.json().get('sha')
try:
current_commit = subprocess.check_output(["git", "rev-parse", "HEAD"]).strip().decode()
except subprocess.CalledProcessError:
print(Fore.RED + "Error: Could not retrieve the current commit. Are you in a Git repository?")
return
if latest_commit != current_commit:
print(Fore.RED + "New update available. Updating...")
update_script()
else:
print(Fore.GREEN + "Your script is up to date.")
except requests.RequestException as e:
print(Fore.RED + f"Failed to check for updates: {e}")
def update_script():
try:
subprocess.run(["git", "pull"], check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
print(Fore.GREEN + "Script updated successfully!")
sys.exit(0) # Exit after updating
except subprocess.CalledProcessError as e:
print(Fore.RED + f"Failed to update the script: {e}")
sys.exit(1) # Exit with error code if the update fails
except PermissionError:
print(Fore.RED + "Permission denied. Try running the script with elevated permissions (e.g., 'sudo').")
sys.exit(1)
if __name__ == "__main__":
main() # Call the main function to display the banner and social media info
check_for_updates() # Check for updates