Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $PATH_PSCP = "pscp.exe"
- $PATH_PSSERVICE = "c:\PsTools\psservice.exe"
- $PATH_PSEXEC = "c:\PsTools\psexec.exe"
- $SLEEP_SECS = "5"
- $MAX_STATUS_CHECK_ITER = "2"
- Function WaitForServiceTo ($address, $service, $status) {
- [Array]$serv_query_args = "\\$address", "-u", "$REMOTE_USER", "-p", "$REMOTE_USER_PWD", "query", "$service";
- $iteration = 1
- do {
- if ($iteration -gt $MAX_STATUS_CHECK_ITER) {
- write-host "No se consiguió que el servicio $service llegue al estado $status en el equipo $address" -foreground "red"
- return $false
- }
- write-host "Esperamos $SLEEP_SECS segundos antes de comprobar el estado del servicio" -foreground "yellow"
- Start-Sleep -s $SLEEP_SECS
- write-host "Solicitud de estado para el servicio $service - Iteración $iteration" -foreground "yellow"
- write-host "$PATH_PSSERVICE $serv_query_args" -foreground "yellow"
- $result = & $PATH_PSSERVICE $serv_query_args
- if ($result -eq $null) {
- break
- }
- $str_result = [string]$result
- $res = $str_result.Contains($status)
- $iteration = $iteration + 1
- } while ($res -ne $true)
- return $true
- }
- Function StopService ($address, $service) {
- [Array]$serv_stop_args = "\\$address", "-u", "$REMOTE_USER", "-p", "$REMOTE_USER_PWD", "stop", "$service";
- write-host "Stopping service $service" -foreground "yellow"
- write-host "$PATH_PSSERVICE $serv_stop_args" -foreground "yellow"
- $result = & $PATH_PSSERVICE $serv_stop_args
- $str_result = [string]$result
- $RES = $str_result.Contains("1 STOPPED")
- if ($result -ne $null -and $res -ne $true) {
- write-host "Servicio $service no ha parado todavía..." -foreground "yellow"
- $wait_result = WaitForServiceTo $address $service "1 STOPPED"
- } else {
- $wait_result = $true
- }
- if ($wait_result -eq $true) {
- write-host "Servicio $service parado" -foreground "green"
- }
- return $wait_result
- }
- Function StartService ($address, $service) {
- [Array]$serv_start_args = "\\$address", "-u", "$REMOTE_USER", "-p", "$REMOTE_USER_PWD", "start", "$service";
- write-host "Starting service $service" -foreground "yellow"
- write-host "$PATH_PSSERVICE $serv_start_args" -foreground "yellow"
- $result = & $PATH_PSSERVICE $serv_start_args
- $str_result = [string]$result
- $RES = $str_result.Contains("4 RUNNING")
- if ($result -ne $null -and $res -ne $true) {
- write-host "Servicio $service no se ha iniciado todavía..." -foreground "yellow"
- $wait_result = WaitForServiceTo $address $service "4 RUNNING"
- } else {
- $wait_result = $true
- }
- if ($wait_result -eq $true) {
- write-host "Servicio $service iniciado" -foreground "green"
- }
- return $wait_result
- }
- & cls
- if ($args.Length -ne 4) {
- write-host "Wrong number of parameters. usage: kiosk_installer_script.ps1 REMOTE_USERNAME REMOTE_USERNAME_PASSWORD INSTALLATION_FOLDER_NAME KIOSK_TYPE" -foreground "red"
- exit
- }
- $REMOTE_USER = $args[0]
- $REMOTE_USER_PWD = $args[1]
- $INSTALLER_FOLDER = $args[2]
- $KIOSK_TYPE = $args[3]
- if ($KIOSK_TYPE -eq "TPVA") {
- $MSI_FILE = "TPVAInstaller.msi"
- $SERVICE_NAME = "IonIDESellingPointManager"
- $PRODUCT_CODE = "{3A273578-9191-441E-B82A-6F70933CA4CD}"
- $SOURCE_KIOSK_LIST = "$Pwd\tpva_kiosks"
- $KIOSK_INSTALL_ERROR = "$Pwd\failed_tpva_kiosks.txt"
- } elseif ($KIOSK_TYPE -eq "KION") {
- $MSI_FILE = "KIONInstaller.msi"
- $SERVICE_NAME = "IonIDESellingPointManager"
- $PRODUCT_CODE = "{9DF487A0-4B4F-45D1-B78B-ACACA69131BA}"
- $SOURCE_KIOSK_LIST = "$Pwd\kion_kiosks"
- $KIOSK_INSTALL_ERROR = "$Pwd\failed_kion_kiosks.txt"
- } elseif ($KIOSK_TYPE -eq "IK100") {
- $MSI_FILE = "IK100Installer.msi"
- $SERVICE_NAME = "IonIDESellingPointManager"
- $PRODUCT_CODE = "{0577C7A7-9A7D-42AD-838E-D85C47487A46}"
- $SOURCE_KIOSK_LIST = "$Pwd\ik100_kiosks"
- $KIOSK_INSTALL_ERROR = "$Pwd\failed_ik100_kiosks.txt"
- } else {
- write-host "Kiosk type must be either TPVA or KION or IK100" -foreground "red"
- exit
- }
- if ($INSTALLER_FOLDER.StartsWith(".\") -eq $True) {
- $INSTALLER_FOLDER = $INSTALLER_FOLDER.TrimStart(".\")
- }
- if (Test-Path ("$KIOSK_INSTALL_ERROR")) {
- & del "$KIOSK_INSTALL_ERROR"
- }
- $kiosk_list = [System.IO.File]::OpenText("$SOURCE_KIOSK_LIST")
- try {
- for(;;) {
- $kiosk_address = $kiosk_list.ReadLine()
- if ($kiosk_address -eq $null) {
- break
- }
- write-host "------ Copiando directorio de instalación $INSTALLER_FOLDER a máquina $kiosk_address ------" -foreground "magenta"
- ""
- [Array]$sftp_args = "-sftp", "-v", "-r", "-l", "$REMOTE_USER", "-pw", "$REMOTE_USER_PWD", "$Pwd\$INSTALLER_FOLDER", "$kiosk_address`:";
- write-host "$PATH_PSCP $sftp_args" -foreground "yellow"
- & $PATH_PSCP $sftp_args
- if ($LASTEXITCODE -ne 0) {
- write-host "Could not copy installation folder to kiosk $kiosk_address" -foreground "red"
- "$kiosk_address $LASTEXITCODE" >> "$KIOSK_INSTALL_ERROR"
- continue
- }
- if ($KIOSK_TYPE -eq "TPVA" -Or $KIOSK_TYPE -eq "KION") {
- ""
- write-host "------ Parando servicio IonIDEKillExplorer ------" -foreground "magenta"
- ""
- $serv_res = StopService $kiosk_address "IonIDEKillExplorer"
- if ($serv_res -eq $false) {
- write-host "Error parando el servicio" -foreground "red"
- "$kiosk_address" >> "$KIOSK_INSTALL_ERROR"
- continue
- }
- ""
- write-host "------ Parando servicio IonIDEFirefoxService ------" -foreground "magenta"
- ""
- $serv_res = StopService $kiosk_address "IonIDEFirefoxService"
- if ($serv_res -eq $false) {
- write-host "Error parando el servicio" -foreground "red"
- "$kiosk_address" >> "$KIOSK_INSTALL_ERROR"
- continue
- }
- }
- ""
- write-host "------ Parando servicio $SERVICE_NAME ------" -foreground "magenta"
- ""
- $serv_res = StopService $kiosk_address $SERVICE_NAME
- if ($serv_res -eq $false) {
- $dialog_screen = new-object -comobject wscript.shell
- $int_answer = $dialog_screen.popup("Continuar instalación en este kiosco?", 0 , "Error parando servicio $SERVICE_NAME", 4)
- If ($int_answer -eq 6) {
- write-host "Continuando la instalación en este kiosco" -foreground "green"
- } else {
- write-host "Error parando el servicio" -foreground "red"
- "$kiosk_address" >> "$KIOSK_INSTALL_ERROR"
- continue
- }
- }
- ""
- write-host "------ Desinstalando versión anterior de $SERVICE_NAME ------" -foreground "magenta"
- ""
- [Array]$serv_uninstall_args = "\\$kiosk_address", "-u", "$REMOTE_USER", "-p", "$REMOTE_USER_PWD", "cmd", "/c", "`"msiexec.exe /x $PRODUCT_CODE /qn`"";
- write-host "$PATH_PSEXEC $serv_uninstall_args" -foreground "yellow"
- cmd /c $PATH_PSEXEC $serv_uninstall_args
- ""
- if ($LASTEXITCODE -eq 0) {
- write-host "Desinstalación remota completada con éxito" -foreground "green"
- } elseif ($LASTEXITCODE -eq 1605) {
- write-host "Aplicación ya desinstalada. Continuando el proceso..." -foreground "yellow"
- } else {
- write-host "Error en la desinstalación remota - Error $LASTEXITCODE" -foreground "red"
- "$kiosk_address $LASTEXITCODE" >> "$KIOSK_INSTALL_ERROR"
- continue
- }
- ""
- write-host "------ Instalando nueva versión de $SERVICE_NAME ------" -foreground "magenta"
- ""
- [Array]$serv_install_args = "\\$kiosk_address", "-u", "$REMOTE_USER", "-p", "$REMOTE_USER_PWD", "cmd", "/c", "`"msiexec.exe /i C:\temp\$INSTALLER_FOLDER\$MSI_FILE /qn /l*v c:\temp\$INSTALLER_FOLDER\install.log user=$REMOTE_USER pass=$REMOTE_USER_PWD`"";
- write-host "$PATH_PSEXEC $serv_install_args" -foreground "yellow"
- cmd /c $PATH_PSEXEC $serv_install_args
- ""
- if ($LASTEXITCODE -eq 0) {
- write-host "Instalación remota completada con éxito" -foreground "green"
- } else {
- write-host "Error en la instalación remota - Error $LASTEXITCODE" -foreground "red"
- "$kiosk_address $LASTEXITCODE" >> "$KIOSK_INSTALL_ERROR"
- continue
- }
- ""
- write-host "------ Iniciando servicio $SERVICE_NAME ------" -foreground "magenta"
- ""
- $serv_res = StartService $kiosk_address $SERVICE_NAME
- if ($serv_res -eq $false) {
- write-host "Error iniciando el servicio" -foreground "red"
- "$kiosk_address" >> "$KIOSK_INSTALL_ERROR"
- continue
- }
- }
- }
- finally {
- $kiosk_list.Close();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement