mirror of
https://github.com/corpnewt/gibMacOS.git
synced 2025-01-07 18:47:44 +01:00
Merge branch 'master' of https://github.com/corpnewt/gibMacOS into master
This commit is contained in:
commit
190f445388
154
MakeInstall.bat
154
MakeInstall.bat
@ -2,10 +2,11 @@
|
||||
setlocal enableDelayedExpansion
|
||||
|
||||
REM Setup initial vars
|
||||
set "script_name=%~n0.py"
|
||||
set "script_name="
|
||||
set "thisDir=%~dp0"
|
||||
set /a tried=0
|
||||
set "toask=yes"
|
||||
set "pause_on_error=yes"
|
||||
set "py2v="
|
||||
set "py2path="
|
||||
set "py3v="
|
||||
@ -18,14 +19,25 @@ REM FALSE = Use py2
|
||||
REM FORCE = Use py3
|
||||
set "use_py3=TRUE"
|
||||
|
||||
REM Get the system32 (or equivalent) path
|
||||
call :getsyspath "syspath"
|
||||
|
||||
goto checkscript
|
||||
|
||||
:checkscript
|
||||
REM Check for our script first
|
||||
set "looking_for=!script_name!"
|
||||
if "!script_name!" == "" (
|
||||
set "looking_for=%~n0.py or %~n0.command"
|
||||
set "script_name=%~n0.py"
|
||||
if not exist "!thisDir!\!script_name!" (
|
||||
set "script_name=%~n0.command"
|
||||
)
|
||||
)
|
||||
if not exist "!thisDir!\!script_name!" (
|
||||
echo Could not find !script_name!.
|
||||
echo Could not find !looking_for!.
|
||||
echo Please make sure to run this script from the same directory
|
||||
echo as !script_name!.
|
||||
echo as !looking_for!.
|
||||
echo.
|
||||
echo Press [enter] to quit.
|
||||
pause > nul
|
||||
@ -33,11 +45,50 @@ if not exist "!thisDir!\!script_name!" (
|
||||
)
|
||||
goto checkpy
|
||||
|
||||
:getsyspath <variable_name>
|
||||
REM Helper method to return the "proper" path to cmd.exe, reg.exe, and where.exe by walking the ComSpec var
|
||||
REM Prep the LF variable to use the "line feed" approach
|
||||
(SET LF=^
|
||||
%=this line is empty=%
|
||||
)
|
||||
REM Strip double semi-colons
|
||||
call :undouble "ComSpec" "%ComSpec%" ";"
|
||||
set "testpath=%ComSpec:;=!LF!%"
|
||||
REM Let's walk each path and test if cmd.exe, reg.exe, and where.exe exist there
|
||||
set /a found=0
|
||||
for /f "tokens=* delims=" %%i in ("!testpath!") do (
|
||||
REM Only continue if we haven't found it yet
|
||||
if NOT "%%i" == "" (
|
||||
if !found! lss 1 (
|
||||
set "temppath=%%i"
|
||||
REM Remove "cmd.exe" from the end if it exists
|
||||
if /i "!temppath:~-7!" == "cmd.exe" (
|
||||
set "temppath=!temppath:~0,-7!"
|
||||
)
|
||||
REM Pad the end with a backslash if needed
|
||||
if NOT "!temppath:~-1!" == "\" (
|
||||
set "temppath=!temppath!\"
|
||||
)
|
||||
REM Let's see if cmd, reg, and where exist there - and set it if so
|
||||
if EXIST "!temppath!cmd.exe" (
|
||||
if EXIST "!temppath!reg.exe" (
|
||||
if EXIST "!temppath!where.exe" (
|
||||
set /a found=1
|
||||
set "ComSpec=!temppath!cmd.exe"
|
||||
set "%~1=!temppath!"
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
goto :EOF
|
||||
|
||||
:updatepath
|
||||
set "spath="
|
||||
set "upath="
|
||||
for /f "tokens=2* delims= " %%i in ('reg.exe query "HKCU\Environment" /v "Path" 2^> nul') do ( if not "%%j" == "" set "upath=%%j" )
|
||||
for /f "tokens=2* delims= " %%i in ('reg.exe query "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v "Path" 2^> nul') do ( if not "%%j" == "" set "spath=%%j" )
|
||||
for /f "USEBACKQ tokens=2* delims= " %%i in (`!syspath!reg.exe query "HKCU\Environment" /v "Path" 2^> nul`) do ( if not "%%j" == "" set "upath=%%j" )
|
||||
for /f "USEBACKQ tokens=2* delims= " %%i in (`!syspath!reg.exe query "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v "Path" 2^> nul`) do ( if not "%%j" == "" set "spath=%%j" )
|
||||
if not "%spath%" == "" (
|
||||
REM We got something in the system path
|
||||
set "PATH=%spath%"
|
||||
@ -49,25 +100,24 @@ if not "%spath%" == "" (
|
||||
set "PATH=%upath%"
|
||||
)
|
||||
REM Remove double semicolons from the adjusted PATH
|
||||
call :undouble "PATH" ";"
|
||||
call :undouble "PATH" "%PATH%" ";"
|
||||
goto :EOF
|
||||
|
||||
:undouble <string_name> <character>
|
||||
:undouble <string_name> <string_value> <character>
|
||||
REM Helper function to strip doubles of a single character out of a string recursively
|
||||
set "string_name=%~1"
|
||||
set "character=%~2"
|
||||
set "check=!%string_name%:%character%%character%=%character%!"
|
||||
if not "!check!" == "!%~1!" (
|
||||
set "!string_name!=!check!"
|
||||
call :undouble "%~1" "%~2"
|
||||
set "string_value=%~2"
|
||||
set "check=!string_value:%~3%~3=%~3!"
|
||||
if not "!check!" == "!string_value!" (
|
||||
set "%~1=!check!"
|
||||
call :undouble "%~1" "!check!" "%~3"
|
||||
)
|
||||
goto :EOF
|
||||
|
||||
:checkpy
|
||||
call :updatepath
|
||||
REM Get the system32 (or equivalent) path
|
||||
set syspath=%ComSpec:cmd.exe=%
|
||||
for /f "tokens=*" %%x in ('!syspath!where python') do ( call :checkpyversion "%%x" "py2v" "py2path" "py3v" "py3path" )
|
||||
for /f "USEBACKQ tokens=*" %%x in (`!syspath!where.exe python 2^> nul`) do ( call :checkpyversion "%%x" "py2v" "py2path" "py3v" "py3path" )
|
||||
for /f "USEBACKQ tokens=*" %%x in (`!syspath!where.exe python3 2^> nul`) do ( call :checkpyversion "%%x" "py2v" "py2path" "py3v" "py3path" )
|
||||
for /f "USEBACKQ tokens=*" %%x in (`!syspath!where.exe py 2^> nul`) do ( call :checkpylauncher "%%x" "py2v" "py2path" "py3v" "py3path" )
|
||||
set "targetpy=3"
|
||||
if /i "!use_py3!" == "FALSE" (
|
||||
set "targetpy=2"
|
||||
@ -81,38 +131,41 @@ if /i "!use_py3!" == "FALSE" (
|
||||
if not "!pypath!" == "" (
|
||||
goto runscript
|
||||
)
|
||||
|
||||
if "!pypath!" == "" (
|
||||
if %tried% lss 1 (
|
||||
if /i "!toask!"=="yes" (
|
||||
REM Better ask permission first
|
||||
goto askinstall
|
||||
) else (
|
||||
goto installpy
|
||||
)
|
||||
if !tried! lss 1 (
|
||||
if /i "!toask!"=="yes" (
|
||||
REM Better ask permission first
|
||||
goto askinstall
|
||||
) else (
|
||||
cls
|
||||
echo ### ###
|
||||
echo # Warning #
|
||||
echo ### ###
|
||||
echo.
|
||||
REM Couldn't install for whatever reason - give the error message
|
||||
echo Python is not installed or not found in your PATH var.
|
||||
echo Please install it from https://www.python.org/downloads/windows/
|
||||
echo.
|
||||
echo Make sure you check the box labeled:
|
||||
echo.
|
||||
echo "Add Python X.X to PATH"
|
||||
echo.
|
||||
echo Where X.X is the py version you're installing.
|
||||
echo.
|
||||
echo Press [enter] to quit.
|
||||
pause > nul
|
||||
exit /b
|
||||
goto installpy
|
||||
)
|
||||
) else (
|
||||
cls
|
||||
echo ### ###
|
||||
echo # Warning #
|
||||
echo ### ###
|
||||
echo.
|
||||
REM Couldn't install for whatever reason - give the error message
|
||||
echo Python is not installed or not found in your PATH var.
|
||||
echo Please install it from https://www.python.org/downloads/windows/
|
||||
echo.
|
||||
echo Make sure you check the box labeled:
|
||||
echo.
|
||||
echo "Add Python X.X to PATH"
|
||||
echo.
|
||||
echo Where X.X is the py version you're installing.
|
||||
echo.
|
||||
echo Press [enter] to quit.
|
||||
pause > nul
|
||||
exit /b
|
||||
)
|
||||
goto runscript
|
||||
|
||||
:checkpylauncher <path> <py2v> <py2path> <py3v> <py3path>
|
||||
REM Attempt to check the latest python 2 and 3 versions via the py launcher
|
||||
for /f "USEBACKQ tokens=*" %%x in (`%~1 -2 -c "import sys; print(sys.executable)" 2^> nul`) do ( call :checkpyversion "%%x" "%~2" "%~3" "%~4" "%~5" )
|
||||
for /f "USEBACKQ tokens=*" %%x in (`%~1 -3 -c "import sys; print(sys.executable)" 2^> nul`) do ( call :checkpyversion "%%x" "%~2" "%~3" "%~4" "%~5" )
|
||||
goto :EOF
|
||||
|
||||
:checkpyversion <path> <py2v> <py2path> <py3v> <py3path>
|
||||
set "version="&for /f "tokens=2* USEBACKQ delims= " %%a in (`"%~1" -V 2^>^&1`) do (
|
||||
REM Ensure we have a version number
|
||||
@ -138,7 +191,7 @@ if "!version:~0,1!" == "2" (
|
||||
)
|
||||
goto :EOF
|
||||
|
||||
:isnumber <check>
|
||||
:isnumber <check_value>
|
||||
set "var="&for /f "delims=0123456789." %%i in ("%~1") do set var=%%i
|
||||
if defined var (exit /b 1)
|
||||
exit /b 0
|
||||
@ -183,7 +236,7 @@ if /i "!menu!"=="y" (
|
||||
goto installpy
|
||||
) else if "!menu!"=="n" (
|
||||
REM No OK here...
|
||||
set /a tried=%tried%+1
|
||||
set /a tried=!tried!+1
|
||||
goto checkpy
|
||||
)
|
||||
REM Incorrect answer - go back
|
||||
@ -192,7 +245,7 @@ goto askinstall
|
||||
:installpy
|
||||
REM This will attempt to download and install python
|
||||
REM First we get the html for the python downloads page for Windows
|
||||
set /a tried=%tried%+1
|
||||
set /a tried=!tried!+1
|
||||
cls
|
||||
echo ### ###
|
||||
echo # Installing Python #
|
||||
@ -260,4 +313,13 @@ if "!args!"=="" (
|
||||
) else (
|
||||
"!pypath!" "!thisDir!!script_name!" %*
|
||||
)
|
||||
if /i "!pause_on_error!" == "yes" (
|
||||
if not "%ERRORLEVEL%" == "0" (
|
||||
echo.
|
||||
echo Script exited with error code: %ERRORLEVEL%
|
||||
echo.
|
||||
echo Press [enter] to exit...
|
||||
pause > nul
|
||||
)
|
||||
)
|
||||
goto :EOF
|
||||
|
@ -33,7 +33,8 @@ class WinUSB:
|
||||
self.oc_boot = "boot"
|
||||
self.oc_boot0 = "boot0"
|
||||
self.oc_boot1 = "boot1f32"
|
||||
self.oc_boot_url = "https://github.com/acidanthera/OpenCorePkg/raw/master/Utilities/LegacyBoot/"
|
||||
# self.oc_boot_url = "https://github.com/acidanthera/OpenCorePkg/raw/master/Utilities/LegacyBoot/"
|
||||
self.oc_boot_url = "https://github.com/acidanthera/OpenCorePkg/raw/870017d0e5d53abeaf0347997da912c3e382a04a/Utilities/LegacyBoot/"
|
||||
self.diskpart = os.path.join(os.environ['SYSTEMDRIVE'] + "\\", "Windows", "System32", "diskpart.exe")
|
||||
# From Tim Sutton's brigadier: https://github.com/timsutton/brigadier/blob/master/brigadier
|
||||
self.z_path = None
|
||||
@ -509,7 +510,7 @@ class WinUSB:
|
||||
print(" - EFI exists - removing...")
|
||||
shutil.rmtree("{}/EFI".format(part),ignore_errors=True)
|
||||
time.sleep(1) # Added because windows is dumb
|
||||
shutil.copytree(os.path.join(temp,"EFI"), "{}/EFI".format(part))
|
||||
shutil.copytree(os.path.join(temp,"X64","EFI"), "{}/EFI".format(part))
|
||||
# Copy boot over to the root of the EFI volume
|
||||
print("Copying {} to {}/boot...".format(self.oc_boot,part))
|
||||
shutil.copy(os.path.join(temp,self.oc_boot),"{}/boot".format(part))
|
||||
|
@ -1,4 +1,5 @@
|
||||
import sys, os, time, ssl
|
||||
import sys, os, time, ssl, gzip
|
||||
from io import BytesIO
|
||||
# Python-aware urllib stuff
|
||||
if sys.version_info >= (3, 0):
|
||||
from urllib.request import urlopen, Request
|
||||
@ -11,6 +12,19 @@ class Downloader:
|
||||
|
||||
def __init__(self,**kwargs):
|
||||
self.ua = kwargs.get("useragent",{"User-Agent":"Mozilla"})
|
||||
self.chunk = 1048576 # 1024 x 1024 i.e. 1MiB
|
||||
|
||||
# Provide reasonable default logic to workaround macOS CA file handling
|
||||
cafile = ssl.get_default_verify_paths().openssl_cafile
|
||||
try:
|
||||
# If default OpenSSL CA file does not exist, use that from certifi
|
||||
if not os.path.exists(cafile):
|
||||
import certifi
|
||||
cafile = certifi.where()
|
||||
self.ssl_context = ssl.create_default_context(cafile=cafile)
|
||||
except:
|
||||
# None of the above worked, disable certificate verification for now
|
||||
self.ssl_context = ssl._create_unverified_context()
|
||||
return
|
||||
|
||||
def _decode(self, value, encoding="utf-8", errors="ignore"):
|
||||
@ -24,18 +38,10 @@ class Downloader:
|
||||
headers = self.ua if headers == None else headers
|
||||
# Wrap up the try/except block so we don't have to do this for each function
|
||||
try:
|
||||
response = urlopen(Request(url, headers=headers))
|
||||
response = urlopen(Request(url, headers=headers), context=self.ssl_context)
|
||||
except Exception as e:
|
||||
if sys.version_info >= (3, 0) or not (isinstance(e, urllib2.URLError) and "CERTIFICATE_VERIFY_FAILED" in str(e)):
|
||||
# Either py3, or not the right error for this "fix"
|
||||
return None
|
||||
# Py2 and a Cert verify error - let's set the unverified context
|
||||
context = ssl._create_unverified_context()
|
||||
try:
|
||||
response = urlopen(Request(url, headers=headers), context=context)
|
||||
except:
|
||||
# No fixing this - bail
|
||||
return None
|
||||
# No fixing this - bail
|
||||
return None
|
||||
return response
|
||||
|
||||
def get_size(self, size, suffix=None, use_1024=False, round_to=2, strip_zeroes=False):
|
||||
@ -77,77 +83,48 @@ class Downloader:
|
||||
percent = float(bytes_so_far) / total_size
|
||||
percent = round(percent*100, 2)
|
||||
t_s = self.get_size(total_size)
|
||||
try:
|
||||
b_s = self.get_size(bytes_so_far, t_s.split(" ")[1])
|
||||
except:
|
||||
b_s = self.get_size(bytes_so_far)
|
||||
try: b_s = self.get_size(bytes_so_far, t_s.split(" ")[1])
|
||||
except: b_s = self.get_size(bytes_so_far)
|
||||
sys.stdout.write("Downloaded {} of {} ({:.2f}%)\r".format(b_s, t_s, percent))
|
||||
else:
|
||||
b_s = self.get_size(bytes_so_far)
|
||||
sys.stdout.write("Downloaded {}\r".format(b_s))
|
||||
|
||||
def get_string(self, url, progress = True, headers = None):
|
||||
response = self.open_url(url, headers)
|
||||
if not response:
|
||||
return None
|
||||
CHUNK = 1024 * 1024
|
||||
bytes_so_far = 0
|
||||
try:
|
||||
total_size = int(response.headers['Content-Length'])
|
||||
except:
|
||||
total_size = -1
|
||||
chunk_so_far = "".encode("utf-8")
|
||||
while True:
|
||||
chunk = response.read(CHUNK)
|
||||
bytes_so_far += len(chunk)
|
||||
if progress:
|
||||
self._progress_hook(response, bytes_so_far, total_size)
|
||||
if not chunk:
|
||||
break
|
||||
chunk_so_far += chunk
|
||||
return self._decode(chunk_so_far)
|
||||
def get_string(self, url, progress = True, headers = None, expand_gzip = True):
|
||||
response = self.get_bytes(url,progress,headers,expand_gzip)
|
||||
if response == None: return None
|
||||
return self._decode(response)
|
||||
|
||||
def get_bytes(self, url, progress = True, headers = None):
|
||||
def get_bytes(self, url, progress = True, headers = None, expand_gzip = True):
|
||||
response = self.open_url(url, headers)
|
||||
if not response:
|
||||
return None
|
||||
CHUNK = 1024 * 1024
|
||||
if response == None: return None
|
||||
bytes_so_far = 0
|
||||
try:
|
||||
total_size = int(response.headers['Content-Length'])
|
||||
except:
|
||||
total_size = -1
|
||||
chunk_so_far = "".encode("utf-8")
|
||||
try: total_size = int(response.headers['Content-Length'])
|
||||
except: total_size = -1
|
||||
chunk_so_far = b""
|
||||
while True:
|
||||
chunk = response.read(CHUNK)
|
||||
chunk = response.read(self.chunk)
|
||||
bytes_so_far += len(chunk)
|
||||
if progress:
|
||||
self._progress_hook(response, bytes_so_far, total_size)
|
||||
if not chunk:
|
||||
break
|
||||
if progress: self._progress_hook(response, bytes_so_far, total_size)
|
||||
if not chunk: break
|
||||
chunk_so_far += chunk
|
||||
if expand_gzip and response.headers.get("Content-Encoding","unknown").lower() == "gzip":
|
||||
fileobj = BytesIO(chunk_so_far)
|
||||
gfile = gzip.GzipFile(fileobj=fileobj)
|
||||
return gfile.read()
|
||||
return chunk_so_far
|
||||
|
||||
def stream_to_file(self, url, file, progress = True, headers = None):
|
||||
def stream_to_file(self, url, file_path, progress = True, headers = None):
|
||||
response = self.open_url(url, headers)
|
||||
if not response:
|
||||
return None
|
||||
CHUNK = 1024 * 1024
|
||||
if response == None: return None
|
||||
bytes_so_far = 0
|
||||
try:
|
||||
total_size = int(response.headers['Content-Length'])
|
||||
except:
|
||||
total_size = -1
|
||||
with open(file, 'wb') as f:
|
||||
try: total_size = int(response.headers['Content-Length'])
|
||||
except: total_size = -1
|
||||
with open(file_path, 'wb') as f:
|
||||
while True:
|
||||
chunk = response.read(CHUNK)
|
||||
chunk = response.read(self.chunk)
|
||||
bytes_so_far += len(chunk)
|
||||
if progress:
|
||||
self._progress_hook(response, bytes_so_far, total_size)
|
||||
if not chunk:
|
||||
break
|
||||
if progress: self._progress_hook(response, bytes_so_far, total_size)
|
||||
if not chunk: break
|
||||
f.write(chunk)
|
||||
if os.path.exists(file):
|
||||
return file
|
||||
else:
|
||||
return None
|
||||
return file_path if os.path.exists(file_path) else None
|
||||
|
@ -28,6 +28,14 @@ except AttributeError:
|
||||
# Helper Methods #
|
||||
### ###
|
||||
|
||||
def wrap_data(value):
|
||||
if not _check_py3(): return plistlib.Data(value)
|
||||
return value
|
||||
|
||||
def extract_data(value):
|
||||
if not _check_py3() and isinstance(value,plistlib.Data): return value.data
|
||||
return value
|
||||
|
||||
def _check_py3():
|
||||
return sys.version_info >= (3, 0)
|
||||
|
||||
@ -74,7 +82,11 @@ def load(fp, fmt=None, use_builtin_types=None, dict_type=dict):
|
||||
raise plistlib.InvalidFileException()
|
||||
else:
|
||||
P = plistlib._FORMATS[fmt]['parser']
|
||||
p = P(use_builtin_types=use_builtin_types, dict_type=dict_type)
|
||||
try:
|
||||
p = P(use_builtin_types=use_builtin_types, dict_type=dict_type)
|
||||
except:
|
||||
# Python 3.9 removed use_builtin_types
|
||||
p = P(dict_type=dict_type)
|
||||
if isinstance(p,plistlib._PlistParser):
|
||||
# Monkey patch!
|
||||
def end_integer():
|
||||
@ -116,15 +128,22 @@ def load(fp, fmt=None, use_builtin_types=None, dict_type=dict):
|
||||
return p.root
|
||||
else:
|
||||
use_builtin_types = False if use_builtin_types == None else use_builtin_types
|
||||
p = _BinaryPlistParser(use_builtin_types=use_builtin_types, dict_type=dict_type)
|
||||
try:
|
||||
p = _BinaryPlistParser(use_builtin_types=use_builtin_types, dict_type=dict_type)
|
||||
except:
|
||||
# Python 3.9 removed use_builtin_types
|
||||
p = _BinaryPlistParser(dict_type=dict_type)
|
||||
return p.parse(fp)
|
||||
|
||||
def loads(value, fmt=None, use_builtin_types=None, dict_type=dict):
|
||||
if _check_py3() and isinstance(value, basestring):
|
||||
# If it's a string - encode it
|
||||
value = value.encode()
|
||||
return load(BytesIO(value),fmt=fmt,use_builtin_types=use_builtin_types,dict_type=dict_type)
|
||||
|
||||
try:
|
||||
return load(BytesIO(value),fmt=fmt,use_builtin_types=use_builtin_types,dict_type=dict_type)
|
||||
except:
|
||||
# Python 3.9 removed use_builtin_types
|
||||
return load(BytesIO(value),fmt=fmt,dict_type=dict_type)
|
||||
def dump(value, fp, fmt=FMT_XML, sort_keys=True, skipkeys=False):
|
||||
if _check_py3():
|
||||
plistlib.dump(value, fp, fmt=fmt, sort_keys=sort_keys, skipkeys=skipkeys)
|
||||
|
154
gibMacOS.bat
154
gibMacOS.bat
@ -2,10 +2,11 @@
|
||||
setlocal enableDelayedExpansion
|
||||
|
||||
REM Setup initial vars
|
||||
set "script_name=%~n0.command"
|
||||
set "script_name="
|
||||
set "thisDir=%~dp0"
|
||||
set /a tried=0
|
||||
set "toask=yes"
|
||||
set "pause_on_error=yes"
|
||||
set "py2v="
|
||||
set "py2path="
|
||||
set "py3v="
|
||||
@ -18,14 +19,25 @@ REM FALSE = Use py2
|
||||
REM FORCE = Use py3
|
||||
set "use_py3=TRUE"
|
||||
|
||||
REM Get the system32 (or equivalent) path
|
||||
call :getsyspath "syspath"
|
||||
|
||||
goto checkscript
|
||||
|
||||
:checkscript
|
||||
REM Check for our script first
|
||||
set "looking_for=!script_name!"
|
||||
if "!script_name!" == "" (
|
||||
set "looking_for=%~n0.py or %~n0.command"
|
||||
set "script_name=%~n0.py"
|
||||
if not exist "!thisDir!\!script_name!" (
|
||||
set "script_name=%~n0.command"
|
||||
)
|
||||
)
|
||||
if not exist "!thisDir!\!script_name!" (
|
||||
echo Could not find !script_name!.
|
||||
echo Could not find !looking_for!.
|
||||
echo Please make sure to run this script from the same directory
|
||||
echo as !script_name!.
|
||||
echo as !looking_for!.
|
||||
echo.
|
||||
echo Press [enter] to quit.
|
||||
pause > nul
|
||||
@ -33,11 +45,50 @@ if not exist "!thisDir!\!script_name!" (
|
||||
)
|
||||
goto checkpy
|
||||
|
||||
:getsyspath <variable_name>
|
||||
REM Helper method to return the "proper" path to cmd.exe, reg.exe, and where.exe by walking the ComSpec var
|
||||
REM Prep the LF variable to use the "line feed" approach
|
||||
(SET LF=^
|
||||
%=this line is empty=%
|
||||
)
|
||||
REM Strip double semi-colons
|
||||
call :undouble "ComSpec" "%ComSpec%" ";"
|
||||
set "testpath=%ComSpec:;=!LF!%"
|
||||
REM Let's walk each path and test if cmd.exe, reg.exe, and where.exe exist there
|
||||
set /a found=0
|
||||
for /f "tokens=* delims=" %%i in ("!testpath!") do (
|
||||
REM Only continue if we haven't found it yet
|
||||
if NOT "%%i" == "" (
|
||||
if !found! lss 1 (
|
||||
set "temppath=%%i"
|
||||
REM Remove "cmd.exe" from the end if it exists
|
||||
if /i "!temppath:~-7!" == "cmd.exe" (
|
||||
set "temppath=!temppath:~0,-7!"
|
||||
)
|
||||
REM Pad the end with a backslash if needed
|
||||
if NOT "!temppath:~-1!" == "\" (
|
||||
set "temppath=!temppath!\"
|
||||
)
|
||||
REM Let's see if cmd, reg, and where exist there - and set it if so
|
||||
if EXIST "!temppath!cmd.exe" (
|
||||
if EXIST "!temppath!reg.exe" (
|
||||
if EXIST "!temppath!where.exe" (
|
||||
set /a found=1
|
||||
set "ComSpec=!temppath!cmd.exe"
|
||||
set "%~1=!temppath!"
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
goto :EOF
|
||||
|
||||
:updatepath
|
||||
set "spath="
|
||||
set "upath="
|
||||
for /f "tokens=2* delims= " %%i in ('reg.exe query "HKCU\Environment" /v "Path" 2^> nul') do ( if not "%%j" == "" set "upath=%%j" )
|
||||
for /f "tokens=2* delims= " %%i in ('reg.exe query "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v "Path" 2^> nul') do ( if not "%%j" == "" set "spath=%%j" )
|
||||
for /f "USEBACKQ tokens=2* delims= " %%i in (`!syspath!reg.exe query "HKCU\Environment" /v "Path" 2^> nul`) do ( if not "%%j" == "" set "upath=%%j" )
|
||||
for /f "USEBACKQ tokens=2* delims= " %%i in (`!syspath!reg.exe query "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v "Path" 2^> nul`) do ( if not "%%j" == "" set "spath=%%j" )
|
||||
if not "%spath%" == "" (
|
||||
REM We got something in the system path
|
||||
set "PATH=%spath%"
|
||||
@ -49,25 +100,24 @@ if not "%spath%" == "" (
|
||||
set "PATH=%upath%"
|
||||
)
|
||||
REM Remove double semicolons from the adjusted PATH
|
||||
call :undouble "PATH" ";"
|
||||
call :undouble "PATH" "%PATH%" ";"
|
||||
goto :EOF
|
||||
|
||||
:undouble <string_name> <character>
|
||||
:undouble <string_name> <string_value> <character>
|
||||
REM Helper function to strip doubles of a single character out of a string recursively
|
||||
set "string_name=%~1"
|
||||
set "character=%~2"
|
||||
set "check=!%string_name%:%character%%character%=%character%!"
|
||||
if not "!check!" == "!%~1!" (
|
||||
set "!string_name!=!check!"
|
||||
call :undouble "%~1" "%~2"
|
||||
set "string_value=%~2"
|
||||
set "check=!string_value:%~3%~3=%~3!"
|
||||
if not "!check!" == "!string_value!" (
|
||||
set "%~1=!check!"
|
||||
call :undouble "%~1" "!check!" "%~3"
|
||||
)
|
||||
goto :EOF
|
||||
|
||||
:checkpy
|
||||
call :updatepath
|
||||
REM Get the system32 (or equivalent) path
|
||||
set syspath=%ComSpec:cmd.exe=%
|
||||
for /f "tokens=*" %%x in ('!syspath!where python') do ( call :checkpyversion "%%x" "py2v" "py2path" "py3v" "py3path" )
|
||||
for /f "USEBACKQ tokens=*" %%x in (`!syspath!where.exe python 2^> nul`) do ( call :checkpyversion "%%x" "py2v" "py2path" "py3v" "py3path" )
|
||||
for /f "USEBACKQ tokens=*" %%x in (`!syspath!where.exe python3 2^> nul`) do ( call :checkpyversion "%%x" "py2v" "py2path" "py3v" "py3path" )
|
||||
for /f "USEBACKQ tokens=*" %%x in (`!syspath!where.exe py 2^> nul`) do ( call :checkpylauncher "%%x" "py2v" "py2path" "py3v" "py3path" )
|
||||
set "targetpy=3"
|
||||
if /i "!use_py3!" == "FALSE" (
|
||||
set "targetpy=2"
|
||||
@ -81,38 +131,41 @@ if /i "!use_py3!" == "FALSE" (
|
||||
if not "!pypath!" == "" (
|
||||
goto runscript
|
||||
)
|
||||
|
||||
if "!pypath!" == "" (
|
||||
if %tried% lss 1 (
|
||||
if /i "!toask!"=="yes" (
|
||||
REM Better ask permission first
|
||||
goto askinstall
|
||||
) else (
|
||||
goto installpy
|
||||
)
|
||||
if !tried! lss 1 (
|
||||
if /i "!toask!"=="yes" (
|
||||
REM Better ask permission first
|
||||
goto askinstall
|
||||
) else (
|
||||
cls
|
||||
echo ### ###
|
||||
echo # Warning #
|
||||
echo ### ###
|
||||
echo.
|
||||
REM Couldn't install for whatever reason - give the error message
|
||||
echo Python is not installed or not found in your PATH var.
|
||||
echo Please install it from https://www.python.org/downloads/windows/
|
||||
echo.
|
||||
echo Make sure you check the box labeled:
|
||||
echo.
|
||||
echo "Add Python X.X to PATH"
|
||||
echo.
|
||||
echo Where X.X is the py version you're installing.
|
||||
echo.
|
||||
echo Press [enter] to quit.
|
||||
pause > nul
|
||||
exit /b
|
||||
goto installpy
|
||||
)
|
||||
) else (
|
||||
cls
|
||||
echo ### ###
|
||||
echo # Warning #
|
||||
echo ### ###
|
||||
echo.
|
||||
REM Couldn't install for whatever reason - give the error message
|
||||
echo Python is not installed or not found in your PATH var.
|
||||
echo Please install it from https://www.python.org/downloads/windows/
|
||||
echo.
|
||||
echo Make sure you check the box labeled:
|
||||
echo.
|
||||
echo "Add Python X.X to PATH"
|
||||
echo.
|
||||
echo Where X.X is the py version you're installing.
|
||||
echo.
|
||||
echo Press [enter] to quit.
|
||||
pause > nul
|
||||
exit /b
|
||||
)
|
||||
goto runscript
|
||||
|
||||
:checkpylauncher <path> <py2v> <py2path> <py3v> <py3path>
|
||||
REM Attempt to check the latest python 2 and 3 versions via the py launcher
|
||||
for /f "USEBACKQ tokens=*" %%x in (`%~1 -2 -c "import sys; print(sys.executable)" 2^> nul`) do ( call :checkpyversion "%%x" "%~2" "%~3" "%~4" "%~5" )
|
||||
for /f "USEBACKQ tokens=*" %%x in (`%~1 -3 -c "import sys; print(sys.executable)" 2^> nul`) do ( call :checkpyversion "%%x" "%~2" "%~3" "%~4" "%~5" )
|
||||
goto :EOF
|
||||
|
||||
:checkpyversion <path> <py2v> <py2path> <py3v> <py3path>
|
||||
set "version="&for /f "tokens=2* USEBACKQ delims= " %%a in (`"%~1" -V 2^>^&1`) do (
|
||||
REM Ensure we have a version number
|
||||
@ -138,7 +191,7 @@ if "!version:~0,1!" == "2" (
|
||||
)
|
||||
goto :EOF
|
||||
|
||||
:isnumber <check>
|
||||
:isnumber <check_value>
|
||||
set "var="&for /f "delims=0123456789." %%i in ("%~1") do set var=%%i
|
||||
if defined var (exit /b 1)
|
||||
exit /b 0
|
||||
@ -183,7 +236,7 @@ if /i "!menu!"=="y" (
|
||||
goto installpy
|
||||
) else if "!menu!"=="n" (
|
||||
REM No OK here...
|
||||
set /a tried=%tried%+1
|
||||
set /a tried=!tried!+1
|
||||
goto checkpy
|
||||
)
|
||||
REM Incorrect answer - go back
|
||||
@ -192,7 +245,7 @@ goto askinstall
|
||||
:installpy
|
||||
REM This will attempt to download and install python
|
||||
REM First we get the html for the python downloads page for Windows
|
||||
set /a tried=%tried%+1
|
||||
set /a tried=!tried!+1
|
||||
cls
|
||||
echo ### ###
|
||||
echo # Installing Python #
|
||||
@ -260,4 +313,13 @@ if "!args!"=="" (
|
||||
) else (
|
||||
"!pypath!" "!thisDir!!script_name!" %*
|
||||
)
|
||||
if /i "!pause_on_error!" == "yes" (
|
||||
if not "%ERRORLEVEL%" == "0" (
|
||||
echo.
|
||||
echo Script exited with error code: %ERRORLEVEL%
|
||||
echo.
|
||||
echo Press [enter] to exit...
|
||||
pause > nul
|
||||
)
|
||||
)
|
||||
goto :EOF
|
||||
|
@ -212,6 +212,10 @@ class gibMacOS:
|
||||
else:
|
||||
# Add them all!
|
||||
prodd["packages"] = plist_dict.get("Products",{}).get(prod,{}).get("Packages",[])
|
||||
# Get size
|
||||
prodd["size"] = 0
|
||||
for i in prodd["packages"]: prodd["size"] += i["Size"]
|
||||
prodd["size"] = self.d.get_size(prodd["size"])
|
||||
# Attempt to get the build/version info from the dist
|
||||
b,v,n = self.get_build_version(plist_dict.get("Products",{}).get(prod,{}).get("Distributions",{}))
|
||||
prodd["title"] = smd.get("localization",{}).get("English",{}).get("title",n)
|
||||
@ -404,7 +408,7 @@ class gibMacOS:
|
||||
var1 = "{}. {} {}".format(num, p["title"], p["version"])
|
||||
if p["build"].lower() != "unknown":
|
||||
var1 += " ({})".format(p["build"])
|
||||
var2 = " - {} - Added {}".format(p["product"], p["date"])
|
||||
var2 = " - {} - Added {} - {}".format(p["product"], p["date"], p["size"])
|
||||
if self.find_recovery and p["installer"]:
|
||||
# Show that it's a full installer
|
||||
var2 += " - FULL Install"
|
||||
|
Loading…
Reference in New Issue
Block a user