home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / ijgwy1_0.zip / install.cmd < prev    next >
OS/2 REXX Batch file  |  1998-12-01  |  17KB  |  697 lines

  1. /*
  2. ** Module   :INSTALL.CMD
  3. ** Abstract :Installation script for FXWRAP.SYS
  4. **
  5. ** Copyright (C) F/X Communications
  6. **
  7. ** Log: Sat  17/10/1998 Created
  8. **
  9. */
  10. level=1
  11.  
  12. '@echo off'
  13.  
  14. say 'FXWrap Install V0.2.5  Copyright (C) 1998  F/X Communications'
  15. say
  16.  
  17. parse source os2 type invocation
  18. lastslash = lastpos('\',invocation)
  19. path = substr(invocation,1,lastslash-1)
  20.  
  21. /***************************************************************************
  22. ** Common part of installed/uninstaller
  23. */
  24.  
  25. /* Determine drive letter where OS/2 is installed */
  26.  
  27. drive=strip(left(value('COMSPEC',,'OS2ENVIRONMENT'),1))
  28.  
  29. do while drive='' | stream(drive':\config.sys','c','query exists')=''
  30.  
  31.     say 'Install is unable to automatically determine '
  32.     say 'drive letter where OS/2 is installed'
  33.     say
  34.  
  35.     /* unable to determine drive. Ask user */
  36.  
  37.     say 'Please enter drive letter for your OS/2 partition:'
  38.     pull drive
  39.     if length(drive)<>1 | stream(drive':\config.sys','c','query exists')=''
  40.     then do
  41.         say 'Invalid drive'
  42.         drive=''
  43.     end
  44. end
  45.  
  46. /* Determine PROTOCOL.INI location */
  47. config=drive':\config.sys'
  48. protini=''
  49.  
  50. do while lines(config)>0
  51.     str=translate(strip(linein(config)))
  52.  
  53.     if left(str,6)<>'DEVICE'
  54.         then iterate
  55.  
  56.     if pos('PROTMAN.OS2',str) >0
  57.     then do
  58.         parse value str with 'DEVICE='protman prot_path
  59.  
  60.         /* If /I: is specified, then use value passed in /I */
  61.         /* else use path of protman itself */
  62.  
  63.         prot_path=strip(prot_path)
  64.  
  65.         if prot_path = ''
  66.         then do
  67.             protini=left(protman, lastpos('\',protman)-1)
  68.         end
  69.         else do
  70.             parse value prot_path with beg':\'protman
  71.             protini=right(beg,1)':\'protman
  72.         end
  73.     end
  74. end
  75. call stream config, 'c', 'close'
  76.  
  77. do while protini=''
  78.     say 'Install is unable to automatically determine '
  79.     say 'path of PROTOCOL.INI'
  80.     say
  81.  
  82.     /* unable to determine drive. Ask user */
  83.     say 'Please enter path of PROTOCOL.INI:'
  84.     pull protini
  85.     if stream(protini'\protocol.ini','c','query exists')=''
  86.     then do
  87.         say 'Path is ivalid'
  88.     end
  89. end
  90.  
  91. /* check prerequisites */
  92.  
  93. if stream(protini'\PROTOCOL.!!!','c', 'query exists')<>''
  94. then do
  95.     say 'File PROTOCOL.!!! exists in directory 'protini
  96.     say 'Probably caused by cancelled installation of FXWRAP'
  97.     say 'Check contents of file, and please rename or delete it.'
  98.     say 'Then restart installation of FXWRAP.'
  99.     exit
  100. end
  101.  
  102. if stream(drive':\CONFIG.!!!','c', 'query exists')<>''
  103. then do
  104.     say 'File CONFIG.!!! exists in 'translate(drive)':\'
  105.     say 'Probably caused by cancelled installation of FXWRAP'
  106.     say 'Check contents of file, and please rename or delete it.'
  107.     say 'Then restart installation of FXWRAP.'
  108.     exit
  109. end
  110.  
  111. /* Last chance */
  112.  
  113. say 'Press'
  114. say '<I> to install FXWRAP'
  115. say '<U> to uninstall previously installed FXWRAP'
  116. say 'any other key to exit'
  117.  
  118. pull answer
  119.  
  120. backup_copy=backup_name(protini'\PROTOCOL.')
  121. backup_config=backup_name(drive':\CONFIG.')
  122.  
  123. if backup_copy='' | backup_config=''
  124. then do
  125.     say 'Unable to create backup copy of system files, aborting.'
  126.     exit
  127. end
  128.  
  129. if answer='U'
  130.     then call uninstall;
  131.  
  132. if answer='I'
  133.     then call install;
  134. exit
  135.  
  136. /*--------------------------------------------------------------------------*/
  137. /* Installation procedure                                                   */
  138. /*--------------------------------------------------------------------------*/
  139.  
  140. Install:
  141.  
  142. if stream(path'\FXWRAP.SYS','c', 'query exists')=''
  143. then do
  144.     say 'File FXWRAP.SYS is NOT found in the INSTALL.CMD directory, aborting.'
  145.     exit
  146. end
  147.  
  148. config=drive':\config.sys'
  149.  
  150. do while lines(config)>0
  151.     str=translate(strip(linein(config)))
  152.  
  153.     if left(str,6)<>'DEVICE'
  154.         then iterate
  155.  
  156.     if pos('FXWRAP.SYS', str) >0
  157.     then do
  158.         say 'Install does not support installation of more than one'
  159.         say 'instance of FXWRAP.SYS.'
  160.         exit
  161.     end
  162. end
  163. call stream config, 'c', 'close'
  164.  
  165.  
  166. /* Parse PROTOCOL.INI and build bind tree */
  167.  
  168. config=protini'\PROTOCOL.INI'
  169. nif_list=''
  170. bind_list.=''
  171. cur_nif=''
  172. tcpip_nif=''
  173.  
  174. /* determine full list of NIF's */
  175. /* determine full list of bindings for each NIF's*/
  176.  
  177. do while lines(config) > 0
  178.     str=strip(linein(config))
  179.     if str=''
  180.         then iterate;
  181.  
  182.     if left(str,1)=';'
  183.         then iterate;
  184.  
  185.     if left(str,1)='[' /*section name*/
  186.     then do
  187.         cur_nif=strip(substr(str,2,length(str)-2))
  188.  
  189.         if translate(cur_nif)='TCPIP_NIF'
  190.             then tcpip_nif=cur_nif;
  191.  
  192.         nif_list=nif_list' 'cur_nif
  193.         bind_list.cur_nif=''
  194.         bind_list.cur_nif.bound=0
  195.         iterate
  196.     end
  197.  
  198.     if cur_nif=''
  199.         then iterate;
  200.  
  201.     parse value str with variable'='var_value
  202.  
  203.     if translate(strip(variable))='BINDINGS'
  204.     then do
  205.         bind_list.cur_nif=var_value
  206.         iterate
  207.     end
  208.  
  209.     if cur_nif='IBMLXCFG'
  210.     then do
  211.         parse value str with nif_name'='file_name
  212.         nif_name=strip(nif_name)
  213.         file_name=strip(file_name)
  214.         bind_list.nif_name.file=file_name
  215.     end
  216. end
  217. call stream config, 'c', 'close'
  218. nif_list=strip(nif_list)
  219.  
  220. /* Determine bottom level NIF's */
  221.  
  222. bottom_nifs=''
  223.  
  224. do i=1 to words(nif_list)
  225.     call find_bindings word(nif_list,i)
  226. end
  227.  
  228. do i=1 to words(nif_list)
  229.     cur_nif=word(nif_list,i)
  230.  
  231.     if bind_list.cur_nif.bound = 1
  232.     then do
  233.         bottom_nifs=bottom_nifs' 'cur_nif
  234.     end
  235. end
  236.  
  237. bottom_nifs=strip(bottom_nifs)
  238.  
  239. /* */
  240. j=1
  241. sel_nif=-1
  242.  
  243. say 'You have 'words(bottom_nifs)' LAN adapters installed'
  244. say 'Select one of the following:'
  245.  
  246. do i=1 to words(nif_list)
  247.     cur_nif=word(nif_list,i)
  248.  
  249.     if bind_list.cur_nif.bound = 1
  250.     then do
  251.         lan_num=wordpos(cur_nif, translate(bind_list.tcpip_nif,' ',','))-1
  252.         say j'. lan'lan_num':' strip(adapter_name(cur_nif))
  253.         j=j+1
  254.     end
  255. end
  256.  
  257. say '0. Exit'
  258.  
  259. do while sel_nif='' | verify(sel_nif,'0123456789') <> 0 | sel_nif < 0 | sel_nif > j
  260.     say 'Choice:'
  261.     pull sel_nif .
  262. end
  263.  
  264. if sel_nif=0
  265.     then exit;
  266.  
  267. j = 0
  268.  
  269. replace_nif=''
  270.  
  271. do i=1 to words(nif_list)
  272.     cur_nif=word(nif_list,i)
  273.     if bind_list.cur_nif.bound = 1
  274.     then do
  275.         j = j + 1
  276.         if j = sel_nif
  277.         then do
  278.             replace_nif=cur_nif
  279.             leave;
  280.         end
  281.     end
  282. end
  283.  
  284. say 'Processing 'adapter_name(replace_nif)
  285.  
  286. infile =protini'\PROTOCOL.INI'
  287. outfile=protini'\PROTOCOL.!!!'
  288.  
  289. do while lines(infile) > 0
  290.     str2=linein(infile)
  291.     str=strip(str2)
  292.  
  293.     if str='' | left(str,1)=';' | left(str,1)='['
  294.     then do
  295.         call lineout outfile, str2
  296.         iterate
  297.     end
  298.  
  299.     parse value str2 with var_name'='var_value
  300.  
  301.     if translate(strip(var_name))='BINDINGS'
  302.     then do
  303.         repl_pos=pos(translate(replace_nif),translate(var_value))
  304.         if repl_pos > 0
  305.         then do
  306.             var_value=replace_bindings(var_value, replace_nif, 'FXWRAP_nif')
  307.             call lineout outfile, '   'strip(var_name)'   = 'var_value
  308.         end
  309.         else
  310.             call lineout outfile, str2;
  311.     end
  312.     else
  313.         call lineout outfile, str2;
  314. end
  315.  
  316. call lineout outfile,'[FXWRAP_nif]'
  317. call lineout outfile,''
  318. call lineout outfile,'   Drivername = FXWRAP1$'
  319. call lineout outfile,'   Bindings   = 'replace_nif
  320. call lineout outfile,''
  321.  
  322. call stream outfile, 'c', 'close'
  323. call stream infile, 'c', 'close'
  324.  
  325. say 'Processing 'translate(drive)':\CONFIG.SYS'
  326.  
  327. tmpconfig=drive':\CONFIG.!!!'
  328. infile   =drive':\CONFIG.SYS'
  329. inserted=0
  330.  
  331. do while lines(infile) > 0
  332.     str=linein(infile)
  333.     call lineout tmpconfig, str
  334.  
  335.     if inserted=1
  336.         then iterate;
  337.  
  338.     if pos('\IBMCOM\MACS\',translate(str)) > 0 & left(translate(strip(str)),6)='DEVICE'
  339.     then do
  340.         call lineout tmpconfig, 'DEVICE='protini'\MACS\FXWRAP.SYS'
  341.         inserted=1
  342.     end
  343. end
  344.  
  345. if inserted=0
  346. then do
  347.     call lineout tmpconfig, 'DEVICE='protini'\MACS\FXWRAP.SYS'
  348. end
  349.  
  350. call stream tmpconfig, 'c', 'close'
  351. call stream infile, 'c', 'close'
  352.  
  353. /* replace PROTOCOL.INI */
  354. /* replace CONFIG.SYS */
  355. /* copy FXWRAP.SYS to all other MAC's */
  356.  
  357. 'copy FXWRAP.SYS 'protini'\MACS >nul 2>nul'
  358. if rc<>0
  359. then do
  360.     say 'Unable to copy FXWRAP.SYS to 'protini'\MACS'
  361.     exit
  362. end
  363.  
  364. 'copy 'protini'\PROTOCOL.INI 'backup_copy '>nul 2>nul'
  365.  
  366. if rc<>0
  367. then do
  368.     say 'Unable to create backup copy of PROTOCOL.INI'
  369.     exit
  370. end
  371.  
  372. say protini'\PROTOCOL.INI saved as 'backup_copy;
  373.  
  374. 'copy 'drive':\CONFIG.SYS 'backup_config '>nul 2>nul'
  375.  
  376. if rc<>0
  377. then do
  378.     say 'Unable to create backup copy of CONFIG.SYS'
  379.     exit
  380. end
  381.  
  382. say drive':\CONFIG.SYS saved as 'backup_config
  383.  
  384. 'copy 'outfile protini'\PROTOCOL.INI >nul 2>nul'
  385. if rc<>0
  386. then do
  387.     say 'Unable to replace 'protini'\PROTOCOL.INI'
  388.     exit
  389. end
  390. 'del 'outfile '> nul 2>nul'
  391.  
  392. 'copy 'tmpconfig drive':\CONFIG.SYS >nul 2>nul'
  393. if rc<>0
  394. then do
  395.     say 'Unable to replace 'drive':\CONFIG.SYS'
  396.     exit
  397. end
  398. 'del 'tmpconfig '> nul 2>nul'
  399.  
  400. say 'Installation completed successfully'
  401. say 'You must reboot computer to activate FXWRAP.SYS device driver.'
  402.  
  403. return ''
  404.  
  405. /*--------------------------------------------------------------------------*/
  406. /* Uninstallation procedure                                                 */
  407. /*--------------------------------------------------------------------------*/
  408.  
  409. uninstall:
  410. /* Parse PROTOCOL.INI and build bind tree */
  411.  
  412. config=protini'\PROTOCOL.INI'
  413. nif_list=''
  414. bind_list.=''
  415. cur_nif=''
  416.  
  417. /* determine full list of NIF's */
  418. /* determine full list of bindings for each NIF's*/
  419.  
  420. do while lines(config) > 0
  421.     str=strip(linein(config))
  422.     if str=''
  423.         then iterate;
  424.  
  425.     if left(str,1)=';'
  426.         then iterate;
  427.  
  428.     if left(str,1)='[' /*section name*/
  429.     then do
  430.         cur_nif=strip(substr(str,2,length(str)-2))
  431.         nif_list=nif_list' 'cur_nif
  432.         bind_list.cur_nif=''
  433.         bind_list.cur_nif.bound=0
  434.         iterate
  435.     end
  436.  
  437.     if cur_nif=''
  438.         then iterate;
  439.  
  440.     parse value str with variable'='var_value
  441.  
  442.     if translate(strip(variable))='BINDINGS'
  443.     then do
  444.         bind_list.cur_nif=var_value
  445.         iterate
  446.     end
  447.  
  448.     if cur_nif='IBMLXCFG'
  449.     then do
  450.         parse value str with nif_name'='file_name
  451.         nif_name=strip(nif_name)
  452.         file_name=strip(file_name)
  453.         bind_list.nif_name.file=file_name
  454.     end
  455. end
  456.  
  457. call stream config, 'c', 'close'
  458.  
  459. nif_list=strip(nif_list)
  460.  
  461. /* Determine bottom level NIF's */
  462.  
  463. bottom_nifs=''
  464.  
  465. do i=1 to words(nif_list)
  466.     call find_bindings word(nif_list,i)
  467. end
  468.  
  469. do i=1 to words(nif_list)
  470.     cur_nif=word(nif_list,i)
  471.     /*say 'nif_list.'cur_nif'='bind_list.cur_nif*/
  472.     if bind_list.cur_nif.bound = 1
  473.     then do
  474.         bottom_nifs=bottom_nifs' 'cur_nif
  475.     end
  476. end
  477.  
  478. bottom_nifs=strip(bottom_nifs)
  479.  
  480. fxwrap_nif=''
  481. /* Find FXWRAP_nif and find their bindings */
  482. do i=1 to words(bottom_nifs)
  483.     cur_nif=word(bottom_nifs,i)
  484.     if left(translate(cur_nif),6)='FXWRAP'
  485.     then do
  486.         /*say cur_nif',' bind_list.cur_nif*/
  487.         fxwrap_nif=cur_nif
  488.         leave
  489.     end
  490. end
  491. if fxwrap_nif=''
  492. then do
  493.     say 'FXWRAP is NOT installed, aborting'
  494.     exit
  495. end
  496.  
  497. /*say cur_nif 'bound to' bind_list.cur_nif*/
  498.  
  499. say 'Processing 'fxwrap_nif
  500.  
  501. infile =protini'\PROTOCOL.INI'
  502. outfile=protini'\PROTOCOL.!!!'
  503.  
  504. do while lines(infile) > 0
  505.     str2=linein(infile)
  506.     str=strip(str2)
  507.  
  508.     if str='' | left(str,1)=';' | left(str,1)='['
  509.     then do
  510.         if left(str,1)='['
  511.         then do
  512.             if translate(strip(substr(str,2,length(str)-2)))=translate(fxwrap_nif)
  513.             then do
  514.                 do while lines(infile) > 0
  515.                     str2 = linein(infile)
  516.                     if left(strip(str2),1)='['
  517.                     then do
  518.                         call lineout outfile, str2;
  519.                         leave
  520.                     end
  521.                 end
  522.             end
  523.             else
  524.                 call lineout outfile, str2;
  525.         end
  526.         else
  527.             call lineout outfile, str2;
  528.         iterate
  529.     end
  530.  
  531.     parse value str2 with var_name'='var_value
  532.  
  533.     if translate(strip(var_name))='BINDINGS'
  534.     then do
  535.         repl_pos=pos(translate(fxwrap_nif),translate(var_value))
  536.         if repl_pos > 0
  537.         then do
  538.             var_value=replace_bindings(var_value, fxwrap_nif, bind_list.fxwrap_nif)
  539.             call lineout outfile, '   'strip(var_name)'   = 'var_value
  540.         end
  541.         else
  542.             call lineout outfile, str2;
  543.     end
  544.     else
  545.         call lineout outfile, str2;
  546. end
  547.  
  548. call stream outfile, 'c', 'close'
  549. call stream infile, 'c', 'close'
  550.  
  551. say 'Processing 'translate(drive)':\CONFIG.SYS'
  552.  
  553. tmpconfig=drive':\CONFIG.!!!'
  554. infile   =drive':\CONFIG.SYS'
  555. inserted=0
  556.  
  557. do while lines(infile) > 0
  558.     str=linein(infile)
  559.     /* Find FXWRAP.SYS */
  560.     if left(translate(strip(str)),6)='DEVICE' & pos('FXWRAP.SYS',translate(str)) > 0
  561.         then iterate;
  562.     else
  563.         call lineout tmpconfig, str;
  564. end
  565.  
  566. call stream tmpconfig, 'c', 'close'
  567. call stream infile, 'c', 'close'
  568.  
  569. /* replace PROTOCOL.INI */
  570. /* replace CONFIG.SYS */
  571. /* copy FXWRAP.SYS to all other MAC's */
  572.  
  573. 'copy 'protini'\PROTOCOL.INI 'backup_copy '>nul 2>nul'
  574.  
  575. if rc<>0
  576. then do
  577.     say 'Unable to create backup copy of PROTOCOL.INI'
  578.     exit
  579. end
  580.  
  581. say protini'\PROTOCOL.INI saved as 'backup_copy;
  582.  
  583. 'copy 'drive':\CONFIG.SYS 'backup_config '>nul 2>nul'
  584.  
  585. if rc<>0
  586. then do
  587.     say 'Unable to create backup copy of CONFIG.SYS'
  588.     exit
  589. end
  590.  
  591. say drive':\CONFIG.SYS saved as 'backup_config
  592.  
  593. 'copy 'outfile protini'\PROTOCOL.INI >nul 2>nul'
  594. if rc<>0
  595. then do
  596.     say 'Unable to replace 'protini'\PROTOCOL.INI'
  597.     exit
  598. end
  599. 'del 'outfile '> nul 2>nul'
  600.  
  601. 'copy 'tmpconfig drive':\CONFIG.SYS >nul 2>nul'
  602. if rc<>0
  603. then do
  604.     say 'Unable to replace 'drive':\CONFIG.SYS'
  605.     exit
  606. end
  607.  
  608. 'del 'tmpconfig '> nul 2>nul'
  609.  
  610. say 'Uninstallation completed successfully'
  611. say 'You must reboot computer to deactivate FXWRAP.SYS device driver.'
  612.  
  613. return ''
  614.  
  615. /*--------------------------------------------------------------------------*/
  616. /* Utility procedure                                                        */
  617. /*--------------------------------------------------------------------------*/
  618.  
  619. find_bindings: procedure expose bind_list. level
  620.     cur_nif=arg(1)
  621.  
  622.     if bind_list.cur_nif<>''
  623.     then do
  624.         /*bindings can be separated by commas and by spaces */
  625.         bind_list.cur_nif=space(translate(bind_list.cur_nif,' ', ','),1)
  626.  
  627.         do j=1 to words(strip(bind_list.cur_nif))
  628.             nif=word(strip(bind_list.cur_nif),j)
  629.             bind_list.nif.bound=1
  630.             call find_bindings nif
  631.         end
  632.     end
  633. return 0
  634.  
  635. adapter_name:
  636.     fname=arg(1)
  637.     adaptername=fname
  638.     fname=bind_list.fname.file
  639.     section=''
  640.  
  641.     if fname<>'' & stream(protini'\MACS\'fname,'c','query exists')<>''
  642.     then do
  643.         ad_nif=protini'\MACS\'fname
  644.  
  645.         do while lines(ad_nif)
  646.             str=strip(linein(ad_nif))
  647.  
  648.             if str=''
  649.                 then iterate;
  650.  
  651.             if left(str,'1')='['
  652.             then do
  653.                 if section<>''
  654.                     then leave; /* parse only first section of .NIF*/
  655.                 section=strip(substr(str,2,length(str)-2))
  656.                 iterate
  657.             end
  658.  
  659.             if section=''
  660.                 then iterate;
  661.  
  662.             parse value str with var_name'='var_value
  663.             if translate(strip(var_name))='TITLE'
  664.             then do
  665.                 adaptername=var_value
  666.                 leave
  667.             end
  668.         end
  669.         call stream ad_nif, 'c', 'close'
  670.     end
  671. return adaptername
  672.  
  673. backup_name: procedure
  674.     backup_copy=''
  675.     basefile=arg(1)
  676.     bkp=0
  677.  
  678.     do while backup_copy='' & bkp < 1000
  679.         bkp_ext=right(bkp,3,'0')
  680.         if stream(basefile||bkp_ext,'c','query exists')=''
  681.         then do
  682.             backup_copy=basefile||bkp_ext
  683.         end
  684.         bkp=bkp+1
  685.     end
  686. return backup_copy
  687.  
  688. replace_bindings: procedure
  689.     var_value=strip(arg(1))
  690.     find_nif=strip(arg(2))
  691.     repl_nif=strip(arg(3))
  692.  
  693.     repl_pos=pos(translate(find_nif),translate(var_value))
  694.     var_value=insert(repl_nif,delstr(var_value,repl_pos,length(find_nif)),repl_pos-1)
  695. return var_value
  696.  
  697.