Skip to content

opsi.orgheader image

opsi.org
Views
WinstScripts >>

python

Document Actions
last edited 4 months ago by sehlers
Qualified for opsi 3.3
;------ start of python.ins -------
; Copyright (c) uib gmbh (www.uib.de)
; This sourcecode is owned by uib
; and published under the Terms of the General Public License.

;sources for this product
;http://www.python.org/download/releases/2.5/
;http://www.python.org/download/releases/2.5/msi/
;http://starship.python.net/crew/mhammond/
;http://sourceforge.net/project/showfiles.php?group_id=78018&package_id=79063
;http://www.dll-files.com/dllindex/dll-files.shtml?mfc71
;http://tgolden.sc.sabren.com/python/wmi.html
;http://tgolden.sc.sabren.com/python/wmi_cookbook.html

[Initial]
; Message at install time:
Message=installing python script interpreter ......
LogLevel=2
;  Log Errors in Logfile but don't abort:
ExitOnError=false
; Show syntax errors in the script:
ScriptErrorMessages=on
; Dont trace step by step through the script:
TraceMode=off
; let started programs run in front of the winst window
StayOnTop=false



[Aktionen]
DefVar $RebootFlag$
DefVar $WinstRegKey$
DefVar $RebootRegVar$
;Variables for version of the operating system (OS)-Test
DefVar $SYSTEMROOT$
DefVar $SYSTEMDRIVE$
Set $SYSTEMDRIVE$ = "%SYSTEMDRIVE%"
Set $SYSTEMROOT$ = "%SYSTEMROOT%"
DefVar $TEMP$
Set $TEMP$= EnvVar("TEMP")
DefVar $MinorOS$
DefVar $OS$
DefVar $Path$
set $Path$ = EnvVar ("Path")

DefVar $PythonInstallLogfile$
DefVar $OpenSSLInstallLogfile$
Set $PythonInstallLogfile$ = "c:\tmp\python_inst.log"
Set $OpenSSLInstallLogfile$ = "c:\tmp\python_openssl_inst.log"
Set $OpenSSLInstallLogfile$ = "c:\tmp\vcredist_x86.log"

DefVar $PRODUCTPATH$
Set $PRODUCTPATH$="%ProgramFilesDir%\python25"

DefStringList $TimeOutList$
DefStringList $ProcessList$
DefVar $ProcFound$
DefVar $SuccessFound$
DefVar $TimeOut$
DefVar $SearchProc$

DefStringList $INST_ResultList$
DefVar $INST_python_installed$
DefVar $INST_extensions_installed$
DefVar $INST_system_bit$
DefVar $INST_32Bit_ProgramFilesDir$

Set $INST_system_bit$ = "32"

set $OS$ = GetOS
set $MinorOS$ = GetNTVersion
if ( $OS$ = "Windows_NT" OR $OS$ = "Windows_95" )
   if not(HasMinimumSpace ("%SYSTEMDRIVE%", "20 MB"))
      LogError "Nicht genuegend Platz auf C: . 20 MB auf C: fuer Python erforderlich."
      ; Stop script and set installation status to failed
      isFatalError
   else
    ;sub_check_32_64
    Files_copy_SSL_dll
    sub_check_installation
    if ($INST_python_installed$ = "false") or ("on"=IniVar("force_installation"))
      ; Show product picture
      ShowBitmap /3 "%scriptpath%\python.png" "Python"
      
      ; Installing python base
      Winbatch_python_deinstall_2-5
      Winbatch_python_silent
      
      ; Installing win32 extensions
      ExecWith_autoit_pywin32 "%SCRIPTPATH%\autoit3.exe" WINST /letThemGo /EscapeStrings
      Winbatch_pywin32
      killtask "autoit3.exe"
      Files_copy_wmi
      sub_check_installation
      if ($INST_python_installed$ = "false")
        logError "Python not (correct) installed: Aborting"
	;pause    "Python not (correct) installed: Aborting"
	isFatalError
      endif
     endif ;python installed or force 
      if ((IniVar("opsi-vista-extension") = "on")) or ("OPSIVISTAEXT"=PARAMSTR)
       if ($INST_extensions_installed$ = "false") or ("on"=IniVar("force_installation"))
	comment Installing opsi/vista extensions
	Winbatch_vc_redist
	
	comment "start an autoit3 instance wich will answer to the setup"
	ExecWith_autoit_pycrypto "%SCRIPTPATH%\autoit3.exe" WINST /letThemGo /EscapeStrings
	Winbatch_pycrypto
	killtask "autoit3.exe"
	Winbatch_pyOpenSSL
	Winbatch_Twisted_NoDocs
	;Files_copy_Win32OpenSSL
	ExecWith_autoit_Win32OpenSSL "%SCRIPTPATH%\autoit3.exe" WINST /letThemGo /EscapeStrings
	Winbatch_Win32OpenSSL /letThemGo
	;set $SearchProc$ = "Win32OpenSSL_Light-0_9_8h"
	;sub_wait_until_proc_finished
	sleepSeconds 5
	sub_wait_until_success
	;DosInAnIcon_TryForSuccess
	killtask "Win32OpenSSL_Light-0_9_8h.exe"
	killtask "Win32OpenSSL_Light-0_9_8h.tmp"
	killtask "autoit3.exe"
	;ExecWith_autoit_wxPython  "%SCRIPTPATH%\autoit3.exe" WINST /letThemGo /EscapeStrings
	;Winbatch_wxPython
	Files_TwistedWeb2
	
	
	sub_check_installation
	if ($INST_extensions_installed$ = "false")
	  logError "Python Extensions not (correct) installed: Aborting"
	  ;pause    "Python Extensions not (correct) installed: Aborting"
	  isFatalError
	endif
	  
       endif ; extensions not installed or force  
      endif

      
      ; Modify $PATH
      Registry_python_path
      if IniVar("startmenue") = "off"
         LinkFolder_python_off
      else
         LinkFolder_python_on
      endif
      
      
       
      ; We need a reboot because path settings are changed
      ; We don't want to reboot if it is called by service_setup.cmd
      if not("OPSIVISTAEXT"=PARAMSTR)
       ExitWindows /Reboot
      endif 

   endif
endif

[sub_check_installation]
set $INST_ResultList$ = getOutStreamFromSection ('DosInAnIcon_checkpython')
if ("Python 2.5.2" = takestring(0,$INST_ResultList$))
 set $INST_python_installed$ = "true"
 comment "Python correct installed"
 Winbatch_checkpython
 if ("0" = getLastExitCode)
  comment "Python Extensions correct installed"
  set $INST_extensions_installed$ = "true"
 else 
  comment "Python Extensions not correct installed"
  set $INST_extensions_installed$ = "false"
 endif 
else
  set $INST_python_installed$ = "false"
  comment "Python not correct installed"  
endif

[Winbatch_python_deinstall_2-5]
; the /uninstall option needs windows installer 3.0
;msiexec /qb-! /li "$PythonInstallLogfile$" /uninstall "%scriptpath%\python-2.5.msi" 
;msiexec /qb-! /li "$PythonInstallLogfile$" /x "%scriptpath%\python-2.5.msi" 
; python 2.5.0
msiexec /qb-! /li "$PythonInstallLogfile$" /x {0A2C5854-557E-48C8-835A-3B9F074BDCAA}
; python 2.5.1
msiexec /qb-! /li "$PythonInstallLogfile$" /x {31800004-6386-4999-A519-518F2D78D8F0}
; python 2.5.2
msiexec /qb-! /li "$PythonInstallLogfile$" /x {6B976ADF-8AE8-434E-B282-A06C7F624D2F}

[Winbatch_python_silent]
msiexec /qb-!  /li+ "$PythonInstallLogfile$" /i "%ScriptPath%\python-2.5.2.msi" TARGETDIR="$PRODUCTPATH$" ALLUSERS=2

[ExecWith_autoit_pywin32]
WinWait("Setup","This Wizard will install")
Send("{ENTER}")
WinWait("Setup","Python 2.5 is required for thi")
Send("{ENTER}")
WinWait("Setup","Click Next to begin the instal")
Send("{ENTER}")
WinWait("Setup","Click the Finish button to exit the Setup wizard.")
Send("{ENTER}")
exit

[Winbatch_pywin32]
"%ScriptPath%\deps\pywin32-211.win32-py2.5.exe"

[Winbatch_pyOpenSSL]
msiexec /qb-!  /li+ "$OpenSSLInstallLogfile$" /i "%ScriptPath%\deps\pyOpenSSL-0.7.win32-py2.5.msi" ALLUSERS=2

[Winbatch_vc_redist]
"%ScriptPath%\deps\vcredist_x86.exe" /q:a /c:"msiexec /i vcredist.msi /qb-! /l*v $OpenSSLInstallLogfile$ ALLUSERS=2"

[ExecWith_autoit_pycrypto]
WinWait("Setup","This Wizard will install pycrypto on your computer.")
Send("{ENTER}")
WinWait("Setup","Python 2.5 is required for thi")
Send("{ENTER}")
WinWait("Setup","Click Next to begin the instal")
Send("{ENTER}")
WinWait("Setup","Click the Finish button to exit the Setup wizard.")
Send("{ENTER}")
exit

[Winbatch_pycrypto]
"%ScriptPath%\deps\pycrypto-2.0.1.win32-py2.5.exe"

[Winbatch_Twisted_NoDocs]
"%ScriptPath%\deps\Twisted_NoDocs-8.1.0.win32-py2.5.exe" /silent /NOCANCEL

[ExecWith_autoit_Win32OpenSSL]
;WinWait("Setup")
;Send("{ENTER}")
AdlibEnable('myAdLibV2')
WinWait("Setup - OpenSSL Light","Welcome to the OpenSSL Light Setup Wizard")
Send("{ENTER}")
WinWait("Setup - OpenSSL Light","License Agreement")
Send("{TAB}")
Send("{UP}")
Send("{ENTER}")
WinWait("Setup - OpenSSL Light","Select Destination Location")
Send("%ProgramFilesDir%\openssl")
Send("{ENTER}")
WinWait("Setup - OpenSSL Light","Select Start Menu Folder")
Send("{ENTER}")
WinWait("Setup - OpenSSL Light","Select Additional Tasks")
Send("{ENTER}")
WinWait("Setup - OpenSSL Light","Ready to Install")
Send("{ENTER}")
WinWait("Setup - OpenSSL Light","Completing the OpenSSL Light Setup Wizard")
Send("{SPACE}")
Send("{ENTER}")
exit

Func myAdLibV2 ( )
if WinExists ( 'Setup','The Win32 OpenSSL') then
 WinActivate ( 'Setup','The Win32 OpenSSL')
 Send("{ENTER}")
endif
EndFunc

[Winbatch_Win32OpenSSL]
"%ScriptPath%\deps\Win32OpenSSL_Light-0_9_8h.exe" /NOCANCEL /SUPPRESSMSGBOXES /NORESTART /SP- /LOG="c:\tmp\Win32OpenSSL.log"
;"%ScriptPath%\deps\Win32OpenSSL_Light-0_9_8h.exe"  /SILENT /SUPPRESSMSGBOXES /NORESTART /SP- /LOG="c:\tmp\Win32OpenSSL.log"

[Files_copy_Win32OpenSSL]
copy -sv "%ScriptPath%\openssl\*.*" "$INST_32Bit_ProgramFilesDir$\openssl"

[Files_copy_SSL_dll]
copy -vc "%ScriptPath%\openssl\*.dll" "%System%"

[ExecWith_autoit_wxPython]
WinWait("Setup","Welcome to the OpenSSL Light Setup Wizard")
Send("{ENTER}")
exit

[Winbatch_wxPython]
"%ScriptPath%\deps\wxPython2.8-win32-unicode-2.8.8.1-py25.exe" /silent /NOCANCEL /SUPPRESSMSGBOXES

[Files_TwistedWeb2]
copy -s "%ScriptPath%\deps\TwistedWeb2-8.1.0/twisted/*.*" "$PRODUCTPATH$\Lib\site-packages\twisted"

[Files_copy_wmi]
copy "%ScriptPath%\wmi.py" "$PRODUCTPATH$\lib"
copy -v "%ScriptPath%\mfc71.dll" "%System%"

[LinkFolder_python_off]
set_basefolder common_programs
delete_subfolder "Python 2.5"
delete_subfolder "OpenSSL"
delete_subfolder "Twisted (Python 2.5)"

[LinkFolder_python_on]
set_basefolder common_programs
set_subfolder "Python 2.5"
set_link
 name: PythonWin
 target: $PRODUCTPATH$\Lib\site-packages\pythonwin\pythonwin.exe
 parameters:
 working_dir: $PRODUCTPATH$
 icon_file: 
 icon_index:
