agent_installer.bat 5.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. @echo off
  2. net session >nul 2>&1
  3. if NOT %errorLevel% == 0 (
  4. echo Failure: Current permissions inadequate.
  5. echo[
  6. echo Run this script by using "Run as administrator" in the context menu.
  7. pause >nul
  8. exit
  9. )
  10. set WD=%~dp0
  11. pushd %WD%
  12. REM Create a vbs file that downloads the setup binary for Cygwin
  13. echo strFileURL = "http://cygwin.com/setup-x86.exe" > dwl_setup.vbs
  14. echo Dim strSavePath >> dwl_setup.vbs
  15. echo strSavePath = CreateObject("Scripting.FileSystemObject").GetAbsolutePathName(".") ^& "\setup-x86.exe" >> dwl_setup.vbs
  16. echo Set objXMLHTTP = CreateObject("MSXML2.XMLHTTP") >> dwl_setup.vbs
  17. echo objXMLHTTP.open "GET", strFileURL, false >> dwl_setup.vbs
  18. echo objXMLHTTP.send() >> dwl_setup.vbs
  19. echo If objXMLHTTP.Status = 200 Then >> dwl_setup.vbs
  20. echo Set objADOStream = CreateObject("ADODB.Stream") >> dwl_setup.vbs
  21. echo objADOStream.Open >> dwl_setup.vbs
  22. echo objADOStream.Type = 1 'adTypeBinary >> dwl_setup.vbs
  23. echo objADOStream.Write objXMLHTTP.ResponseBody >> dwl_setup.vbs
  24. echo objADOStream.Position = 0 >> dwl_setup.vbs
  25. echo Set objFso = Createobject("Scripting.FileSystemObject") >> dwl_setup.vbs
  26. echo If objFso.Fileexists(strSavePath) Then objFSO.DeleteFile strSavePath >> dwl_setup.vbs
  27. echo Set objFso = Nothing >> dwl_setup.vbs
  28. echo objADOStream.SaveToFile strSavePath >> dwl_setup.vbs
  29. echo objADOStream.Close >> dwl_setup.vbs
  30. echo Set objADOStream = Nothing >> dwl_setup.vbs
  31. echo End if >> dwl_setup.vbs
  32. echo Set objXMLHTTP = Nothing >> dwl_setup.vbs
  33. REM Advice
  34. echo DO NOT CLOSE THIS WINDOW YET.
  35. echo The setup process will continue once cygwin installation ends.
  36. REM start the download for Cygwin setup.exe
  37. dwl_setup.vbs
  38. REM start the setup for cygwin with the requiered repositories, paths and packages
  39. setup-x86.exe -K http://cygwinports.org/ports.gpg -s ftp://mirrors.kernel.org/sources.redhat.com/cygwinports -s ftp://ftp.gwdg.de/pub/linux/sources.redhat.com/cygwin --quiet-mode --packages screen --packages subversion --packages perl --packages wget --packages unzip --packages tar --packages gawk --packages pure-ftpd --packages screen --packages bzip2 --packages wget --packages zip --packages unzip --packages nano --packages rsync --root %WD% --local-package-dir %WD%cygTemp -P crypt -P csih -P diffutils -P gettext -P groff -P less -P libapr1 -P libaprutil1 -P libasn1_8 -P libattr1 -P libbz2_1 -P libcom_err2 -P libdb4.5 -P libdb4.8 -P libexpat1 -P libffi6 -P libgcc1 -P libgcrypt11 -P libgdbm4 -P libgmp10 -P libgmp3 -P libgnutls26 -P libgpg-error0 -P libgssapi3 -P libheimbase1 -P libheimntlm0 -P libhx509_5 -P libiconv2 -P libidn11 -P libintl8 -P libiodbc2 -P libkrb5_26 -P liblzma5 -P liblzo2_2 -P libmpfr4 -P libmysqlclient18 -P libncurses10 -P libncursesw10 -P libneon27 -P libopenldap2_4_2 -P libopenssl098 -P libopenssl100 -P libp11-kit0 -P libpcre0 -P libpopt0 -P libpq5 -P libproxy1 -P libroken18 -P libsasl2_3 -P libserf1_0 -P libsqlite3_0 -P libssp0 -P libstdc++6 -P libtasn1_3 -P libuuid1 -P libwind0 -P libxml2 -P openssl -P perl_vendor -P texinfo -P xz -P _autorebase -P _update-info-dir -P perl-Path-Class -P perl-YAML -P make -P libpcre1> cygwin_setup.log
  40. REM Set the needed enviroment variables to run Cygwin executables without writing the full path
  41. set path=%WD%\bin;%WD%\usr\sbin;%path%
  42. set SHELL=/bin/bash
  43. REM Create batch files to start and stop the agent
  44. echo @echo off> agent_start.bat
  45. echo set WD=%%~dp0>> agent_start.bat
  46. echo pushd %%WD%%>> agent_start.bat
  47. echo set path=%%WD%%bin;%%WD%%usr\sbin;%%path%%>> agent_start.bat
  48. echo set CYGWIN=server ntsec>> agent_start.bat
  49. echo set SHELL=/bin/bash>> agent_start.bat
  50. cp -f agent_start.bat agent_stop.bat
  51. echo set /p PID1=^<%%WD%%OGP\ogp_agent.pid>> agent_stop.bat
  52. echo kill -15 %%PID1%%>> agent_stop.bat
  53. echo set /p PID2=^<%%WD%%var\run\pure-ftpd.pid>> agent_stop.bat
  54. echo kill -15 %%PID2%%>> agent_stop.bat
  55. echo set /p PID3=^<%%WD%%OGP\ogp_agent_run.pid>> agent_stop.bat
  56. echo kill -15 %%PID3%%>> agent_stop.bat
  57. echo rm -Rf /OGP/.svn>> agent_start.bat
  58. echo rm -Rf /usr/bin/.svn>> agent_start.bat
  59. echo bash ogp_agent -pidfile /OGP/ogp_agent_run.pid>> agent_start.bat
  60. REM Create a vbs to run agent_start.bat hidden
  61. echo Dim strSavePath> agent_start_background.vbs
  62. echo strSavePath = CreateObject("Scripting.FileSystemObject").GetAbsolutePathName(".") ^& "\agent_start.bat">> agent_start_background.vbs
  63. echo CreateObject("Wscript.Shell").Run "" ^& strSavePath ^& "" , 0, false>> agent_start_background.vbs
  64. REM download the bash script that starts the agent setup
  65. echo Downloading the agent setup bash script from SVN ...
  66. svn co svn://svn.code.sf.net/p/hldstart/code/trunk/agent_win/bin bin
  67. chmod +x bin/ogp_install
  68. REM Asks for adding OGP agent to the system startup
  69. set /p ONBOOT= Start OGP agent at system boot[Y/n]:
  70. IF "X%ONBOOT%" == "X" (
  71. set ONBOOT=Y
  72. )
  73. IF "X%ONBOOT%" == "Xy" (
  74. set ONBOOT=Y
  75. )
  76. IF "X%ONBOOT%" == "XN" (
  77. set ONBOOT=n
  78. )
  79. IF "X%ONBOOT%" == "XY" (
  80. set /p PASS=please enter the password for user '%USERNAME%':
  81. schtasks /create /tn "OGP agent start on boot" /rl highest /ru %USERDOMAIN%\%USERNAME% /rp "%PASS%" /tr %WD%agent_start.bat /sc onstart
  82. ) ELSE (
  83. IF "X%ONBOOT%" == "Xn" (
  84. schtasks /delete /tn "OGP agent start on boot"
  85. )
  86. )
  87. REM run the agent setup
  88. bash -i ogp_install