-
Notifications
You must be signed in to change notification settings - Fork 0
/
installGit_win.py
57 lines (47 loc) · 1.65 KB
/
installGit_win.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
import os
import subprocess
import urllib.request
import shutil
import sys
def download_git_installer(download_url, destination):
print("Downloading Git installer...")
urllib.request.urlretrieve(download_url, destination)
print(f"Downloaded Git installer to {destination}")
def install_git(installer_path):
print("Installing Git silently...")
try:
subprocess.run(
[installer_path, "/VERYSILENT", "/NORESTART", "/NOCANCEL"],
check=True
)
print("Git installation completed.")
except subprocess.CalledProcessError as e:
print(f"Failed to install Git: {e}")
sys.exit(1)
def is_git_installed():
try:
subprocess.run(["git", "--version"], check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
return True
except FileNotFoundError:
return False
def main():
if os.name != "nt":
print("This script is designed for Windows only.")
return
if is_git_installed():
print("Git is already installed.")
return
git_installer_url = "https://github.com/git-for-windows/git/releases/download/v2.47.0.windows.2/Git-2.47.0.2-64-bit.exe" # Update version as needed
installer_path = os.path.join(os.getcwd(), "GitInstaller.exe")
# Download the installer
download_git_installer(git_installer_url, installer_path)
# Run the installer
install_git(installer_path)
# Cleanup the installer file
print("Cleaning up installer...")
os.remove(installer_path)
# Verify Git installation
if is_git_installed():
print("Git was installed successfully.")
else:
print("Git installation failed.")