Advertisement
J2897

Python Installer

Jan 21st, 2016
336
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 3.31 KB | None | 0 0
  1. :: Released under the GNU General Public License version 3 by J2897.
  2.  
  3. :: This will download and install Python in the default folder.
  4. :: Be sure to set the PYVER variable to the version you require!
  5.  
  6. :: You can use 'wget' and 'md5deep' with a 'hashes.dat' file if PowerShell is unavailable.
  7.  
  8. :: To run from Cygwin (OpenSSH)...
  9. :: ls -d1 /cygdrive/c/*/ # List folders.
  10. :: chmod 700 '/cygdrive/c/cygstore/scripts/Python_Installer/Python_Installer.bat' # Make executable.
  11. :: cygstart '/cygdrive/c/cygstore/scripts/Python_Installer/Python_Installer.bat'
  12.  
  13. :: After installing, you may want to reset the permissions...
  14. :: icacls "$(cygpath -w '/cygdrive/c/cygstore/scripts/')" # List permissions.
  15. :: icacls "$(cygpath -w '/cygdrive/c/cygstore/scripts/')" /reset /T /C /L /Q # Reset permissions.
  16.  
  17. @echo OFF
  18. setlocal
  19. pushd "%~dp0"
  20. cls
  21. title Python Installer
  22.  
  23. REM Is Python installed?
  24. if exist "%SYSTEMDRIVE%\Python27" (
  25.     echo Python is already installed.
  26.     goto :End
  27. )
  28.  
  29. REM Check for administrative privileges.
  30. ver | findstr "Version 6." >nul
  31. if %ERRORLEVEL% == 0 (
  32.     openfiles >nul
  33.     if errorlevel 1 (
  34.         popd
  35.         endlocal
  36.         exit /b 1
  37.     )
  38. )
  39.  
  40. set "PYVER=2.7.11"
  41. set "FN32=python-%PYVER%.msi"
  42. set "FN64=python-%PYVER%.amd64.msi"
  43.  
  44. REM Get the OS #-Bit...
  45. set "BIT=64"
  46. if %PROCESSOR_ARCHITECTURE% == x86 (
  47.     if not defined PROCESSOR_ARCHITEW6432 (set "BIT=32")
  48. )
  49.  
  50. REM Set the appropriate Python executable...
  51. if %BIT% == 64 (
  52.     set "FN=%FN64%"
  53. ) else (
  54.     set "FN=%FN32%"
  55. )
  56.  
  57. set "URL=https://www.python.org/ftp/python/%PYVER%/%FN%"
  58.  
  59. REM Does the installation file already exist?
  60. if exist "%USERPROFILE%\Downloads\%FN%" (set "TEMP_PYTHON_MSI=%USERPROFILE%\Downloads\%FN%") else (
  61.     if exist "%TEMP%\%FN%" (set "TEMP_PYTHON_MSI=%TEMP%\%FN%") else (
  62.         set "TEMP_PYTHON_MSI=%TEMP%\%FN%"
  63.     )
  64. )
  65.  
  66. REM Is wget available?
  67. if not exist "wget\wget.exe" (
  68.     if exist "%TEMP_PYTHON_MSI%" (
  69.         del "%TEMP_PYTHON_MSI%"
  70.     )
  71.     goto :Download
  72. )
  73.  
  74. REM Is the MD5 Hash valid?
  75.  
  76.     REM Set the appropriate md5deep executable...
  77.     if %BIT% == 64 (
  78.         set "MD5DEEP_EXE=%CD%\md5deep\md5deep64.exe"
  79.     ) else (
  80.         set "MD5DEEP_EXE=%CD%\md5deep\md5deep.exe"
  81.     )
  82.  
  83.     REM Verify the MD5 Hash...
  84.     set "HASH_DB=%CD%\hashes.dat"
  85.     "%MD5DEEP_EXE%" -M "%HASH_DB%" -b "%TEMP_PYTHON_MSI%"
  86.     if %ERRORLEVEL% LEQ 1 (
  87.         echo MD5 hash verified.
  88.         goto :Install
  89.     ) else (
  90.         echo MD5 mismatch.
  91.     )
  92.  
  93. :Continue
  94. echo Attempting to continue the download . . .
  95. wget\wget.exe -c "%URL%" -O "%TEMP_PYTHON_MSI%" --no-check-certificate && (goto :Install) || (
  96.     echo Failed to continue downloading using wget.
  97.     echo Restarting download . . .
  98.     del "%TEMP_PYTHON_MSI%"
  99. )
  100.  
  101. :Download
  102. echo Downloading . . .
  103. if exist "wget\wget.exe" (
  104.     wget\wget.exe "%URL%" -O "%TEMP_PYTHON_MSI%" -nv --no-check-certificate || (
  105.         echo Failed to download using wget.
  106.         goto :End
  107.     )
  108. ) else (
  109.     powershell -command "& { (New-Object Net.WebClient).DownloadFile('%URL%', '%TEMP_PYTHON_MSI%') }"
  110.     if %ERRORLEVEL% NEQ 0 (
  111.         echo Failed to download using PowerShell.
  112.         title Python Installer
  113.         goto :End
  114.     )
  115.     title Python Installer
  116. )
  117.  
  118. :Install
  119. echo Installing %FN% . . .
  120. msiexec /i "%TEMP_PYTHON_MSI%" /qn ALLUSERS=1 || (echo Failed to install Python.)
  121.  
  122. :End
  123. echo Finished.
  124. pause
  125. if defined TEMP_PYTHON_MSI (
  126.     if exist "%TEMP_PYTHON_MSI%" (del "%TEMP_PYTHON_MSI%")
  127. )
  128. popd
  129. endlocal
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement