home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / wpdsc093.zip / install.cmd < prev    next >
OS/2 REXX Batch file  |  1995-11-06  |  8KB  |  289 lines

  1. /* rexx */
  2.  
  3. parse source . . srcpath
  4. parse arg args
  5.  
  6. call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
  7. call SysLoadFuncs
  8. call RxFuncAdd "DSCRxLoadFuncs","rxdscr","DSCRxLoadFuncs"
  9. call DSCRxLoadFuncs
  10.  
  11.  
  12. say "Description WPS Classes replacement version 0.93"
  13. say "Copyright (c) 1995 Virtual Objects Software"
  14. dllpath=word(args,1)
  15. phase=word(args,2)
  16.  
  17.  
  18. uninst.cmd = filespec("drive",srcpath)||filespec("path",srcpath)||"uninst.cmd"
  19. org_dir=directory()
  20. call directory(filespec("drive",srcpath)||filespec("path",srcpath))
  21.  
  22. if dllpath='' then do
  23.     say 'Usage: install.cmd <dll-path>'
  24.     say '  where <dll-path> is the directory contained '
  25.     say '  in LIBPATH statement in your CONFIG.SYS'
  26.     signal ExitInst
  27. end
  28. dllpath=CutLastBash(dllpath)
  29.  
  30. if \DriveIsLocal(dllpath) then do
  31.   say "You should specify the path on local drive."
  32.   say "Do not use remote paths like "||dllpath||"!"
  33.   signal ExitInst
  34. end
  35.  
  36.  
  37. bootdrv=QueryBootDrive()
  38.  
  39.  
  40. dscrdistr.1="dscrdf.dll"
  41. dscrdistr.2="dscrlst.dll"
  42. dscrdistr.3="install.cmd"
  43. dscrdistr.4="uninst.cmd"
  44. dscrdistr.5="rxdscr.dll"
  45.  
  46. dscrdistr.0=5
  47.  
  48.  
  49.  
  50. cls.2="DSCRFileList"
  51. cls.1="DSCRDataFile"
  52. dll.2="dscrlst"
  53. dll.1="dscrdf"
  54. cls.0=2
  55. dll.0=2
  56.  
  57. reinstId="<DSCRReinst>"
  58. call SysDestroyObject(reinstId)
  59. Call SysDestroyObject "<DSCRFileList_TEMP>"
  60.  
  61. if phase='PhaseTwo' then signal PhaseTwo
  62.  
  63. if CheckDSCRClasses() then do
  64.   say "Another version of WPS DSCR classes is installed."
  65.   say "To reinstall them or replace with the newer version"
  66.   say "WPS DSCR classes should be unregistered by ..."
  67.   say "... calling uninst.cmd"
  68.   'call '||uninst.cmd
  69.   say " "
  70.  
  71.   if \DriveIsLocal(srcpath) then do
  72.    
  73.    say "You've started installation from the remote or detached drive."
  74.    say "This may cause reinstallation proccess to be failed. "
  75.    say "Therefore WPS DSCR package files will now be copied to "
  76.    say "your boot drive "QueryBootDrive()
  77.    org_dir=QueryBootDrive()'\TEMP'
  78.    drop found.
  79.    rc=SysFileTree(org_dir, "found","DO")
  80.    if found.0=0 then do
  81.      rc=SysMkDir(org_dir)
  82.      if rc\=0 then do
  83.        say "Error occured while creating "org_dir
  84.        say "SysMkDir return code="rc
  85.        org_dir=QueryBootDrive()
  86.        say "Resetting to "org_dir
  87.      end
  88.    end
  89.    drop found.
  90.    do i=1 to dscrdistr.0 
  91.       'copy '||dscrdistr.i||' '||org_dir||'\'||dscrdistr.i
  92.    end
  93.   end
  94.  
  95.   /* reinstall */
  96.   say "Creating DLLs' removing script..."
  97.   remove_dll=QueryBootDrive()||"\dscrdll.cmd"
  98.   call SysFileDelete(remove_dll);
  99.   rc=lineout(remove_dll,'@echo off')
  100.   rc=lineout(remove_dll,'echo Removing old WPS DSCR DLLs...')
  101.   if rc\=0 then do
  102.     say 'Error occured while creating 'remove_dll
  103.     signal ExitInst
  104.   end
  105.  
  106.   do i=1 to dll.0
  107.     remdll=DSCRxDllPath(dll.i)
  108.     if datatype(remdll, "Number")=1 then remdll=dllpath||'\'||dll.i||'.DLL'
  109.      rc=lineout(remove_dll,'del '||remdll)
  110.      if rc\=0 then do
  111.       say 'Error occured while creating 'remove_dll
  112.       signal ExitInst
  113.      end
  114.   end
  115.  
  116.   say 'Backing up 'config.sys' to 'config.bak
  117.   config.sys=QueryBootDrive()||'\CONFIG.SYS'
  118.   config.bak=QueryBootDrive()||'\CONFIG.DCR'
  119.   drop retC
  120.   answ='Y'
  121.   do while retC\=0 & answ='Y'
  122.      'copy '||config.sys||' '||config.bak
  123.      retC=rc
  124.      if retC\=0 then do 
  125.       say 'Error backing up 'config.sys' to 'config.bak
  126.       say 'Maybe one of the files '||config.sys||' '||config.bak
  127.       say 'is locked by another process...'
  128.       say 'Would you like to try again? (Y/N)'
  129.       pull answer
  130.       answ=substr(toUpper(answer),1,1)
  131.      end
  132.   end
  133.   if retC\=0 then do 
  134.     say "You've cancelled the installation..."
  135.     signal ExitInst
  136.   end 
  137.   rc=lineout(config.sys, " ")
  138.   rc=lineout(config.sys, 'call=C:\OS2\CMD.EXE /Q /C '||remove_dll)
  139.   if rc\=0 then do
  140.     say 'Error occured while replacing updating 'config.sys
  141.     signal ExitInst
  142.   end
  143.  
  144.   rc=lineout(remove_dll, 'echo Restoring original 'config.sys'...')
  145.   rc=lineout(remove_dll, 'copy 'config.bak' 'config.sys)
  146.   if rc\=0 then do
  147.     say 'Error occured while creating 'remove_dll
  148.     signal ExitInst
  149.   end
  150.  
  151.  
  152.   say 'Creating WPS DSCR reinstallation Program object in StartUp folder...'
  153.   rc=SysCreateObject("WPProgram", "WPS DSCR  Reinstall","<WP_START>","EXENAME="||org_dir||'\'||filespec("name",srcpath)||";PARAMETERS="||dllpath||" PhaseTwo;STARTUPDIR="||org_dir||";OBJECTID="||reinstId);
  154.   if rc=0 then do
  155.     say 'Error creating reinstall object in StartUp folder.'
  156.     signal ExitInst
  157.   end
  158.   say "Now you should reboot the Workplace Shell "
  159.   say "to continue reinstallation process."
  160.   signal ExitInst
  161. end
  162.  
  163. PhaseTwo:
  164.  
  165. do i=1 to dll.0
  166.   'copy '||dll.i||'.dll '||dllpath
  167.   if rc\=0 then do
  168.     dllDel=dllpath||'\'||dll.i||'.dll'
  169.     say 'File '|| dllDel ||' is locked by the system...'
  170.     say 'To correct this problem you would run UNINST.CMD'
  171.     say 'and then either delete file 'dllDel
  172.         say 'or restart install.cmd again.' 
  173.     say 'Note: if you will not able to perform this under Workplace Shell loaded'
  174.     say '      try to boot in command prompt and perform this action again.'
  175.     say '      (To load under command prompt press Alt-F1 when white square '
  176.     say '       and "OS/2" text appere in the left top corner of the screen' 
  177.     say '       when booting OS/2)'
  178.     drop dllDel
  179.     signal ExitInst
  180.   end
  181. end
  182.  
  183. 'copy rxdscr.dll '||dllpath
  184.  
  185. do i=1 to cls.0
  186.   retc=SysRegisterObjectClass(cls.i,dll.i) 
  187.   if retc=1 then
  188.          say 'Install successfully completed for the class 'cls.i
  189.   else do
  190.     say 'Error registering class 'cls.i' ('dll.i')'
  191.     say 'Please contact VOS to report this error'
  192.     signal ExitInst
  193.   end            
  194. end
  195.  
  196. rc= DSCRxReplaceClass('WPDataFile','DSCRDataFile',1)
  197.  
  198. if rc=0 then do
  199.   say 'Error occured while replacing WPDataFile class'
  200.     signal ExitInst
  201. end
  202. say 'Class WPDataFile successfuly replaced with DSCRDataFile'
  203.  
  204. rc=DSCRxReplaceClass('WPFolder','DSCRFileList',1)
  205.  
  206. if rc=0 then do
  207.   say 'Error occured while replacing WPFolder class'
  208.     signal ExitInst
  209. end
  210.  
  211. say 'Class WPFolder successfuly replaced with DSCRFileList'
  212.  
  213. say 'WPS DSCR classes installation completed successfuly!'
  214. say 'Now you have to reload Workplace Shell to make changes work.'
  215. say 'The simple way to do that is to reboot your system'
  216.  
  217. ExitInst:
  218.  
  219. 'pause'
  220. exit(0)
  221.  
  222.  
  223. CheckDSCRClasses: procedure expose cls. dll.
  224. /* This procedure returns TRUE (1) if either one of 
  225.  WPS DSCR classes is found in your system */
  226. retVal=0
  227. drop clsFlg.
  228.  
  229.     call SysQueryClassList "list."
  230.     do i = 1 to list.0
  231.     parse value list.i with clsName    clsDll
  232.         do j=1 to cls.0
  233.         if toUpper(clsName)=toUpper(cls.j) then clsFlg.j=1
  234.     end    
  235.     end
  236.     do j=1 to cls.0
  237.     if clsFlg.j=1 then retVal=1
  238.     end 
  239. return retVal
  240.  
  241. toUpper: procedure
  242. parse upper arg args
  243. return args
  244.  
  245. QueryBootDrive: procedure 
  246. fs=SysSearchPath('PATH','CMD.EXE')
  247. drvRet=filespec('drive', fs)
  248. return drvRet
  249.  
  250. CutLastbash: procedure
  251. parse arg args
  252. l1=lastpos('\',args)
  253. l2=length(args)
  254. if l1=l2 then return substr(args,1,l2-1)
  255. return args
  256.  
  257.  
  258. FindDllInLibPath: procedure
  259. parse arg dllName
  260. dllPath=0
  261. bootDrv=QueryBootDrive()
  262. config.sys=bootDrv||"\CONFIG.SYS"
  263. if SysFileSearch('LIBPATH',config.sys,'str.')\=0 then  return 0
  264. target='LIBPATH='
  265. l1=length(target)
  266. do i=str.0 to 1 by -1
  267.  l2=COMPARE(target,toUpper(str.i))-1
  268.  if l1=l2 then do
  269.    LPvalue=substr(str.i,l1+1)
  270.    setlocal
  271.    env='PATH'
  272.    call value env,LPvalue,'OS2ENVIRONMENT'
  273.    dllPath=SysSearchPath(env, dllName||".dll")
  274.    endlocal
  275.    return dllPath
  276.  end
  277. end
  278. return dllPath
  279.  
  280.  
  281.  
  282. DriveIsLocal: procedure
  283. parse arg drvIn
  284. drvIn=filespec("drive",toUpper(drvIn))
  285. retVal=0
  286. map=SysDriveMap("A:","LOCAL")
  287. if pos(drvIn, map)\=0 then return 1
  288. return retVal
  289.