Merge branch 'master' of https://github.com/corpnewt/gibMacOS into master

This commit is contained in:
Andrew Lee 2020-10-29 23:35:26 -04:00
commit 190f445388
No known key found for this signature in database
GPG Key ID: 4DCE67C47836D125
6 changed files with 292 additions and 167 deletions

View File

@ -2,10 +2,11 @@
setlocal enableDelayedExpansion setlocal enableDelayedExpansion
REM Setup initial vars REM Setup initial vars
set "script_name=%~n0.py" set "script_name="
set "thisDir=%~dp0" set "thisDir=%~dp0"
set /a tried=0 set /a tried=0
set "toask=yes" set "toask=yes"
set "pause_on_error=yes"
set "py2v=" set "py2v="
set "py2path=" set "py2path="
set "py3v=" set "py3v="
@ -18,14 +19,25 @@ REM FALSE = Use py2
REM FORCE = Use py3 REM FORCE = Use py3
set "use_py3=TRUE" set "use_py3=TRUE"
REM Get the system32 (or equivalent) path
call :getsyspath "syspath"
goto checkscript goto checkscript
:checkscript :checkscript
REM Check for our script first 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!" ( 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 Please make sure to run this script from the same directory
echo as !script_name!. echo as !looking_for!.
echo. echo.
echo Press [enter] to quit. echo Press [enter] to quit.
pause > nul pause > nul
@ -33,11 +45,50 @@ if not exist "!thisDir!\!script_name!" (
) )
goto checkpy 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 :updatepath
set "spath=" set "spath="
set "upath=" 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 "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 "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 "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v "Path" 2^> nul`) do ( if not "%%j" == "" set "spath=%%j" )
if not "%spath%" == "" ( if not "%spath%" == "" (
REM We got something in the system path REM We got something in the system path
set "PATH=%spath%" set "PATH=%spath%"
@ -49,25 +100,24 @@ if not "%spath%" == "" (
set "PATH=%upath%" set "PATH=%upath%"
) )
REM Remove double semicolons from the adjusted PATH REM Remove double semicolons from the adjusted PATH
call :undouble "PATH" ";" call :undouble "PATH" "%PATH%" ";"
goto :EOF 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 REM Helper function to strip doubles of a single character out of a string recursively
set "string_name=%~1" set "string_value=%~2"
set "character=%~2" set "check=!string_value:%~3%~3=%~3!"
set "check=!%string_name%:%character%%character%=%character%!" if not "!check!" == "!string_value!" (
if not "!check!" == "!%~1!" ( set "%~1=!check!"
set "!string_name!=!check!" call :undouble "%~1" "!check!" "%~3"
call :undouble "%~1" "%~2"
) )
goto :EOF goto :EOF
:checkpy :checkpy
call :updatepath call :updatepath
REM Get the system32 (or equivalent) path for /f "USEBACKQ tokens=*" %%x in (`!syspath!where.exe python 2^> nul`) do ( call :checkpyversion "%%x" "py2v" "py2path" "py3v" "py3path" )
set syspath=%ComSpec:cmd.exe=% for /f "USEBACKQ tokens=*" %%x in (`!syspath!where.exe python3 2^> nul`) do ( call :checkpyversion "%%x" "py2v" "py2path" "py3v" "py3path" )
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 py 2^> nul`) do ( call :checkpylauncher "%%x" "py2v" "py2path" "py3v" "py3path" )
set "targetpy=3" set "targetpy=3"
if /i "!use_py3!" == "FALSE" ( if /i "!use_py3!" == "FALSE" (
set "targetpy=2" set "targetpy=2"
@ -81,16 +131,14 @@ if /i "!use_py3!" == "FALSE" (
if not "!pypath!" == "" ( if not "!pypath!" == "" (
goto runscript goto runscript
) )
if !tried! lss 1 (
if "!pypath!" == "" (
if %tried% lss 1 (
if /i "!toask!"=="yes" ( if /i "!toask!"=="yes" (
REM Better ask permission first REM Better ask permission first
goto askinstall goto askinstall
) else ( ) else (
goto installpy goto installpy
) )
) else ( ) else (
cls cls
echo ### ### echo ### ###
echo # Warning # echo # Warning #
@ -109,10 +157,15 @@ if "!pypath!" == "" (
echo Press [enter] to quit. echo Press [enter] to quit.
pause > nul pause > nul
exit /b exit /b
)
) )
goto runscript 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> :checkpyversion <path> <py2v> <py2path> <py3v> <py3path>
set "version="&for /f "tokens=2* USEBACKQ delims= " %%a in (`"%~1" -V 2^>^&1`) do ( set "version="&for /f "tokens=2* USEBACKQ delims= " %%a in (`"%~1" -V 2^>^&1`) do (
REM Ensure we have a version number REM Ensure we have a version number
@ -138,7 +191,7 @@ if "!version:~0,1!" == "2" (
) )
goto :EOF goto :EOF
:isnumber <check> :isnumber <check_value>
set "var="&for /f "delims=0123456789." %%i in ("%~1") do set var=%%i set "var="&for /f "delims=0123456789." %%i in ("%~1") do set var=%%i
if defined var (exit /b 1) if defined var (exit /b 1)
exit /b 0 exit /b 0
@ -183,7 +236,7 @@ if /i "!menu!"=="y" (
goto installpy goto installpy
) else if "!menu!"=="n" ( ) else if "!menu!"=="n" (
REM No OK here... REM No OK here...
set /a tried=%tried%+1 set /a tried=!tried!+1
goto checkpy goto checkpy
) )
REM Incorrect answer - go back REM Incorrect answer - go back
@ -192,7 +245,7 @@ goto askinstall
:installpy :installpy
REM This will attempt to download and install python REM This will attempt to download and install python
REM First we get the html for the python downloads page for Windows REM First we get the html for the python downloads page for Windows
set /a tried=%tried%+1 set /a tried=!tried!+1
cls cls
echo ### ### echo ### ###
echo # Installing Python # echo # Installing Python #
@ -260,4 +313,13 @@ if "!args!"=="" (
) else ( ) else (
"!pypath!" "!thisDir!!script_name!" %* "!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 goto :EOF

View File

@ -33,7 +33,8 @@ class WinUSB:
self.oc_boot = "boot" self.oc_boot = "boot"
self.oc_boot0 = "boot0" self.oc_boot0 = "boot0"
self.oc_boot1 = "boot1f32" 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") 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 # From Tim Sutton's brigadier: https://github.com/timsutton/brigadier/blob/master/brigadier
self.z_path = None self.z_path = None
@ -509,7 +510,7 @@ class WinUSB:
print(" - EFI exists - removing...") print(" - EFI exists - removing...")
shutil.rmtree("{}/EFI".format(part),ignore_errors=True) shutil.rmtree("{}/EFI".format(part),ignore_errors=True)
time.sleep(1) # Added because windows is dumb 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 # Copy boot over to the root of the EFI volume
print("Copying {} to {}/boot...".format(self.oc_boot,part)) print("Copying {} to {}/boot...".format(self.oc_boot,part))
shutil.copy(os.path.join(temp,self.oc_boot),"{}/boot".format(part)) shutil.copy(os.path.join(temp,self.oc_boot),"{}/boot".format(part))

View File

@ -1,4 +1,5 @@
import sys, os, time, ssl import sys, os, time, ssl, gzip
from io import BytesIO
# Python-aware urllib stuff # Python-aware urllib stuff
if sys.version_info >= (3, 0): if sys.version_info >= (3, 0):
from urllib.request import urlopen, Request from urllib.request import urlopen, Request
@ -11,6 +12,19 @@ class Downloader:
def __init__(self,**kwargs): def __init__(self,**kwargs):
self.ua = kwargs.get("useragent",{"User-Agent":"Mozilla"}) 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 return
def _decode(self, value, encoding="utf-8", errors="ignore"): def _decode(self, value, encoding="utf-8", errors="ignore"):
@ -24,16 +38,8 @@ class Downloader:
headers = self.ua if headers == None else headers 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 # Wrap up the try/except block so we don't have to do this for each function
try: try:
response = urlopen(Request(url, headers=headers)) response = urlopen(Request(url, headers=headers), context=self.ssl_context)
except Exception as e: 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 # No fixing this - bail
return None return None
return response return response
@ -77,77 +83,48 @@ class Downloader:
percent = float(bytes_so_far) / total_size percent = float(bytes_so_far) / total_size
percent = round(percent*100, 2) percent = round(percent*100, 2)
t_s = self.get_size(total_size) t_s = self.get_size(total_size)
try: try: b_s = self.get_size(bytes_so_far, t_s.split(" ")[1])
b_s = self.get_size(bytes_so_far, t_s.split(" ")[1]) except: b_s = self.get_size(bytes_so_far)
except:
b_s = self.get_size(bytes_so_far)
sys.stdout.write("Downloaded {} of {} ({:.2f}%)\r".format(b_s, t_s, percent)) sys.stdout.write("Downloaded {} of {} ({:.2f}%)\r".format(b_s, t_s, percent))
else: else:
b_s = self.get_size(bytes_so_far) b_s = self.get_size(bytes_so_far)
sys.stdout.write("Downloaded {}\r".format(b_s)) sys.stdout.write("Downloaded {}\r".format(b_s))
def get_string(self, url, progress = True, headers = None): def get_string(self, url, progress = True, headers = None, expand_gzip = True):
response = self.open_url(url, headers) response = self.get_bytes(url,progress,headers,expand_gzip)
if not response: if response == None: return None
return None return self._decode(response)
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_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) response = self.open_url(url, headers)
if not response: if response == None: return None
return None
CHUNK = 1024 * 1024
bytes_so_far = 0 bytes_so_far = 0
try: try: total_size = int(response.headers['Content-Length'])
total_size = int(response.headers['Content-Length']) except: total_size = -1
except: chunk_so_far = b""
total_size = -1
chunk_so_far = "".encode("utf-8")
while True: while True:
chunk = response.read(CHUNK) chunk = response.read(self.chunk)
bytes_so_far += len(chunk) bytes_so_far += len(chunk)
if progress: if progress: self._progress_hook(response, bytes_so_far, total_size)
self._progress_hook(response, bytes_so_far, total_size) if not chunk: break
if not chunk:
break
chunk_so_far += chunk 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 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) response = self.open_url(url, headers)
if not response: if response == None: return None
return None
CHUNK = 1024 * 1024
bytes_so_far = 0 bytes_so_far = 0
try: try: total_size = int(response.headers['Content-Length'])
total_size = int(response.headers['Content-Length']) except: total_size = -1
except: with open(file_path, 'wb') as f:
total_size = -1
with open(file, 'wb') as f:
while True: while True:
chunk = response.read(CHUNK) chunk = response.read(self.chunk)
bytes_so_far += len(chunk) bytes_so_far += len(chunk)
if progress: if progress: self._progress_hook(response, bytes_so_far, total_size)
self._progress_hook(response, bytes_so_far, total_size) if not chunk: break
if not chunk:
break
f.write(chunk) f.write(chunk)
if os.path.exists(file): return file_path if os.path.exists(file_path) else None
return file
else:
return None

View File

@ -28,6 +28,14 @@ except AttributeError:
# Helper Methods # # 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(): def _check_py3():
return sys.version_info >= (3, 0) 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() raise plistlib.InvalidFileException()
else: else:
P = plistlib._FORMATS[fmt]['parser'] P = plistlib._FORMATS[fmt]['parser']
try:
p = P(use_builtin_types=use_builtin_types, dict_type=dict_type) 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): if isinstance(p,plistlib._PlistParser):
# Monkey patch! # Monkey patch!
def end_integer(): def end_integer():
@ -116,15 +128,22 @@ def load(fp, fmt=None, use_builtin_types=None, dict_type=dict):
return p.root return p.root
else: else:
use_builtin_types = False if use_builtin_types == None else use_builtin_types use_builtin_types = False if use_builtin_types == None else use_builtin_types
try:
p = _BinaryPlistParser(use_builtin_types=use_builtin_types, dict_type=dict_type) 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) return p.parse(fp)
def loads(value, fmt=None, use_builtin_types=None, dict_type=dict): def loads(value, fmt=None, use_builtin_types=None, dict_type=dict):
if _check_py3() and isinstance(value, basestring): if _check_py3() and isinstance(value, basestring):
# If it's a string - encode it # If it's a string - encode it
value = value.encode() value = value.encode()
try:
return load(BytesIO(value),fmt=fmt,use_builtin_types=use_builtin_types,dict_type=dict_type) 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): def dump(value, fp, fmt=FMT_XML, sort_keys=True, skipkeys=False):
if _check_py3(): if _check_py3():
plistlib.dump(value, fp, fmt=fmt, sort_keys=sort_keys, skipkeys=skipkeys) plistlib.dump(value, fp, fmt=fmt, sort_keys=sort_keys, skipkeys=skipkeys)

View File

@ -2,10 +2,11 @@
setlocal enableDelayedExpansion setlocal enableDelayedExpansion
REM Setup initial vars REM Setup initial vars
set "script_name=%~n0.command" set "script_name="
set "thisDir=%~dp0" set "thisDir=%~dp0"
set /a tried=0 set /a tried=0
set "toask=yes" set "toask=yes"
set "pause_on_error=yes"
set "py2v=" set "py2v="
set "py2path=" set "py2path="
set "py3v=" set "py3v="
@ -18,14 +19,25 @@ REM FALSE = Use py2
REM FORCE = Use py3 REM FORCE = Use py3
set "use_py3=TRUE" set "use_py3=TRUE"
REM Get the system32 (or equivalent) path
call :getsyspath "syspath"
goto checkscript goto checkscript
:checkscript :checkscript
REM Check for our script first 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!" ( 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 Please make sure to run this script from the same directory
echo as !script_name!. echo as !looking_for!.
echo. echo.
echo Press [enter] to quit. echo Press [enter] to quit.
pause > nul pause > nul
@ -33,11 +45,50 @@ if not exist "!thisDir!\!script_name!" (
) )
goto checkpy 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 :updatepath
set "spath=" set "spath="
set "upath=" 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 "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 "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 "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v "Path" 2^> nul`) do ( if not "%%j" == "" set "spath=%%j" )
if not "%spath%" == "" ( if not "%spath%" == "" (
REM We got something in the system path REM We got something in the system path
set "PATH=%spath%" set "PATH=%spath%"
@ -49,25 +100,24 @@ if not "%spath%" == "" (
set "PATH=%upath%" set "PATH=%upath%"
) )
REM Remove double semicolons from the adjusted PATH REM Remove double semicolons from the adjusted PATH
call :undouble "PATH" ";" call :undouble "PATH" "%PATH%" ";"
goto :EOF 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 REM Helper function to strip doubles of a single character out of a string recursively
set "string_name=%~1" set "string_value=%~2"
set "character=%~2" set "check=!string_value:%~3%~3=%~3!"
set "check=!%string_name%:%character%%character%=%character%!" if not "!check!" == "!string_value!" (
if not "!check!" == "!%~1!" ( set "%~1=!check!"
set "!string_name!=!check!" call :undouble "%~1" "!check!" "%~3"
call :undouble "%~1" "%~2"
) )
goto :EOF goto :EOF
:checkpy :checkpy
call :updatepath call :updatepath
REM Get the system32 (or equivalent) path for /f "USEBACKQ tokens=*" %%x in (`!syspath!where.exe python 2^> nul`) do ( call :checkpyversion "%%x" "py2v" "py2path" "py3v" "py3path" )
set syspath=%ComSpec:cmd.exe=% for /f "USEBACKQ tokens=*" %%x in (`!syspath!where.exe python3 2^> nul`) do ( call :checkpyversion "%%x" "py2v" "py2path" "py3v" "py3path" )
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 py 2^> nul`) do ( call :checkpylauncher "%%x" "py2v" "py2path" "py3v" "py3path" )
set "targetpy=3" set "targetpy=3"
if /i "!use_py3!" == "FALSE" ( if /i "!use_py3!" == "FALSE" (
set "targetpy=2" set "targetpy=2"
@ -81,16 +131,14 @@ if /i "!use_py3!" == "FALSE" (
if not "!pypath!" == "" ( if not "!pypath!" == "" (
goto runscript goto runscript
) )
if !tried! lss 1 (
if "!pypath!" == "" (
if %tried% lss 1 (
if /i "!toask!"=="yes" ( if /i "!toask!"=="yes" (
REM Better ask permission first REM Better ask permission first
goto askinstall goto askinstall
) else ( ) else (
goto installpy goto installpy
) )
) else ( ) else (
cls cls
echo ### ### echo ### ###
echo # Warning # echo # Warning #
@ -109,10 +157,15 @@ if "!pypath!" == "" (
echo Press [enter] to quit. echo Press [enter] to quit.
pause > nul pause > nul
exit /b exit /b
)
) )
goto runscript 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> :checkpyversion <path> <py2v> <py2path> <py3v> <py3path>
set "version="&for /f "tokens=2* USEBACKQ delims= " %%a in (`"%~1" -V 2^>^&1`) do ( set "version="&for /f "tokens=2* USEBACKQ delims= " %%a in (`"%~1" -V 2^>^&1`) do (
REM Ensure we have a version number REM Ensure we have a version number
@ -138,7 +191,7 @@ if "!version:~0,1!" == "2" (
) )
goto :EOF goto :EOF
:isnumber <check> :isnumber <check_value>
set "var="&for /f "delims=0123456789." %%i in ("%~1") do set var=%%i set "var="&for /f "delims=0123456789." %%i in ("%~1") do set var=%%i
if defined var (exit /b 1) if defined var (exit /b 1)
exit /b 0 exit /b 0
@ -183,7 +236,7 @@ if /i "!menu!"=="y" (
goto installpy goto installpy
) else if "!menu!"=="n" ( ) else if "!menu!"=="n" (
REM No OK here... REM No OK here...
set /a tried=%tried%+1 set /a tried=!tried!+1
goto checkpy goto checkpy
) )
REM Incorrect answer - go back REM Incorrect answer - go back
@ -192,7 +245,7 @@ goto askinstall
:installpy :installpy
REM This will attempt to download and install python REM This will attempt to download and install python
REM First we get the html for the python downloads page for Windows REM First we get the html for the python downloads page for Windows
set /a tried=%tried%+1 set /a tried=!tried!+1
cls cls
echo ### ### echo ### ###
echo # Installing Python # echo # Installing Python #
@ -260,4 +313,13 @@ if "!args!"=="" (
) else ( ) else (
"!pypath!" "!thisDir!!script_name!" %* "!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 goto :EOF

View File

@ -212,6 +212,10 @@ class gibMacOS:
else: else:
# Add them all! # Add them all!
prodd["packages"] = plist_dict.get("Products",{}).get(prod,{}).get("Packages",[]) 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 # 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",{})) 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) prodd["title"] = smd.get("localization",{}).get("English",{}).get("title",n)
@ -404,7 +408,7 @@ class gibMacOS:
var1 = "{}. {} {}".format(num, p["title"], p["version"]) var1 = "{}. {} {}".format(num, p["title"], p["version"])
if p["build"].lower() != "unknown": if p["build"].lower() != "unknown":
var1 += " ({})".format(p["build"]) 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"]: if self.find_recovery and p["installer"]:
# Show that it's a full installer # Show that it's a full installer
var2 += " - FULL Install" var2 += " - FULL Install"