home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / awget169.zip / awgstop.cmd < prev    next >
OS/2 REXX Batch file  |  2001-07-17  |  9KB  |  291 lines

  1. /* Auto WGet Daemon Termination
  2.  * Copyright (C) 1999-2001 Dmitry A.Steklenev
  3.  *
  4.  * Redistribution and use in source and binary forms, with or without
  5.  * modification, are permitted provided that the following conditions
  6.  * are met:
  7.  *
  8.  * 1. Redistributions of source code must retain the above copyright
  9.  *    notice, this list of conditions and the following disclaimer.
  10.  *
  11.  * 2. Redistributions in binary form must reproduce the above copyright
  12.  *    notice, this list of conditions and the following disclaimer in
  13.  *    the documentation and/or other materials provided with the
  14.  *    distribution.
  15.  *
  16.  * 3. All advertising materials mentioning features or use of this
  17.  *    software must display the following acknowledgment:
  18.  *    "This product includes software developed by Dmitry A.Steklenev".
  19.  *
  20.  * 4. Redistributions of any form whatsoever must retain the following
  21.  *    acknowledgment:
  22.  *    "This product includes software developed by Dmitry A.Steklenev".
  23.  *
  24.  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR OR CONTRIBUTORS "AS IS"
  25.  * AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  26.  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  27.  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  28.  * AUTHOR OR THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  29.  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  30.  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  31.  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  32.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  33.  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  34.  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  35.  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  36.  *
  37.  * $Id: awgstop.cms,v 1.13 2001/05/11 08:54:33 glass Exp $
  38.  */
  39.  
  40. globals = "cfg. local. msg. sys. color. dir. jobs. job. plugins."
  41.  
  42. if translate( value( "AWGET_TRACE",, "OS2ENVIRONMENT" )) == "YES" then do
  43.    call  value "AWGET_TRACE", "", "OS2ENVIRONMENT"
  44.    trace intermediate
  45.    trace results
  46. end
  47.  
  48. call AwInit
  49.  
  50. cls
  51. say color.bold  || "Auto WGet Daemon " || color.usual || "Version 1.6.9 Termination"
  52. say color.usual || "Copyright (C) 1999-2001 Dmitry A.Steklenev"
  53. say color.usual || ""
  54.  
  55. call MsgRead "awgmsg"
  56. call CfgRead
  57. call AwStop
  58.  
  59. exit 0
  60.  
  61. /* $Id: init.cms,v 1.26 2001/05/11 09:45:01 glass Exp $ */
  62.  
  63. /*------------------------------------------------------------------
  64.  * Initialization
  65.  *------------------------------------------------------------------*/
  66. AwInit: procedure expose (globals)
  67.  
  68.   if RxFuncQuery('SysLoadFuncs') then do
  69.      call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
  70.      call SysLoadFuncs
  71.   end
  72.  
  73.   '@echo off'
  74.  
  75.   sys.config_file = value( "ETC",, "OS2ENVIRONMENT" )"\awget.cfg"
  76.   sys.connected   = 1
  77.   sys.active_time = 0
  78.  
  79.   /* enable ANSI extended screen and keyboard control */
  80.   '@ansi on > nul'
  81.  
  82.   color.brown   = "1B"x"[0;33m"
  83.   color.red     = "1B"x"[1;31m"
  84.   color.green   = "1B"x"[1;32m"
  85.   color.yellow  = "1B"x"[1;33m"
  86.   color.blue    = "1B"x"[1;34m"
  87.   color.magenta = "1B"x"[1;35m"
  88.   color.cyan    = "1B"x"[1;36m"
  89.   color.white   = "1B"x"[1;37m"
  90.   color.gray    = "1B"x"[0m"
  91.  
  92.   color.usual   = color.gray
  93.   color.bold    = color.white
  94.   color.error   = color.red
  95.   color.info    = color.green
  96.   color.debug   = color.brown
  97.  
  98.   /* known download utilites */
  99.  
  100.   sys.utils.0      = 2
  101.   sys.utils.1.prog = wget.exe
  102.   sys.utils.1.name = "GNU WGet"
  103.   sys.utils.1.parm = '-c -t 10 -w 30 -P "%p" "%u"'
  104.   sys.utils.2.prog = curl.exe
  105.   sys.utils.2.name = "cURL"
  106.   sys.utils.2.parm = '-y 300 -Y 1 -v -C - -o "%p/%f" "%u"'
  107.  
  108.   sys.utils.default.prog = sys.utils.1.prog
  109.   sys.utils.default.name = sys.utils.1.name
  110.   sys.utils.default.parm = sys.utils.1.parm
  111.  
  112.   /* service semaphores */
  113.  
  114.   sys.running = "$live$"
  115.   sys.killing = "$stop$"
  116.   sys.pushing = "$push$"
  117.   sys.tqueue  = "$term$"
  118.  
  119.   /* stream's open modes */
  120.  
  121.   parse version version .
  122.   if version = "OBJREXX" then do
  123.      sys.open_read  = "OPEN READ  SHAREREAD"
  124.      sys.open_write = "OPEN WRITE SHAREREAD"
  125.      end
  126.   else do
  127.      sys.open_read  = "OPEN READ"
  128.      sys.open_write = "OPEN WRITE"
  129.   end
  130. return
  131.  
  132. /* $Id: nls.cms,v 1.13 2001/05/11 08:54:34 glass Exp $ */
  133.  
  134. /*------------------------------------------------------------------
  135.  * Read messages
  136.  *------------------------------------------------------------------*/
  137. MsgRead: procedure expose (globals)
  138.  
  139.   parse arg msgfile
  140.   parse source OS2 what msgpath
  141.  
  142.   msgfile = filespec( "disk", msgpath ) ||,
  143.             filespec( "path", msgpath ) || "NLS\" || msgfile
  144.  
  145.   country = MsgCountryID()
  146.  
  147.   if stream( msgfile"."country, "c", "query exists" ) == "" then
  148.      country = "001"
  149.  
  150.   msgfile = msgfile"."country
  151.   rc = stream( msgfile, "C", sys.open_read )
  152.  
  153.   if rc \= "READY:" then do
  154.      say  color.error || "■■■ Error on open NLS file: "msgfile
  155.      exit 1
  156.   end
  157.  
  158.   do while lines(msgfile) > 0
  159.      line = strip(linein(msgfile))
  160.  
  161.      do while right(line,1) == "\"
  162.         line = left( line, length(line)-1 )
  163.         line = line || strip(linein(msgfile))
  164.      end
  165.  
  166.      if line \= "" & left(line,1) \= "#" then do
  167.         parse value line with id "=" msg
  168.  
  169.         id  = strip(id )
  170.         msg = strip(msg)
  171.  
  172.         i = pos( "\n", msg )
  173.         do while i > 0
  174.            msg = substr( msg, 1, i-1 ) || '0D0A'x || substr( msg, i+2 )
  175.            i = pos( "\n", msg )
  176.         end
  177.  
  178.         msg.id = msg
  179.      end
  180.   end
  181.  
  182.   rc = stream( msgfile, "C", "CLOSE" )
  183. return
  184.  
  185. /*------------------------------------------------------------------
  186.  * Returns Country Identifier
  187.  *------------------------------------------------------------------*/
  188. MsgCountryID: procedure expose (globals)
  189.  
  190.   country = strip( SysIni( "BOTH", "PM_National", "iCountry" ),, '0'x )
  191.  
  192.   if country == "ERROR:" then
  193.      country =  "001"
  194.   else
  195.      country =  right( country, 3, "0" )
  196.  
  197. return country
  198.  
  199.  
  200. /* $Id: config.cms,v 1.29 2001/05/11 08:54:34 glass Exp $ */
  201.  
  202. /*------------------------------------------------------------------
  203.  * Get Configuration
  204.  *------------------------------------------------------------------*/
  205. CfgRead: procedure expose (globals)
  206.  
  207.   cfg.home                     = "."
  208.   cfg.download                 = "."
  209.   cfg.downloads_simultaneously = 3
  210.   cfg.downloads_attempts       = 15
  211.   cfg.downloads_utility        = sys.utils.default.prog
  212.   cfg.downloads_parameters     = sys.utils.default.parm
  213.   cfg.scan_interval            = 30
  214.   cfg.log_file                 = "nul"
  215.   cfg.error_log                = "nul"
  216.   cfg.log_keep                 = 15
  217.   cfg.message_done             = 'start /n pmpopup2.exe "%m:~~%u" "Auto WGet Daemon" /BELL /B1:"OK" /T:900 /F:"8.Helv"'
  218.   cfg.message_error            = 'start /n pmpopup2.exe "%m:~~%u~%i" "Auto WGet Daemon" /BELL /B1:"OK" /T:900 /F:"8.Helv"'
  219.   cfg.messages                 = 1
  220.   cfg.check_connection         = 0
  221.   cfg.use_desktop              = 0
  222.   cfg.keep_failed_url          = 1
  223.   cfg.keep_done_url            = 0
  224.  
  225.   rc = stream( sys.config_file, "C", sys.open_read )
  226.  
  227.   do while lines(sys.config_file) > 0
  228.      parse value linein(sys.config_file) with command "=" argument
  229.  
  230.      command  = translate(strip(command))
  231.      argument = strip(argument)
  232.  
  233.      select
  234.         when command == "HOME",
  235.            | command == "DOWNLOAD",
  236.            | command == "DOWNLOADS_SIMULTANEOUSLY",
  237.            | command == "DOWNLOADS_ATTEMPTS",
  238.            | command == "DOWNLOADS_UTILITY",
  239.            | command == "DOWNLOADS_PARAMETERS",
  240.            | command == "SCAN_INTERVAL",
  241.            | command == "LOG_FILE",
  242.            | command == "ERROR_LOG",
  243.            | command == "LOG_KEEP",
  244.            | command == "MESSAGE_DONE",
  245.            | command == "MESSAGE_ERROR" then
  246.  
  247.              cfg.command = argument
  248.  
  249.         when command == "MESSAGES",
  250.            | command == "CHECK_CONNECTION",
  251.            | command == "USE_DESKTOP",
  252.            | command == "KEEP_FAILED_URL",
  253.            | command == "KEEP_DONE_URL" then
  254.  
  255.              cfg.command = (argument == "1")
  256.         otherwise
  257.      end
  258.   end
  259.  
  260.   rc = stream( sys.config_file, "C", "CLOSE" )
  261.   cfg.file_date = stream( sys.config_file, "C", "QUERY DATETIME" )
  262. return
  263.  
  264.  
  265. /* $Id: stop.cms,v 1.13 2001/05/11 08:54:34 glass Exp $ */
  266.  
  267. /*------------------------------------------------------------------
  268.  * Stop Auto WGet Daemon
  269.  *------------------------------------------------------------------*/
  270. AwStop: procedure expose (globals)
  271.  
  272.   sys_running  = cfg.home'\'sys.running
  273.   sys_killing  = cfg.home'\'sys.killing
  274.  
  275.   'del 'sys_running' /F 1>nul 2>nul'
  276.  
  277.   call lineout sys_killing, "Must die!"
  278.   call charout, color.info || "■■■ "msg.wait_stopped"..."
  279.  
  280.   do 20 while stream( sys_running, 'c', 'query exist' ) \= ""
  281.      call SysSleep  2
  282.      call charout, "."
  283.     'del 'sys_running' /F 1>nul 2>nul'
  284.   end
  285.   say ; say color.info || "■■■ "msg.stopped || color.usual
  286.  
  287.   rc = stream( sys_killing, 'c', 'close' )
  288.  'del 'sys_killing' /F 1>nul 2>nul'
  289.  
  290. return ""
  291.