home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / awgt1512.zip / install.cmd < prev    next >
OS/2 REXX Batch file  |  1999-07-25  |  14KB  |  428 lines

  1. /* REXX installation script for Auto WGet
  2.  * Copyright (C) 1998-1999 by Dmitry A.Steklenev
  3.  *
  4.  * $Revision: 1.5.1.2 $
  5.  */
  6.  
  7. call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
  8. call SysLoadFuncs
  9.  
  10. parse source os what program tail
  11. dll = substr( program, 1, lastpos( "\", program )) || "awget.dll"
  12.  
  13. call RxFuncAdd 'AwLoadFuncs', dll, 'AwLoadFuncs'
  14. call AwLoadFuncs
  15.  
  16. '@echo off'
  17.  
  18. if translate( value( "REXX_TRACE",, "OS2ENVIRONMENT" )) == "YES" then do
  19.    trace intermediate
  20.    trace results
  21. end
  22.  
  23. CfgFile = value( "ETC",, "OS2ENVIRONMENT" )"\awget.cfg"
  24.  
  25. /*------------------------------------------------------------------
  26.  * Initialization
  27.  *------------------------------------------------------------------*/
  28.  
  29. say "Auto WGet Daemon $Revision: 1.5.1.2 $ Installation"
  30. say "Copyright (C) 1998-1999 by Dmitry A.Steklenev"
  31. say ""
  32.  
  33. call MsgRead "awget"
  34.  
  35. if MsgYesNo( "!!! "msg.msg_instin" "directory()) == 0 then
  36.    exit
  37.  
  38. /*------------------------------------------------------------------
  39.  * Create configuration file
  40.  *------------------------------------------------------------------*/
  41.  
  42. call CfgRead CfgFile
  43.  
  44. if cfg.download == "." then do
  45.    call charout, "!!! "msg.msg_downdir": "
  46.    parse pull cfg.download
  47. end
  48.  
  49. if cfg.use_desktop == 0 then
  50.    cfg.use_desktop = (MsgYesNo( "!!! "msg.msg_usedesk ) == 1)
  51.  
  52. if cfg.logfile == "" then
  53.    cfg.logfile = directory()"\ToDo\Info\awget.log"
  54.  
  55. if cfg.errorlog == "" then
  56.    cfg.errorlog = directory()"\ToDo\Info\awget_error.log"
  57.  
  58. say; call CfgShow
  59. say; pause
  60. say
  61.  
  62. call CfgSave CfgFile
  63. say  "■■■ "msg.msg_updcfg": "CfgFile
  64.  
  65. /*------------------------------------------------------------------
  66.  * Create Folders and Objects
  67.  *------------------------------------------------------------------*/
  68.  
  69. if SysOs2Ver() > "2.30" then
  70.    FldClass = "WPUrlFolder"
  71. else
  72.    FldClass = "WPFolder"
  73.  
  74. call CreateObject FldClass  , "ToDo"   , directory() , "OBJECTID=<AWG_TODO>;"  ||,
  75.                   "ICONFILE="directory()"\icon\todo.ico;"                      ||,
  76.                   "DEFAULTVIEW=DETAILS;DETAILSTODISPLAY=0,1,7,8,12;DETAILSVIEW=NORMAL;", "U"
  77. call CreateObject "WPFolder", "Info"   , "<AWG_TODO>", "OBJECTID=<AWG_INFO>;"  ||,
  78.                   "ICONFILE="directory()"\icon\info.ico;"                      ||,
  79.                   "DEFAULTVIEW=ICON", "U"
  80. call CreateObject FldClass  , "Running", "<AWG_TODO>", "OBJECTID=<AWG_RUN>;"   ||,
  81.                   "ICONFILE="directory()"\icon\run.ico;"                       ||,
  82.                   "DEFAULTVIEW=DETAILS;DETAILSTODISPLAY=0,1,7,8,12;", "U"
  83. call CreateObject FldClass  , "Done"   , "<AWG_TODO>", "OBJECTID=<AWG_DONE>;"  ||,
  84.                   "ICONFILE="directory()"\icon\done.ico;"                      ||,
  85.                   "DEFAULTVIEW=DETAILS;DETAILSTODISPLAY=0,1,7,8,12;", "U"
  86. call CreateObject FldClass  , "Failed" , "<AWG_TODO>", "OBJECTID=<AWG_ERROR>;" ||,
  87.                   "ICONFILE="directory()"\icon\failed.ico;"                    ||,
  88.                   "DEFAULTVIEW=DETAILS;DETAILSTODISPLAY=0,1,7,8,12;", "U"
  89.  
  90. call CreateObject "WPShadow", "ToDo", "<WP_DESKTOP>",,
  91.                   "SHADOWID=<AWG_TODO>", "R"
  92.  
  93. call CreateObject "WPProgram", "Auto WGet Daemon", "<WP_START>",,
  94.                   "EXENAME="directory()"\AWGETD.CMD;MINIMIZED=YES;STARTUPDIR="directory()";" ||,
  95.                   "OBJECTID=<AWG_DAEMON>;ICONFILE="directory()"\icon\awget.ico;", "R"
  96. call CreateObject "WPProgram", "Add URL", "<AWG_INFO>",,
  97.                   "EXENAME="directory()"\AWGADD.CMD;MINIMIZED=YES;STARTUPDIR="directory()';PARAMETERS="['msg.msg_enterurl']";' ||,
  98.                   "OBJECTID=<AWG_ADD>;ICONFILE="directory()"\icon\add.ico;", "U"
  99. call CreateObject "WPProgram", "Uninstall Auto WGet Daemon", "<AWG_INFO>",,
  100.                   "EXENAME="directory()"\UNINSTL.CMD;STARTUPDIR="directory()";" ||,
  101.                   "OBJECTID=<AWG_DEINST>;ICONFILE="directory()"\icon\uninstl.ico;", "R"
  102.  
  103. call CreateObject "WPShadow", "ToDo", "<AWG_TODO>",,
  104.                   "SHADOWID=<AWG_ADD>;OBJECTID=<AWG_ADD_SHADOW>;", "R"
  105.  
  106. call CreateObject "WPProgram", "Readme (Russian)", "<AWG_INFO>" ,,
  107.                   'EXENAME=E.EXE;PROGTYPE=PM;PARAMETERS="'directory()'\AWGET.RUS"', "R"
  108. call CreateObject "WPProgram", "Readme (English)", "<AWG_INFO>" ,,
  109.                   'EXENAME=E.EXE;PROGTYPE=PM;PARAMETERS="'directory()'\AWGET.ENG"', "R"
  110. call CreateObject "WPProgram", "AWGet Configuration", "<AWG_INFO>" ,,
  111.                   'EXENAME=E.EXE;PROGTYPE=PM;PARAMETERS='CfgFile, "R"
  112.  
  113. if SysOs2Ver() > "2.30" then do
  114.    call CreateObject "WPUrl", "Auto WGet Daemon" || "0A"x || "Home Page (Russian)", "<AWG_INFO>",,
  115.                     "URL=http://www.geocities.com/SiliconValley/Vista/7567/software/index.html", "R"
  116.    call CreateObject "WPUrl", "Auto WGet Daemon" || "0A"x || "Home Page (English)", "<AWG_INFO>",,
  117.                     "URL=http://www.geocities.com/SiliconValley/Vista/7567/software/english/index.html", "R"
  118. end
  119.  
  120. if SysOs2Ver() > "2.30" then do
  121.    say
  122.    if MsgYesNo( "!!! "msg.msg_addtray ) == 1 then
  123.       call SysSetObjectData "<WP_WARPCENTER>", "ADDTRAY=Auto WGet Daemon,<AWG_TODO>,<AWG_INFO>,<AWG_ADD>"
  124.    say
  125. end
  126.  
  127. /*------------------------------------------------------------------
  128.  * Delete old files
  129.  *------------------------------------------------------------------*/
  130.  
  131. old.1 = directory()"\vwin.eng"
  132. old.2 = directory()"\vwin.exe"
  133. old.3 = directory()"\awget.ico"
  134. old.4 = directory()"\info.ico"
  135. old.5 = directory()"\awget.msg"
  136. old.0 = 5
  137.  
  138. do i = 1 to old.0
  139.    if stream( old.i, "c", "query exists" ) \= "" then do
  140.       '@del "'old.i'" 1> nul 2> nul'
  141.    end
  142. end
  143.  
  144. call SysDestroyObject "<AWG_LOCK>"
  145. call SysSetObjectData "<AWG_DAEMON>", "OPEN=DEFAULT"
  146.  
  147. say "■■■ "msg.msg_started
  148. say "Done!"
  149.  
  150. exit
  151.  
  152. /*------------------------------------------------------------------
  153.  * Create object
  154.  *------------------------------------------------------------------*/
  155. CreateObject: procedure expose msg.
  156.  
  157.    parse arg class, objname, folder, prmstr, action
  158.  
  159.    rc = SysCreateObject( class, objname, folder, prmstr, action )
  160.  
  161.    objname = translate( objname, " ", "0D"x )
  162.    objname = translate( objname, " ", "0A"x )
  163.  
  164.    if rc then
  165.       say "■■■ "msg.msg_objdone || " "substr(class,1,12) || ": "objname"..."
  166.    else
  167.       say "■■■ "msg.msg_objerr  || " "substr(class,1,12) || ": "objname"..."
  168.  
  169. return rc
  170.  
  171.  
  172. /*------------------------------------------------------------------
  173.  * National Messages Procedures
  174.  *------------------------------------------------------------------*/
  175. MsgRead: procedure expose msg.
  176.  
  177.   parse arg msgfile
  178.   parse source OS2 what msgpath
  179.  
  180.   msgfile = filespec( "disk", msgpath ) ||,
  181.             filespec( "path", msgpath ) || msgfile
  182.  
  183.   country = strip( SysIni( "BOTH", "PM_National", "iCountry" ),, '0'x )
  184.   country = right( country, 3, "0" )
  185.  
  186.   if stream( msgfile"."country, "c", "query exists" ) == "" then
  187.      country = "001"
  188.  
  189.   msgfile = msgfile"."country
  190.   rc = stream( msgfile, "C", "OPEN READ" )
  191.  
  192.   if rc \= "READY:" then do
  193.      say "ERROR: Error open message file: "msgfile
  194.      exit
  195.   end
  196.  
  197.   do while lines(msgfile) > 0
  198.      line = linein(msgfile)
  199.  
  200.      if line \= "" then do
  201.         parse value line with id "=" msg
  202.  
  203.         id  = translate(strip(id))
  204.         msg = strip(msg)
  205.  
  206.         i = pos( "\n", msg )
  207.         do while i > 0
  208.            msg = substr( msg, 1, i-1 ) || '0A0D'x || substr( msg, i+2 )
  209.            i = pos( "\n", msg )
  210.         end
  211.  
  212.         msg.id = msg
  213.      end
  214.   end
  215.  
  216.   rc = stream( msgfile, "C", "CLOSE" )
  217.  
  218. return
  219.  
  220. /*------------------------------------------------------------------
  221.  * Get Yes or No
  222.  *------------------------------------------------------------------*/
  223. MsgYesNo: procedure expose msg.
  224.  
  225.    parse arg prompt
  226.    ok = 0
  227.  
  228.    do until ok
  229.       call charout, prompt"? "
  230.       pull reply
  231.       reply = left(reply,1)
  232.  
  233.       ok = (reply == "Y") |,
  234.            (reply == "N") |,
  235.            (pos( reply, msg.msg_yes ) > 0 ) |,
  236.            (pos( reply, msg.msg_no  ) > 0 )
  237.  
  238.       if \ok then do
  239.          say msg.msg_badyn
  240.       end
  241.    end
  242.  
  243. return (reply = "Y") | (pos( reply, msg.msg_yes ) > 0 )
  244.  
  245. /*------------------------------------------------------------------
  246.  * Get Configuration
  247.  *------------------------------------------------------------------*/
  248. CfgRead: procedure expose cfg. msg.
  249.  
  250.   parse arg CfgFile
  251.  
  252.   cfg.download          = "."
  253.   cfg.maximum_downloads = 3
  254.   cfg.messages          = 1
  255.   cfg.message_done      = ""
  256.   cfg.message_error     = ""
  257.   cfg.wget_parameters   = "-c -t 0 -w 30"
  258.   cfg.scan_interval     = 60
  259.   cfg.check_connection  = 0
  260.   cfg.logfile           = ""
  261.   cfg.errorlog          = ""
  262.   cfg.use_desktop       = 0
  263.   cfg.keep_failed       = 1
  264.   cfg.keep_done         = 0
  265.  
  266.   rc = stream( CfgFile, "C", "OPEN READ" )
  267.  
  268.   do while lines(CfgFile) > 0
  269.      parse value linein(CfgFile) with command "=" argument
  270.  
  271.      command = translate(strip(command))
  272.      argument = strip(argument)
  273.  
  274.      select
  275.         when command == "DOWNLOAD" then
  276.              cfg.download = argument
  277.         when command == "MAXIMUM_DOWNLOADS_SIMULTANEOUSLY" then
  278.              cfg.maximum_downloads = argument
  279.         when command == "MESSAGES" then
  280.              cfg.messages = (argument == "1")
  281.         when command == "WGET_PARAMETERS" then
  282.              cfg.wget_parameters = argument
  283.         when command == "SCAN_INTERVAL" then
  284.              cfg.scan_interval = argument
  285.         when command == "LOG_FILE" then
  286.              cfg.logfile = argument
  287.         when command == "ERROR_LOG" then
  288.              cfg.errorlog = argument
  289.         when command == "MESSAGE_DONE" then
  290.              cfg.message_done = argument
  291.         when command == "MESSAGE_ERROR" then
  292.              cfg.message_error = argument
  293.         when command == "CHECK_CONNECTION" then
  294.              cfg.check_connection = (argument == "1")
  295.         when command == "USE_DESKTOP" then
  296.              cfg.use_desktop = (argument == "1")
  297.         when command == "KEEP_FAILED_URL" then
  298.              cfg.keep_failed = (argument == "1")
  299.         when command == "KEEP_DONE_URL" then
  300.              cfg.keep_done = (argument == "1")
  301.         otherwise
  302.      end
  303.   end
  304.  
  305.   if right( cfg.download, 1 ) = "\" then
  306.      cfg.download = left( cfg.download, length(cfg.download) - 1 )
  307.  
  308.   setlocal
  309.   cfg.download = directory( cfg.download )
  310.   endlocal
  311.  
  312.   if cfg.download == "" then do
  313.      call LogPut cfg.errorlog, msg.msg_invdown
  314.      cfg.download = "."
  315.   end
  316.  
  317.   rc = stream( CfgFile, "C", "CLOSE" )
  318.   cfg.file_date = stream( CfgFile, "C", "QUERY DATETIME" )
  319.  
  320. return
  321.  
  322. /*------------------------------------------------------------------
  323.  * Show Configuration
  324.  *------------------------------------------------------------------*/
  325. CfgShow: procedure expose cfg. msg.
  326.  
  327.   say "*** "msg.msg_downdir  || ": "cfg.download
  328.   say "*** "msg.msg_maxcon   || ": "cfg.maximum_downloads
  329.   say "*** "msg.msg_show     || ": "cfg.messages
  330.  
  331.   if cfg.message_done \= "" then
  332.      say "*** "msg.msg_done  || ": "cfg.message_done
  333.  
  334.   if cfg.message_error \= "" then
  335.      say "*** "msg.msg_error || ": "cfg.message_error
  336.  
  337.   say "*** "msg.msg_interval || ": "cfg.scan_interval
  338.   say "*** "msg.msg_chckconn || ": "cfg.check_connection
  339.   say "*** "msg.msg_parm     || ": "cfg.wget_parameters
  340.   say "*** "msg.msg_usedesk  || ": "cfg.use_desktop
  341.   say "*** "msg.msg_keepfail || ": "cfg.keep_failed
  342.   say "*** "msg.msg_keepdone || ": "cfg.keep_done
  343.  
  344. return
  345.  
  346. /*------------------------------------------------------------------
  347.  * Save Configuration
  348.  *------------------------------------------------------------------*/
  349. CfgSave: procedure expose cfg. msg.
  350.  
  351.   parse arg CfgFile
  352.  
  353.   if stream( CfgFile, "C", "QUERY EXISTS" ) \= "" then
  354.      "del "CfgFile
  355.  
  356.   rc = stream( CfgFile, "C", "OPEN WRITE" )
  357.  
  358.   rc = lineout( CfgFile, "download = "cfg.download )
  359.   rc = lineout( CfgFile, "maximum_downloads_simultaneously = "cfg.maximum_downloads )
  360.   rc = lineout( CfgFile, "messages = "cfg.messages )
  361.  
  362.   if cfg.message_done  \= "" then
  363.      rc = lineout( CfgFile, "message_done  = "cfg.message_done  )
  364.  
  365.   if cfg.message_error \= "" then
  366.      rc = lineout( CfgFile, "message_error = "cfg.message_error )
  367.  
  368.   rc = lineout( CfgFile, "log_file = "cfg.logfile )
  369.   rc = lineout( CfgFile, "error_log = "cfg.errorlog )
  370.   rc = lineout( CfgFile, "wget_parameters = "cfg.wget_parameters )
  371.   rc = lineout( CfgFile, "scan_interval = "cfg.scan_interval )
  372.   rc = lineout( CfgFile, "check_connection = "cfg.check_connection )
  373.   rc = lineout( CfgFile, "use_desktop = "cfg.use_desktop )
  374.   rc = lineout( CfgFile, "keep_failed_url = "cfg.keep_failed )
  375.   rc = lineout( CfgFile, "keep_done_url = "cfg.keep_done )
  376.  
  377.   rc = stream( CfgFile, "C", "CLOSE" )
  378.  
  379. return
  380.  
  381. /*------------------------------------------------------------------
  382.  * Check Configuration
  383.  *------------------------------------------------------------------*/
  384. CfgCheck: procedure expose cfg. msg.
  385.  
  386.   parse arg CfgFile
  387.  
  388.   if cfg.file_date \= stream( CfgFile, "C", "QUERY DATETIME" ) then do
  389.  
  390.      call LogPut cfg.logfile, msg.msg_readcfg
  391.      call CfgRead CfgFile
  392.      say
  393.      call CfgShow
  394.      say
  395.   end
  396.  
  397. return
  398.  
  399. /*------------------------------------------------------------------
  400.  * Write Log Record
  401.  *------------------------------------------------------------------*/
  402. LogPut: procedure expose cfg.
  403.  
  404.   parse arg logfile, message
  405.  
  406.   say "■■■ "message
  407.   if logfile \= "" then do
  408.      call lineout logfile, date()" "time()" -> "message
  409.      rc = stream( logfile, "c", "close" )
  410.   end
  411.  
  412. return
  413.  
  414. /*------------------------------------------------------------------
  415.  * Append Log Record
  416.  *------------------------------------------------------------------*/
  417. LogAdd: procedure expose cfg.
  418.  
  419.   parse arg logfile, message
  420.  
  421.   if logfile \= "" then do
  422.      call lineout logfile, date()" "time()" -> "message
  423.      rc = stream( logfile, "c", "close" )
  424.   end
  425.  
  426. return
  427.  
  428.