Update MakeInstall.bat

This commit is contained in:
CorpNewt 2024-02-07 14:15:56 -06:00 committed by GitHub
parent a434e1bbf1
commit 9065d3760d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -13,6 +13,7 @@ set "py2path="
set "py3v=" set "py3v="
set "py3path=" set "py3path="
set "pypath=" set "pypath="
set "targetpy=3"
REM use_py3: REM use_py3:
REM TRUE = Use if found, use py2 otherwise REM TRUE = Use if found, use py2 otherwise
@ -20,9 +21,48 @@ REM FALSE = Use py2
REM FORCE = Use py3 REM FORCE = Use py3
set "use_py3=TRUE" set "use_py3=TRUE"
REM We'll parse if the first argument passed is
REM --install-python and if so, we'll just install
set "just_installing=FALSE"
REM Get the system32 (or equivalent) path REM Get the system32 (or equivalent) path
call :getsyspath "syspath" call :getsyspath "syspath"
REM Make sure the syspath exists
if "!syspath!" == "" (
if exist "%SYSTEMROOT%\system32\cmd.exe" (
if exist "%SYSTEMROOT%\system32\reg.exe" (
if exist "%SYSTEMROOT%\system32\where.exe" (
REM Fall back on the default path if it exists
set "ComSpec=%SYSTEMROOT%\system32\cmd.exe"
set "syspath=%SYSTEMROOT%\system32\"
)
)
)
if "!syspath!" == "" (
cls
echo ### ###
echo # Warning #
echo ### ###
echo.
echo Could not locate cmd.exe, reg.exe, or where.exe
echo.
echo Please ensure your ComSpec environment variable is properly configured and
echo points directly to cmd.exe, then try again.
echo.
echo Current CompSpec Value: "%ComSpec%"
echo.
echo Press [enter] to quit.
pause > nul
exit /b 1
)
)
if "%~1" == "--install-python" (
set "just_installing=TRUE"
goto installpy
)
goto checkscript goto checkscript
:checkscript :checkscript
@ -42,41 +82,48 @@ if not exist "!thisDir!\!script_name!" (
echo. echo.
echo Press [enter] to quit. echo Press [enter] to quit.
pause > nul pause > nul
exit /b exit /b 1
) )
goto checkpy goto checkpy
:getsyspath <variable_name> :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 Helper method to return a valid path to cmd.exe, reg.exe, and where.exe by
REM Prep the LF variable to use the "line feed" approach REM walking the ComSpec var - will also repair it in memory if need be
(SET LF=^ REM Strip double semi-colons
call :undouble "temppath" "%ComSpec%" ";"
REM Dirty hack to leverage the "line feed" approach - there are some odd side
REM effects with this. Do not use this variable name in comments near this
REM line - as it seems to behave erradically.
(set LF=^
%=this line is empty=% %=this line is empty=%
) )
REM Strip double semi-colons REM Replace instances of semi-colons with a line feed and wrap
call :undouble "ComSpec" "%ComSpec%" ";" REM in parenthesis to work around some strange batch behavior
set "testpath=%ComSpec:;=!LF!%" set "testpath=%temppath:;=!LF!%"
REM Let's walk each path and test if cmd.exe, reg.exe, and where.exe exist there REM Let's walk each path and test if cmd.exe, reg.exe, and where.exe exist there
set /a found=0 set /a found=0
for /f "tokens=* delims=" %%i in ("!testpath!") do ( for /f "tokens=* delims=" %%i in ("!testpath!") do (
REM Only continue if we haven't found it yet REM Only continue if we haven't found it yet
if NOT "%%i" == "" ( if not "%%i" == "" (
if !found! lss 1 ( if !found! lss 1 (
set "temppath=%%i" set "checkpath=%%i"
REM Remove "cmd.exe" from the end if it exists REM Remove "cmd.exe" from the end if it exists
if /i "!temppath:~-7!" == "cmd.exe" ( if /i "!checkpath:~-7!" == "cmd.exe" (
set "temppath=!temppath:~0,-7!" set "checkpath=!checkpath:~0,-7!"
) )
REM Pad the end with a backslash if needed REM Pad the end with a backslash if needed
if NOT "!temppath:~-1!" == "\" ( if not "!checkpath:~-1!" == "\" (
set "temppath=!temppath!\" set "checkpath=!checkpath!\"
) )
REM Let's see if cmd, reg, and where exist there - and set it if so REM Let's see if cmd, reg, and where exist there - and set it if so
if EXIST "!temppath!cmd.exe" ( if EXIST "!checkpath!cmd.exe" (
if EXIST "!temppath!reg.exe" ( if EXIST "!checkpath!reg.exe" (
if EXIST "!temppath!where.exe" ( if EXIST "!checkpath!where.exe" (
set /a found=1 set /a found=1
set "ComSpec=!temppath!cmd.exe" set "ComSpec=!checkpath!cmd.exe"
set "%~1=!temppath!" set "%~1=!checkpath!"
) )
) )
) )
@ -93,7 +140,7 @@ for /f "USEBACKQ tokens=2* delims= " %%i in (`!syspath!reg.exe query "HKLM\SYSTE
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%"
if not "!upath!" == "" ( if not "%upath%" == "" (
REM We also have something in the user path REM We also have something in the user path
set "PATH=%PATH%;%upath%" set "PATH=%PATH%;%upath%"
) )
@ -107,11 +154,13 @@ goto :EOF
:undouble <string_name> <string_value> <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_value=%~2" set "string_value=%~2"
:undouble_continue
set "check=!string_value:%~3%~3=%~3!" set "check=!string_value:%~3%~3=%~3!"
if not "!check!" == "!string_value!" ( if not "!check!" == "!string_value!" (
set "%~1=!check!" set "string_value=!check!"
call :undouble "%~1" "!check!" "%~3" goto :undouble_continue
) )
set "%~1=!check!"
goto :EOF goto :EOF
:checkpy :checkpy
@ -119,7 +168,6 @@ call :updatepath
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 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 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" ) 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" ( if /i "!use_py3!" == "FALSE" (
set "targetpy=2" set "targetpy=2"
set "pypath=!py2path!" set "pypath=!py2path!"
@ -157,7 +205,7 @@ if !tried! lss 1 (
echo. echo.
echo Press [enter] to quit. echo Press [enter] to quit.
pause > nul pause > nul
exit /b exit /b 1
) )
goto runscript goto runscript
@ -255,7 +303,12 @@ echo.
echo Gathering info from https://www.python.org/downloads/windows/... echo Gathering info from https://www.python.org/downloads/windows/...
powershell -command "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; (new-object System.Net.WebClient).DownloadFile('https://www.python.org/downloads/windows/','%TEMP%\pyurl.txt')" powershell -command "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; (new-object System.Net.WebClient).DownloadFile('https://www.python.org/downloads/windows/','%TEMP%\pyurl.txt')"
if not exist "%TEMP%\pyurl.txt" ( if not exist "%TEMP%\pyurl.txt" (
goto checkpy if /i "!just_installing!" == "TRUE" (
echo Failed to get info
exit /b 1
) else (
goto checkpy
)
) )
echo Parsing for latest... echo Parsing for latest...
@ -264,7 +317,7 @@ pushd "%TEMP%"
for /f "tokens=9 delims=< " %%x in ('findstr /i /c:"Latest Python !targetpy! Release" pyurl.txt') do ( set "release=%%x" ) for /f "tokens=9 delims=< " %%x in ('findstr /i /c:"Latest Python !targetpy! Release" pyurl.txt') do ( set "release=%%x" )
popd popd
echo Found Python !release! - Downloading... echo Found Python !release! - Downloading...
REM Let's delete our txt file now - we no longer need it REM Let's delete our txt file now - we no longer need it
del "%TEMP%\pyurl.txt" del "%TEMP%\pyurl.txt"
@ -280,7 +333,12 @@ REM Now we download it with our slick powershell command
powershell -command "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; (new-object System.Net.WebClient).DownloadFile('!url!','%TEMP%\pyinstall.!pytype!')" powershell -command "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; (new-object System.Net.WebClient).DownloadFile('!url!','%TEMP%\pyinstall.!pytype!')"
REM If it doesn't exist - we bail REM If it doesn't exist - we bail
if not exist "%TEMP%\pyinstall.!pytype!" ( if not exist "%TEMP%\pyinstall.!pytype!" (
goto checkpy if /i "!just_installing!" == "TRUE" (
echo Failed to download installer
exit /b 1
) else (
goto checkpy
)
) )
REM It should exist at this point - let's run it to install silently REM It should exist at this point - let's run it to install silently
echo Installing... echo Installing...
@ -301,7 +359,12 @@ REM If it worked, then we should have python in our PATH
REM this does not get updated right away though - let's try REM this does not get updated right away though - let's try
REM manually updating the local PATH var REM manually updating the local PATH var
call :updatepath call :updatepath
goto checkpy if /i "!just_installing!" == "TRUE" (
echo.
echo Done.
) else (
goto checkpy
)
exit /b exit /b
:runscript :runscript