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

  1. /* REXX deinstallation script for Auto WGet Daemon
  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: uninstl.cms,v 1.21 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. cls ; call AwInit
  49.  
  50. say color.bold  || "Auto WGet Daemon " || color.usual || "Version 1.6.9 Deinstallation"
  51. say color.usual || "Copyright (C) 1998-2001 Dmitry A.Steklenev"
  52. say color.usual || ""
  53.  
  54. call MsgRead "awgmsg"
  55. call CfgRead
  56.  
  57. call LogDo err, msg.uninstal_warning
  58. say  ""
  59.  
  60. if MsgYesNo( ">>> "msg.uninstal ) == 0 then
  61.    exit 0
  62.  
  63. remove_config = MsgYesNo( ">>> "msg.remove_config" "sys.config_file )
  64.  
  65. say ""
  66. say AwStop()
  67.  
  68. call SysFileTree "NLS\*", 'erase', 'FO'
  69. do i = 1 to erase.0
  70.    call DeleteFile "NLS\"filespec( "name", erase.i )
  71. end
  72. call SysFileTree "Plugins\*", 'erase', 'FO'
  73. do i = 1 to erase.0
  74.    call DeleteFile "Plugins\"filespec( "name", erase.i )
  75. end
  76. call SysFileTree "Icons\*", 'erase', 'FO'
  77. do i = 1 to erase.0
  78.    call DeleteFile "Icons\"filespec( "name", erase.i )
  79. end
  80. call SysFileTree "*", 'erase', 'FO'
  81. do i = 1 to erase.0
  82.    call DeleteFile filespec( "name", erase.i )
  83. end
  84.  
  85. call DeleteObject "<AWG2_JOBS>"
  86. call DeleteObject "<AWG2_RUNNING>"
  87. call DeleteObject "<AWG2_DONE>"
  88. call DeleteObject "<AWG2_FAILED>"
  89. call DeleteObject "<AWG2_TODO>"
  90. call DeleteObject "<AWG2_DAEMON>"
  91.  
  92. call DeleteDirectory "NLS"
  93. call DeleteDirectory "Icons"
  94. call DeleteDirectory "Plugins"
  95. call DeleteDirectory "Folders"
  96. call directory ".."
  97. call DeleteDirectory cfg.home
  98.  
  99. if remove_config then
  100.    call DeleteFile sys.config_file
  101.  
  102. call DeleteObject "<AWG2_HOME>"
  103. call LogDo inf, "Done!"
  104. say; pause
  105. exit 0
  106.  
  107. /*------------------------------------------------------------------
  108.  * Delete file
  109.  *------------------------------------------------------------------*/
  110. DeleteFile: procedure expose (globals)
  111.  
  112.  parse arg file
  113.  "del "file" 1> nul 2>nul"
  114.  
  115.  if rc == 0 then
  116.     call LogDo inf, msg.erase_done  || ": "file
  117.  else
  118.     call LogDo err, msg.erase_error || ": "file", rc="rc
  119. return rc == 0
  120.  
  121. /*------------------------------------------------------------------
  122.  * Remove directory
  123.  *------------------------------------------------------------------*/
  124. DeleteDirectory: procedure expose (globals)
  125.  
  126.  parse arg path
  127.  rc = SysRmDir(path)
  128.  
  129.  if rc == 0 then
  130.     call LogDo inf, msg.erase_done  || ": "path
  131.  else
  132.     call LogDo err, msg.erase_error || ": "path", rc="rc
  133. return rc == 0
  134.  
  135. /*------------------------------------------------------------------
  136.  * Delete WPS object
  137.  *------------------------------------------------------------------*/
  138. DeleteObject: procedure expose (globals)
  139.  
  140.  parse arg id
  141.  rc = SysDestroyObject( id )
  142.  
  143.  if rc then
  144.     call LogDo inf, msg.erase_done  || ": "id
  145.  else
  146.     call LogDo err, msg.erase_error || ": "id
  147. return rc
  148.  
  149. /*------------------------------------------------------------------
  150.  * Display Log Record
  151.  *------------------------------------------------------------------*/
  152. LogDo: procedure expose (globals)
  153.  
  154.   parse arg type, message
  155.   type = translate(type)
  156.  
  157.   if type == "INF" then type = "INFO"
  158.   if type == "ERR" then type = "ERROR"
  159.  
  160.   if type == "ERROR" then
  161.      call beep 1000, 100
  162.  
  163.   say color.type"■■■ " ||,
  164.       replace( message, '0D0A'x, '0D0A'x || copies( ' ', 4 )) || color.usual
  165.  
  166. return ""
  167.  
  168. /* $Id: init.cms,v 1.26 2001/05/11 09:45:01 glass Exp $ */
  169.  
  170. /*------------------------------------------------------------------
  171.  * Initialization
  172.  *------------------------------------------------------------------*/
  173. AwInit: procedure expose (globals)
  174.  
  175.   if RxFuncQuery('SysLoadFuncs') then do
  176.      call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
  177.      call SysLoadFuncs
  178.   end
  179.  
  180.   '@echo off'
  181.  
  182.   sys.config_file = value( "ETC",, "OS2ENVIRONMENT" )"\awget.cfg"
  183.   sys.connected   = 1
  184.   sys.active_time = 0
  185.  
  186.   /* enable ANSI extended screen and keyboard control */
  187.   '@ansi on > nul'
  188.  
  189.   color.brown   = "1B"x"[0;33m"
  190.   color.red     = "1B"x"[1;31m"
  191.   color.green   = "1B"x"[1;32m"
  192.   color.yellow  = "1B"x"[1;33m"
  193.   color.blue    = "1B"x"[1;34m"
  194.   color.magenta = "1B"x"[1;35m"
  195.   color.cyan    = "1B"x"[1;36m"
  196.   color.white   = "1B"x"[1;37m"
  197.   color.gray    = "1B"x"[0m"
  198.  
  199.   color.usual   = color.gray
  200.   color.bold    = color.white
  201.   color.error   = color.red
  202.   color.info    = color.green
  203.   color.debug   = color.brown
  204.  
  205.   /* known download utilites */
  206.  
  207.   sys.utils.0      = 2
  208.   sys.utils.1.prog = wget.exe
  209.   sys.utils.1.name = "GNU WGet"
  210.   sys.utils.1.parm = '-c -t 10 -w 30 -P "%p" "%u"'
  211.   sys.utils.2.prog = curl.exe
  212.   sys.utils.2.name = "cURL"
  213.   sys.utils.2.parm = '-y 300 -Y 1 -v -C - -o "%p/%f" "%u"'
  214.  
  215.   sys.utils.default.prog = sys.utils.1.prog
  216.   sys.utils.default.name = sys.utils.1.name
  217.   sys.utils.default.parm = sys.utils.1.parm
  218.  
  219.   /* service semaphores */
  220.  
  221.   sys.running = "$live$"
  222.   sys.killing = "$stop$"
  223.   sys.pushing = "$push$"
  224.   sys.tqueue  = "$term$"
  225.  
  226.   /* stream's open modes */
  227.  
  228.   parse version version .
  229.   if version = "OBJREXX" then do
  230.      sys.open_read  = "OPEN READ  SHAREREAD"
  231.      sys.open_write = "OPEN WRITE SHAREREAD"
  232.      end
  233.   else do
  234.      sys.open_read  = "OPEN READ"
  235.      sys.open_write = "OPEN WRITE"
  236.   end
  237. return
  238.  
  239. /* $Id: nls.cms,v 1.13 2001/05/11 08:54:34 glass Exp $ */
  240.  
  241. /*------------------------------------------------------------------
  242.  * Read messages
  243.  *------------------------------------------------------------------*/
  244. MsgRead: procedure expose (globals)
  245.  
  246.   parse arg msgfile
  247.   parse source OS2 what msgpath
  248.  
  249.   msgfile = filespec( "disk", msgpath ) ||,
  250.             filespec( "path", msgpath ) || "NLS\" || msgfile
  251.  
  252.   country = MsgCountryID()
  253.  
  254.   if stream( msgfile"."country, "c", "query exists" ) == "" then
  255.      country = "001"
  256.  
  257.   msgfile = msgfile"."country
  258.   rc = stream( msgfile, "C", sys.open_read )
  259.  
  260.   if rc \= "READY:" then do
  261.      say  color.error || "■■■ Error on open NLS file: "msgfile
  262.      exit 1
  263.   end
  264.  
  265.   do while lines(msgfile) > 0
  266.      line = strip(linein(msgfile))
  267.  
  268.      do while right(line,1) == "\"
  269.         line = left( line, length(line)-1 )
  270.         line = line || strip(linein(msgfile))
  271.      end
  272.  
  273.      if line \= "" & left(line,1) \= "#" then do
  274.         parse value line with id "=" msg
  275.  
  276.         id  = strip(id )
  277.         msg = strip(msg)
  278.  
  279.         i = pos( "\n", msg )
  280.         do while i > 0
  281.            msg = substr( msg, 1, i-1 ) || '0D0A'x || substr( msg, i+2 )
  282.            i = pos( "\n", msg )
  283.         end
  284.  
  285.         msg.id = msg
  286.      end
  287.   end
  288.  
  289.   rc = stream( msgfile, "C", "CLOSE" )
  290. return
  291.  
  292. /*------------------------------------------------------------------
  293.  * Returns Country Identifier
  294.  *------------------------------------------------------------------*/
  295. MsgCountryID: procedure expose (globals)
  296.  
  297.   country = strip( SysIni( "BOTH", "PM_National", "iCountry" ),, '0'x )
  298.  
  299.   if country == "ERROR:" then
  300.      country =  "001"
  301.   else
  302.      country =  right( country, 3, "0" )
  303.  
  304. return country
  305.  
  306. /*------------------------------------------------------------------
  307.  * Get Yes or No
  308.  *------------------------------------------------------------------*/
  309. MsgYesNo: procedure expose (globals)
  310.  
  311.   parse arg prompt
  312.   ok = 0
  313.  
  314.   do until ok
  315.      call charout, prompt"? "
  316.      pull reply
  317.      reply = left(reply,1)
  318.  
  319.      ok = (reply == "Y") |,
  320.           (reply == "N") |,
  321.           (pos( reply, msg.yes ) > 0 ) |,
  322.           (pos( reply, msg.no  ) > 0 )
  323.  
  324.      if \ok then do
  325.         say msg.bad_yesno
  326.      end
  327.   end
  328.  
  329. return (reply = "Y") | ( pos( reply, msg.yes ) > 0 )
  330.  
  331.  
  332. /* $Id: config.cms,v 1.29 2001/05/11 08:54:34 glass Exp $ */
  333.  
  334. /*------------------------------------------------------------------
  335.  * Get Configuration
  336.  *------------------------------------------------------------------*/
  337. CfgRead: procedure expose (globals)
  338.  
  339.   cfg.home                     = "."
  340.   cfg.download                 = "."
  341.   cfg.downloads_simultaneously = 3
  342.   cfg.downloads_attempts       = 15
  343.   cfg.downloads_utility        = sys.utils.default.prog
  344.   cfg.downloads_parameters     = sys.utils.default.parm
  345.   cfg.scan_interval            = 30
  346.   cfg.log_file                 = "nul"
  347.   cfg.error_log                = "nul"
  348.   cfg.log_keep                 = 15
  349.   cfg.message_done             = 'start /n pmpopup2.exe "%m:~~%u" "Auto WGet Daemon" /BELL /B1:"OK" /T:900 /F:"8.Helv"'
  350.   cfg.message_error            = 'start /n pmpopup2.exe "%m:~~%u~%i" "Auto WGet Daemon" /BELL /B1:"OK" /T:900 /F:"8.Helv"'
  351.   cfg.messages                 = 1
  352.   cfg.check_connection         = 0
  353.   cfg.use_desktop              = 0
  354.   cfg.keep_failed_url          = 1
  355.   cfg.keep_done_url            = 0
  356.  
  357.   rc = stream( sys.config_file, "C", sys.open_read )
  358.  
  359.   do while lines(sys.config_file) > 0
  360.      parse value linein(sys.config_file) with command "=" argument
  361.  
  362.      command  = translate(strip(command))
  363.      argument = strip(argument)
  364.  
  365.      select
  366.         when command == "HOME",
  367.            | command == "DOWNLOAD",
  368.            | command == "DOWNLOADS_SIMULTANEOUSLY",
  369.            | command == "DOWNLOADS_ATTEMPTS",
  370.            | command == "DOWNLOADS_UTILITY",
  371.            | command == "DOWNLOADS_PARAMETERS",
  372.            | command == "SCAN_INTERVAL",
  373.            | command == "LOG_FILE",
  374.            | command == "ERROR_LOG",
  375.            | command == "LOG_KEEP",
  376.            | command == "MESSAGE_DONE",
  377.            | command == "MESSAGE_ERROR" then
  378.  
  379.              cfg.command = argument
  380.  
  381.         when command == "MESSAGES",
  382.            | command == "CHECK_CONNECTION",
  383.            | command == "USE_DESKTOP",
  384.            | command == "KEEP_FAILED_URL",
  385.            | command == "KEEP_DONE_URL" then
  386.  
  387.              cfg.command = (argument == "1")
  388.         otherwise
  389.      end
  390.   end
  391.  
  392.   rc = stream( sys.config_file, "C", "CLOSE" )
  393.   cfg.file_date = stream( sys.config_file, "C", "QUERY DATETIME" )
  394. return
  395.  
  396.  
  397. /* $Id: replace.cms,v 1.5 2001/05/11 08:54:34 glass Exp $ */
  398.  
  399. /*------------------------------------------------------------------
  400.  * Search and replace string
  401.  *------------------------------------------------------------------*/
  402. replace: procedure expose (globals)
  403.  
  404.   parse arg source, string, substitute
  405.   string = translate(string)
  406.  
  407.   i = pos( string, translate(source))
  408.  
  409.   do while i \= 0
  410.      source = substr( source, 1, i-1 ) || substitute ||,
  411.               substr( source, i+length(string))
  412.  
  413.      i = pos( string, translate(source), i + length(substitute))
  414.   end
  415.  
  416. return source
  417.  
  418. /* $Id: stop.cms,v 1.13 2001/05/11 08:54:34 glass Exp $ */
  419.  
  420. /*------------------------------------------------------------------
  421.  * Stop Auto WGet Daemon
  422.  *------------------------------------------------------------------*/
  423. AwStop: procedure expose (globals)
  424.  
  425.   sys_running  = cfg.home'\'sys.running
  426.   sys_killing  = cfg.home'\'sys.killing
  427.  
  428.   'del 'sys_running' /F 1>nul 2>nul'
  429.  
  430.   call lineout sys_killing, "Must die!"
  431.   call charout, color.info || "■■■ "msg.wait_stopped"..."
  432.  
  433.   do 20 while stream( sys_running, 'c', 'query exist' ) \= ""
  434.      call SysSleep  2
  435.      call charout, "."
  436.     'del 'sys_running' /F 1>nul 2>nul'
  437.   end
  438.   say ; say color.info || "■■■ "msg.stopped || color.usual
  439.  
  440.   rc = stream( sys_killing, 'c', 'close' )
  441.  'del 'sys_killing' /F 1>nul 2>nul'
  442.  
  443. return ""
  444.