Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- :: Released under the GNU General Public License version 3 by J2897.
- :: This will download and install Python in the default folder.
- :: Be sure to set the PYVER variable to the version you require!
- :: You can use 'wget' and 'md5deep' with a 'hashes.dat' file if PowerShell is unavailable.
- :: To run from Cygwin (OpenSSH)...
- :: ls -d1 /cygdrive/c/*/ # List folders.
- :: chmod 700 '/cygdrive/c/cygstore/scripts/Python_Installer/Python_Installer.bat' # Make executable.
- :: cygstart '/cygdrive/c/cygstore/scripts/Python_Installer/Python_Installer.bat'
- :: After installing, you may want to reset the permissions...
- :: icacls "$(cygpath -w '/cygdrive/c/cygstore/scripts/')" # List permissions.
- :: icacls "$(cygpath -w '/cygdrive/c/cygstore/scripts/')" /reset /T /C /L /Q # Reset permissions.
- @echo OFF
- setlocal
- pushd "%~dp0"
- cls
- title Python Installer
- REM Is Python installed?
- if exist "%SYSTEMDRIVE%\Python27" (
- echo Python is already installed.
- goto :End
- )
- REM Check for administrative privileges.
- ver | findstr "Version 6." >nul
- if %ERRORLEVEL% == 0 (
- openfiles >nul
- if errorlevel 1 (
- popd
- endlocal
- exit /b 1
- )
- )
- set "PYVER=2.7.11"
- set "FN32=python-%PYVER%.msi"
- set "FN64=python-%PYVER%.amd64.msi"
- REM Get the OS #-Bit...
- set "BIT=64"
- if %PROCESSOR_ARCHITECTURE% == x86 (
- if not defined PROCESSOR_ARCHITEW6432 (set "BIT=32")
- )
- REM Set the appropriate Python executable...
- if %BIT% == 64 (
- set "FN=%FN64%"
- ) else (
- set "FN=%FN32%"
- )
- set "URL=https://www.python.org/ftp/python/%PYVER%/%FN%"
- REM Does the installation file already exist?
- if exist "%USERPROFILE%\Downloads\%FN%" (set "TEMP_PYTHON_MSI=%USERPROFILE%\Downloads\%FN%") else (
- if exist "%TEMP%\%FN%" (set "TEMP_PYTHON_MSI=%TEMP%\%FN%") else (
- set "TEMP_PYTHON_MSI=%TEMP%\%FN%"
- )
- )
- REM Is wget available?
- if not exist "wget\wget.exe" (
- if exist "%TEMP_PYTHON_MSI%" (
- del "%TEMP_PYTHON_MSI%"
- )
- goto :Download
- )
- REM Is the MD5 Hash valid?
- REM Set the appropriate md5deep executable...
- if %BIT% == 64 (
- set "MD5DEEP_EXE=%CD%\md5deep\md5deep64.exe"
- ) else (
- set "MD5DEEP_EXE=%CD%\md5deep\md5deep.exe"
- )
- REM Verify the MD5 Hash...
- set "HASH_DB=%CD%\hashes.dat"
- "%MD5DEEP_EXE%" -M "%HASH_DB%" -b "%TEMP_PYTHON_MSI%"
- if %ERRORLEVEL% LEQ 1 (
- echo MD5 hash verified.
- goto :Install
- ) else (
- echo MD5 mismatch.
- )
- :Continue
- echo Attempting to continue the download . . .
- wget\wget.exe -c "%URL%" -O "%TEMP_PYTHON_MSI%" --no-check-certificate && (goto :Install) || (
- echo Failed to continue downloading using wget.
- echo Restarting download . . .
- del "%TEMP_PYTHON_MSI%"
- )
- :Download
- echo Downloading . . .
- if exist "wget\wget.exe" (
- wget\wget.exe "%URL%" -O "%TEMP_PYTHON_MSI%" -nv --no-check-certificate || (
- echo Failed to download using wget.
- goto :End
- )
- ) else (
- powershell -command "& { (New-Object Net.WebClient).DownloadFile('%URL%', '%TEMP_PYTHON_MSI%') }"
- if %ERRORLEVEL% NEQ 0 (
- echo Failed to download using PowerShell.
- title Python Installer
- goto :End
- )
- title Python Installer
- )
- :Install
- echo Installing %FN% . . .
- msiexec /i "%TEMP_PYTHON_MSI%" /qn ALLUSERS=1 || (echo Failed to install Python.)
- :End
- echo Finished.
- pause
- if defined TEMP_PYTHON_MSI (
- if exist "%TEMP_PYTHON_MSI%" (del "%TEMP_PYTHON_MSI%")
- )
- popd
- endlocal
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement