home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 29 Fixes_o / 29-Fixes_o.zip / updwebsu.exe / updwebx.cmd < prev   
OS/2 REXX Batch file  |  1996-11-12  |  19KB  |  582 lines

  1. /****************************************************************************/
  2. /* UPDWEBX 1.3             PSP Fix Distribution, Austin   11/12/1996        */
  3. /*                                                                          */
  4. /* Update IBM Web Explorer and/or Netscape Navigator to support RSU.        */
  5. /*                                                                          */
  6. /* IBM Web Explorer:                                                        */
  7. /* Make sure EXPLORE.INI is in the ETC (SET ETC=) directory.                */
  8. /* Locate Mailcap and Extmap entries                                        */
  9. /*   Exist - check Mailcap and Extmap for required entries.                 */
  10. /*     Exist - do nothing                                                   */
  11. /*     Need  - Read in existing Mailcap/Extmap file, add our entry.         */
  12. /*       R/O drive - write new Mailcap/Extmap file to ETC directory.        */
  13. /*                   update EXPLORE.INI to point to new file                */
  14. /*       R/W drive - delete old Mailcap/Extmap file                         */
  15. /*                   write new Mailcap/Extmap file                          */
  16. /*   Need - add Mailcap/Extmap entries to EXPLORE.INI                       */
  17. /*          write Mailcap/Extmap file with our required entries to the      */
  18. /*          ETC directory                                                   */
  19. /*                                                                          */
  20. /* Netscape Navigator:                                                      */
  21. /* If Netscape entry in OS2.INI then it's installed. Pull the install       */
  22. /* path from the key entry.                                                 */
  23. /* Change to Netscape directory                                             */
  24. /* Check NETSCAPE.INI for "Suffixes www/unknown" and "Viewers www/unknown"  */
  25. /* entries. If either there bail out and tell user to update manually.      */
  26. /*                                                                          */
  27. /* Add "Suffixes www/unknown rsu" and/or "Viewers www/unknown path" to      */
  28. /* NETSCAPE.INI as needed (path is the fully qualified path to where        */
  29. /* Netscape is installed.                                                   */
  30. /****************************************************************************/
  31. '@Echo off'
  32. ver='v1.3'
  33. Parse source whoami
  34. Parse value whoami with . . whoami
  35. call_path=Filespec('DRIVE',whoami)||Filespec('PATH',whoami)
  36. me=Filespec('NAME',whoami)
  37. Say me ver
  38.  
  39. curdir=Directory()        /* remember where we are */
  40. Arg op .
  41. If op='-?' | op='/?' | op='?' then
  42.   Signal Tell
  43.  
  44. /***********************************/
  45. /* Register all REXXUTIL functions */
  46. /***********************************/
  47. rc=RxFuncAdd('SysLoadFuncs', 'REXXUTIL', 'SysLoadFuncs')
  48. If rc>1 then
  49.   Do
  50.     Say 'Unable to register REXXUTIL functions.'
  51.     Signal Done
  52.   End
  53. Call SysLoadFuncs
  54.  
  55. /*****************************************************/
  56. /* Ask what is to be updated, WebX, Netscape or both */
  57. /* if Netscape is installed. Otherwise just do IBM   */
  58. /* WebX.                                             */
  59. /*****************************************************/
  60. updwebx=1
  61. updnetscape=0
  62. netscape=0
  63. x=SysIni('USER','ALL:','apps.')
  64. Do j=1 to apps.0
  65.   If translate(apps.j)='NETSCAPE' then
  66.     Do
  67.       netscape=1
  68.       x=SysIni('USER',apps.j,'ALL:','key.')
  69.       netscape_source=SysIni('USER',apps.j,key.1)   /* Where NS is installed */
  70.       Leave j
  71.     End
  72. End
  73.  
  74. ans=''
  75. If netscape then
  76.   Do
  77.     Say
  78.     Say 'Enter the number preceeding the Web browser you want to update.'
  79.     Say 'Press Enter without entering any data to exit now.'
  80.     Say
  81.     Say '1 IBM Web Explorer'
  82.     Say '2 Netscape Navigator'
  83.     Say '3 Both IBM Web Explorer and Netscape Navigator'
  84.     Do while ans=''
  85.       Pull ans .
  86.       If ans='' then
  87.         Signal Done
  88.       If wordpos(ans,'1 2 3')=0 then
  89.         Do
  90.           Say 'Invalid response ('ans'), try again.'
  91.           ans=''
  92.           Iterate
  93.         End
  94.     End
  95.     updwebx=ans=1 | ans=3
  96.     updnetscape=ans=2 | ans=3
  97.   End
  98.  
  99. /******************************/
  100. /* Make sure WebX or Netscape */
  101. /* are not running.           */
  102. /******************************/
  103. bail=0
  104. temp=SysTempFileName('@PSTAT@.???')
  105. '@PSTAT /C > 'temp
  106. Call Stream temp,'C','Open Read'
  107. Do while lines(temp)
  108.   line=translate(linein(temp))
  109.   If updwebx & pos('EXPLORE.EXE',line)>0 then
  110.     Do
  111.       Call Beep 262,400
  112.       Say
  113.       Say 'Shutdown IBM Web Explorer then rerun this program.'
  114.       bail=1
  115.     End
  116.   If updnetscape & pos('NETSCAPE.EXE',line)>0 then
  117.     Do
  118.       Call Beep 262,400
  119.       Say
  120.       Say 'Shutdown Netscape Navigator then rerun this program.'
  121.       bail=1
  122.     End
  123. End
  124. Call Stream temp,'C','Close'
  125. x=SysFileDelete(temp)
  126. If bail then
  127.   Signal Done
  128.  
  129. /***********************************/
  130. /* Setup some vars needed for both */
  131. /* WebX and Netscape.              */
  132. /***********************************/
  133. etc=value('ETC',,'OS2ENVIRONMENT')          /* Get location of ETC directory */
  134. If etc='' then
  135.   Do
  136.     Say 'SET ETC= not setup in your CONFIG.SYS.'me' cannot continue.'
  137.     Signal Done
  138.   End
  139. bin=substr(etc,1,length(etc)-3)||'BIN'
  140. rsuinst=bin||'\RSUINST.EXE'
  141. rsu_source=call_path||'RSUINST.EXE'
  142. unzip=bin||'\UNZIP.DLL'
  143. unzip_source=call_path||'UNZIP.DLL'
  144. rsuinst_done=0
  145. unzipdll_done=0
  146.  
  147. /****************************************/
  148. /* Update IBM Web Explorer if requested */
  149. /****************************************/
  150. If updwebx then
  151.   Do
  152.     Say
  153.     Say 'Checking IBM Web Explorer setup.'
  154.     Say
  155.     ini='EXPLORE.INI'
  156.     mailcap='MAILCAP'
  157.     extmap='EXTMAP'
  158.     Call Directory(etc)                           /* Change to etc directory */
  159.     If stream(ini,'C','Query Exists')='' then
  160.       Do
  161.         Say ini' not found in 'etc'. Cannot update IBM Web Explorer.'
  162.         Signal CheckNetscape
  163.       End
  164.  
  165.     /************************************************/
  166.     /* Now look for the MAILCAP and EXTMAP entries. */
  167.     /* Not there, add:                              */
  168.     /*   mailcap=etc\mailcap                        */
  169.     /*   extmap=etc\extmap                          */
  170.     /* There, do nothing                            */
  171.     /************************************************/
  172.     chk1='MAILCAP='
  173.     chk2='EXTMAP='
  174.     Parse value '' with mcpath empath .
  175.     update=0
  176.     Call stream ini,'C','Open Read'
  177.     Do j=1 while lines(ini)
  178.       line.j=linein(ini)
  179.       If left(translate(line.j),length(chk1))=chk1 then    /* Mailcap entry? */
  180.         Do
  181.           Parse value line.j with verb'='mcpath .
  182.           If mcpath='' then                      /* No path to Mailcap file? */
  183.             Do
  184.               mcpath=etc||'\MAILCAP'                   /* We will create one */
  185.               line.j=verb'='||mcpath
  186.               update=1
  187.               Iterate j
  188.             End
  189.         End
  190.       Else
  191.         If left(translate(line.j),length(chk2))=chk2 then   /* Extmap entry? */
  192.           Do
  193.             Parse value line.j with verb'='empath .
  194.             If empath='' then
  195.               Do
  196.                 empath=etc||'\EXTMAP'
  197.                 line.j=verb'='||empath
  198.                 update=1
  199.                 Iterate j
  200.               End
  201.           End
  202.     End
  203.     Call stream ini,'C','Close'
  204.  
  205.     /************************************/
  206.     /* Define paths if not already done */
  207.     /* If done check for R/W drive and  */
  208.     /* create local copy if not.        */
  209.     /************************************/
  210.     o=j-1
  211.     If mcpath='' then
  212.       Do
  213.         mcpath=etc||'\MAILCAP'
  214.         o=o+1
  215.         line.o='Mailcap='||mcpath
  216.         update=1
  217.       End
  218.     Else
  219.       If ChkRO(mcpath)<>0 then
  220.         Do
  221.           mcpathn=etc||'\MAILCAP'
  222.           Say mcpath 'located on R/O drive, creating local copy as'
  223.           Say mcpathn
  224.           '@COPY' mcpath mcpathn '>NUL'
  225.           mcpath=mcpathn
  226.           o=o+1
  227.           line.o='Mailcap='||mcpath
  228.           update=1
  229.         End
  230.     If empath='' then
  231.       Do
  232.         empath=etc||'\Extmap'
  233.         o=o+1
  234.         line.o='Extmap='||empath
  235.         update=1
  236.       End
  237.     Else
  238.       If ChkRO(empath)<>0 then
  239.         Do
  240.           empathn=etc||'\EXTMAP'
  241.           Say empath 'located on R/O drive, creating local copy as'
  242.           Say empathn
  243.           '@COPY' empath empathn '>NUL'
  244.           empath=empathn
  245.           o=o+1
  246.           line.o='Extmap='||empath
  247.           update=1
  248.         End
  249.  
  250.     /**************************************/
  251.     /* Update (backup, delete, write new) */
  252.     /* the ini file if needed.            */
  253.     /**************************************/
  254.     If update then
  255.       Do
  256.         backup=SysTempFileName('EXPLORE.???')
  257.         '@COPY 'ini backup' >NUL'
  258.         Say 'Saved 'ini' as 'backup
  259.         x=SysFileDelete(ini)
  260.         Call Stream ini,'C','Open Write'
  261.         Do j=1 to o
  262.           Call lineout ini,line.j
  263.         End
  264.         Call Stream ini,'C','Close'
  265.         Say 'Updated 'ini' with new/changed Mailcap and/or Extmap entries.'
  266.       End
  267.     Else
  268.       Say '"Mailcap" and "Extmap" entries already in 'ini
  269.  
  270.     /************************************/
  271.     /* Now we need to create/update the */
  272.     /* Mailcap/Extmap files to point to */
  273.     /* RSUINST.EXE                      */
  274.     /************************************/
  275.     mailcap=mcpath                               /* Point to new or old file */
  276.     extmap=empath                                                   /* Ditto */
  277.     found=0
  278.     chk=translate('APPLICATION/RSU; 'rsuinst' %S')
  279.     o=0
  280.     If stream(mailcap,'C','Query Exists')<>'' then                /* Exists? */
  281.       Do
  282.         Call Stream mailcap,'C','Open Read'
  283.         Do while lines(mailcap)
  284.           o=o+1
  285.           line.o=linein(mailcap)
  286.           If translate(space(line.o,1))=chk then
  287.             Do
  288.               found=1
  289.               Leave
  290.             End
  291.         End
  292.         Call Stream mailcap,'C','Close'
  293.       End
  294.     If \found then
  295.       Do
  296.         If stream(mailcap,'C','Query Exists')<>'' then
  297.           Do
  298.             backup=SysTempFileName('MAILCAP.???')
  299.             '@COPY 'mailcap backup' >NUL'
  300.             Say 'Saved 'mailcap' as 'backup
  301.             x=SysFileDelete(mailcap)
  302.           End
  303.         o=o+1
  304.         line.o=xlate(chk)
  305.         Call Stream mailcap,'C','Open Write'
  306.         Do j=1 to o
  307.           Call lineout mailcap,line.j
  308.         End
  309.         Call Stream mailcap,'C','Close'
  310.         Say 'Added 'xlate(chk)' to 'mailcap
  311.       End
  312.     Else
  313.       Say '"'xlate(chk)'" already in 'mailcap
  314.  
  315.     found=0
  316.     o=0
  317.     chk='APPLICATION/RSU RSU'
  318.     If stream(extmap,'C','Query Exists')<>'' then
  319.       Do
  320.         Call Stream extmap,'C','Open Read'
  321.         Do while lines(extmap)
  322.           o=o+1
  323.           line.o=linein(extmap)
  324.           If translate(space(line.o,1))=chk then
  325.             Do
  326.               found=1
  327.               Leave
  328.             End
  329.         End
  330.         Call Stream extmap,'C','Close'
  331.       End
  332.     If \found then
  333.       Do
  334.         If stream(extmap,'C','Query Exists')<>'' then
  335.           Do
  336.             backup=SysTempFileName('EXTMAP.???')
  337.             '@COPY 'extmap backup' >NUL'
  338.             Say 'Saved 'extmap' as 'backup
  339.             x=SysFileDelete(extmap)
  340.           End
  341.         o=o+1
  342.         line.o=xlate(chk)
  343.         Call Stream extmap,'C','Open Write'
  344.         Do j=1 to o
  345.           Call lineout extmap,line.j
  346.         End
  347.         Call Stream extmap,'C','Close'
  348.         Say 'Added 'xlate(chk)' to 'extmap
  349.       End
  350.     Else
  351.       Say '"'xlate(chk)'" already in 'extmap
  352.  
  353.     /*******************************************/
  354.     /* Now we copy RSUINST.EXE from the source */
  355.     /* directory to the target directory.      */
  356.     /*******************************************/
  357.     replace=stream(rsuinst,'C','Query Exists')<>''
  358.     '@COPY' rsu_source bin '>NUL'
  359.     If replace then
  360.       Say 'Replaced 'rsuinst
  361.     Else
  362.       Say 'Created 'rsuinst
  363.     rsuinst_done=1
  364.  
  365.     /*********************************************/
  366.     /* Finally we copy UNZIP.DLL from the source */
  367.     /* directory to the target directory.        */
  368.     /*********************************************/
  369.     replace=stream(unzip,'C','Query Exists')<>''
  370.     '@COPY' unzip_source bin '>NUL'
  371.     If replace then
  372.       Say 'Replaced 'unzip
  373.     Else
  374.       Say 'Created 'unzip
  375.     unzipdll_done=1
  376.  
  377.     /*******************************************/
  378.     /* Create an Icon on the Desktop to access */
  379.     /* Software Updates.                       */
  380.     /*******************************************/
  381.     Call directory curdir                    /* put us back where we started */
  382.     Call Rsuwp 'WEBX'
  383.   End                                                         /* Update Webx */
  384.  
  385. /**********************************/
  386. /* Now update Netscape if allowed */
  387. /**********************************/
  388. CheckNetscape:
  389. If updnetscape then
  390.   Do
  391.     Say
  392.     Say 'Checking Netscape Navigator setup.'
  393.     Say
  394.     Call Directory(netscape_source)
  395.     ini='netscape.ini'
  396.     If stream(ini,'C','Query Exists')='' then
  397.       Do
  398.         Say ini' not found, cannot update Netscape Navigator.'
  399.         Signal Done
  400.       End
  401.     If stream(ini,'C','Query Size')=0 then
  402.       Do
  403.         Say ini' size is 0. You must launch Netscape Navigator then'
  404.         Say 'shut it down once to create a complete 'ini' file.'
  405.         Signal Done
  406.       End
  407.     rsuinst='plugins\rsuinst.exe'
  408.     suffixes=0
  409.     x=SysIni(ini,'Suffixes','ALL:','apps.')
  410.     Do j=1 to apps.0
  411.       If translate(apps.j)='WWW/UNKNOWN' then
  412.         Do
  413.           If translate(SysIni(ini,'Suffixes',apps.j))='RSU' then
  414.             Do
  415.               Say 'Netscape "Suffixes www/unknown rsu" already',
  416.                   'registered.'
  417.               suffixes=2
  418.             End
  419.           Else
  420.             Do
  421.               Say 'Netscape "Suffixes www/unknown" already registered.'
  422.               Say 'You need to change the definition to "rsu".'
  423.               suffixes=1
  424.             End
  425.           Iterate j
  426.         End
  427.     End
  428.     viewers=0
  429.     x=SysIni(ini,'Viewers','ALL:','apps.')
  430.     maxtype=0
  431.     typedone=0
  432.     Do j=1 to apps.0
  433.       If translate(apps.j)='WWW/UNKNOWN' then
  434.         Do
  435.           If translate(SysIni(ini,'Viewers',apps.j))=translate(rsuinst) then
  436.             Do
  437.               Say 'Netscape "Viewers www/unknown 'rsuinst'" already',
  438.                   'registered.'
  439.               viewers=2
  440.             End
  441.           Else
  442.             Do
  443.               Say 'Netscape "Viewers www/unknown" already registered.'
  444.               Say 'You need to change the definition to "'rsuinst'".'
  445.               viewers=1
  446.             End
  447.           Iterate j
  448.         End
  449.       If left(translate(apps.j),4)='TYPE' then
  450.         Do
  451.           maxtype=max(maxtype,right(apps.j,1))
  452.           If translate(SysIni(ini,'Viewers',apps.j))='WWW/UNKNOWN' then
  453.             Do
  454.               Say 'Netscape "Viewers 'type' www/unknown" already registered.'
  455.               typedone=1
  456.             End
  457.           Iterate j
  458.         End
  459.     End
  460.     If suffixes=1 | viewers=1 then
  461.       Do
  462.         Say
  463.         Say 'Please follow the manual process outlined on the Web page'
  464.         Say 'if you want to use Service Updates with Netscape Navigator.'
  465.         Say
  466.       End
  467.     If suffixes=0 then
  468.       Do
  469.         x=Sysini(ini,'Suffixes','www/unknown','rsu')
  470.         Say 'Added "Suffixes www/unknown rsu" to 'ini
  471.       End
  472.     If viewers=0 then
  473.       Do
  474.         x=Sysini(ini,'Viewers','www/unknown',rsuinst)
  475.         Say 'Added "Viewers www/unknown 'rsuinst'" to 'ini
  476.       End
  477.     If \typedone then
  478.       Do
  479.         type='TYPE'||maxtype+1
  480.         x=Sysini(ini,'Viewers',type,'www/unknown')
  481.         Say 'Added "Viewers 'type' www/unknown" to 'ini
  482.       End
  483.  
  484.     /*******************************************/
  485.     /* Now we copy RSUINST.EXE from the source */
  486.     /* directory to the PLUGINS directory.     */
  487.     /*******************************************/
  488.     replace=stream(rsuinst,'C','Query Exists')<>''
  489.     '@COPY' rsu_source rsuinst' >NUL'
  490.     If replace then
  491.       Say 'Replaced 'rsuinst
  492.     Else
  493.       Say 'Created 'rsuinst
  494.  
  495.     /*********************************************/
  496.     /* Finally we copy UNZIP.DLL from the source */
  497.     /* directory to the target directory.        */
  498.     /*********************************************/
  499.     If \unzipdll_done then
  500.       Do
  501.         replace=stream(unzip,'C','Query Exists')<>''
  502.         '@COPY' unzip_source bin '>NUL'
  503.         If replace then
  504.           Say 'Replaced 'unzip
  505.         Else
  506.           Say 'Created 'unzip
  507.       End
  508.  
  509.       /*******************************************/
  510.       /* Create an Icon on the Desktop to access */
  511.       /* Software Updates.                       */
  512.       /*******************************************/
  513.       Call directory curdir                /* put us back where we started */
  514.       Call Rsuwp 'NETSCAPE'
  515.   End
  516.  
  517. /*********************/
  518. /* Cleanup and leave */
  519. /*********************/
  520. x=SysFileDelete(rsu_source)
  521. x=SysFileDelete('UPDWEBSU.EXE')
  522. x=SysFileDelete(me)
  523. x=SysFileDelete('RSUWP.CMD')
  524. x=SysFileDelete('UNZIP.DLL')
  525.  
  526. /*******************************/
  527. /* Only exit from this program */
  528. /* Cleanup then exit           */
  529. /*******************************/
  530. Done:
  531. Call directory curdir    /* put us back where we started */
  532. Exit
  533.  
  534. /***************************/
  535. /* Translate to lower case */
  536. /***************************/
  537. Xlate: Procedure
  538. Arg input
  539. lcase='abcdefghijklmnopqrstuvwxyz'
  540. ucase='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
  541. Return translate(input,lcase,ucase)
  542.  
  543. /***********************/
  544. /* See if drive is R/W */
  545. /***********************/
  546. ChkRO: Procedure
  547. Arg path
  548. path=Filespec('DRIVE',path)||Filespec('PATH',path)
  549. temp=SysTempFileName(path||'UPDWEBX.???')
  550. Call Stream temp,'C','Open Write'
  551. If Stream(temp,'S')<>'READY' then
  552.   retrc=1
  553. Else
  554.   Do
  555.     Call Stream temp,'C','Close'
  556.     x=SysFileDelete(temp)
  557.     retrc=0
  558.   End
  559. Return retrc
  560.  
  561. /**************************************/
  562. /* Display help info for this program */
  563. /**************************************/
  564. Tell:
  565. Say 'Form: UPDWEBX'
  566. Say
  567. Say 'Will update IBM Web Explorer and/or Netscape Navigator to add support for'
  568. Say 'the Service Updates (RSU) tool for applying fixes from the Internet'
  569. Say 'directly to your system.'
  570. Say
  571. Say 'IBM Web Explorer'
  572. Say 'Adds/updates EXPLORE.INI and associated Mailcap/Extmap files.'
  573. Say 'Adds/updates RSUINST.EXE to BIN directory.'
  574. Say
  575. Say 'Netscape Navigator'
  576. Say 'Adds the Suffixes and Viewers entries to NETSCAPE.INI.'
  577. Say 'Adds/updates RSUINST.EXE to PLUGINS directory.'
  578. Say
  579. Say 'Also creates a Program Object (Icon) on your Desktop for each of the'
  580. Say 'above if they are updated.'
  581. Signal Done
  582.