end_link
set_link
 name: Python for Windows Documentation
 target: $PRODUCTPATH$\Lib\site-packages\pythonwin\pywin32.chm
 parameters:
 working_dir: $PRODUCTPATH$
 icon_file:
 icon_index:
end_link

[Registry_python_path]
openkey [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\control\Session Manager\Environment]
set "Path"="$Path$"
supp "Path"; "$PRODUCTPATH$"

[sub_wait_until_success]
set $SuccessFound$="0"
set $TimeOut$="0"
set $TimeOutList$= createStringList("0","1","2","3","4","5","6","7","8","end")
for %t% in $TimeOutList$ do sub_successlook_and_wait

[sub_successlook_and_wait]
if ($TimeOut$="0") and ($SuccessFound$="0")
 Winbatch_LookForSuccess
 if ("0" = getLastExitCode)
  comment "opensll installation ready to kill"
  set $SuccessFound$="1"
 else 
  comment "opensll installation not ready to kill"
  set $SuccessFound$="0"
 endif 
 if ("%t%"="end") 
  set $TimeOut$="1"
  comment "Time out: kill installation anyway"
 endif
 if ($TimeOut$="0") and ($SuccessFound$="0")
  sleepSeconds 2
 else
  comment "nothing to do"
 endif
endif

[Winbatch_LookForSuccess]
findstr /I /C:"Installation process succeeded" "c:\tmp\Win32OpenSSL.log"



[DosInAnIcon_TryForSuccess]
set TIMEOUT=
:TRY
findstr /I /C:"Installation process succeeded" "c:\tmp\Win32OpenSSL.log"
IF %ERRORLEVEL% 0 goto READY
set TIMEOUT=%TIMEOUT%1
if %TIMEOUT% == 1111111111111111 goto READY
sleep 1
goto TRY
:READY

[sub_wait_until_proc_finished]
set $ProcFound$="1"
set $TimeOut$="0"
set $TimeOutList$= createStringList("0","1","2","3","4","5","6","7","8","end")
for %t% in $TimeOutList$ do sub_proclook_and_wait

[sub_proclook_and_wait]
if ($TimeOut$="0") and ($ProcFound$="1")
 set $ProcFound$="0"
 set $ProcessList$ = getOutStreamFromSection('DosBatch_pslist')
 LogLevel = -2
 for %s% in $ProcessList$ do sub_find_proc
 LogLevel = 2
 if ("%t%"="end") 
  set $TimeOut$="1"
 endif
 if ($TimeOut$="0") and ($ProcFound$="1")
  sleepSeconds 2
 endif
 if ($TimeOut$="1") and ($ProcFound$="1")
  killtask $SearchProc$+".exe"
  killtask $SearchProc$+".tmp"
  sleepSeconds 2
  ; ExitWindows /ImmediateReboot
 endif
endif

[sub_find_proc]
 if ($ProcFound$="0")
  if takestring(0, splitStringOnWhitespace ("%s%")) = $SearchProc$
   set $ProcFound$="1"
  endif
 endif

[DosBatch_pslist]
@echo off
%ScriptPath%\pslist /accepteula

[DosInAnIcon_checkpython]
@echo off
"%ProgramFilesDir%\python25\python.exe" --version

[Winbatch_checkpython]
"%ProgramFilesDir%\python25\python.exe" -c "import Crypto, OpenSSL, twisted.internet, twisted.web2, ctypes, pywintypes, ntsecuritycon, win32service, win32event, win32con, win32ts, win32process, win32api, win32security, win32gui, win32wnet, win32netcon, _winreg"

[sub_check_32_64]
set $INST_ResultList$ = getOutStreamFromSection ('DosInAnIcon_check_32_64')
if ("x64-based PC " = takestring(1,$INST_ResultList$))
 set $INST_system_bit$=64
 set $INST_32Bit_ProgramFilesDir$ = "%ProgramFilesDir% x86"
endif
if ("x32-based PC " = takestring(1,$INST_ResultList$))
 set $INST_system_bit$=32
 set $INST_32Bit_ProgramFilesDir$ = "%ProgramFilesDir%"
endif


[DosInAnIcon_check_32_64]
@echo off
wmic computersystem get SystemType