home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 33 VDrivers / 33-VDrivers.zip / 128tntb5.zip / SETUP.CMD < prev    next >
OS/2 REXX Batch file  |  1998-12-23  |  11KB  |  328 lines

  1. /***************************************************/
  2.  
  3. /*****************************************
  4. * Intialize Rexxutil Functions
  5. ******************************************/
  6.  
  7.   call RxFuncAdd 'SysLoadFuncs' , 'REXXUTIL', 'SysLoadFuncs'
  8.  
  9.   signal on syntax name MsgExit
  10.  
  11.   call SysLoadFuncs
  12.  
  13.   numeric digits 12
  14.  
  15. /******************************************
  16. * Define message ids from *mid*.h
  17. *******************************************/
  18.   MSG_SYSINIT_BOOT_NOT_FD    = 1475
  19.   MSG_INCORRECT_DOSVER       = 1210
  20.   MSG_NO_META_MATCH          =  257
  21.   MSG_PRINT_FILE_NOT_FOUND   = 1533
  22.   MSG_COMP_INVALID_PATH      = 1171
  23.   MSG_BOOT_MUST_RESTART      = 1716
  24.   MSG_INSTALL_UNSUCCESSFUL   = 1975
  25.   MSG_INSTALL_HY_HDR         = 1976
  26.   MSG_PROC_NOT_FOUND         =  127
  27.   MSG_REP_SOUR_PATH_REQ      = 1137
  28.   MSG_SYS_INV_DRIVE          = 1461
  29.   MSG_CHCP_INVALID_PARAMETER = 1761
  30.   MSG_UNP_INSERT_PI          = 1218
  31.   MSG_ERR_PROC_ARG           = 1249
  32.   MSG_MBS_INVALID_COMMAND    =  872
  33.   SPTReboot                  = x2d('FE00',4)
  34.   SPTRebootErr               = x2d('FE08',4)
  35.   SPTWithErr                 = x2d('0008',4)
  36.  
  37.  
  38. /*****************************************
  39. * Initialized globals
  40. ******************************************/
  41.   GRADDKEYS    = 'NV GEN VGA'
  42.   GRADDDSCS    = 'nvgradd gengradd vgagradd'
  43.   graddPackDSC = 'grdpack.dsc'
  44.   cidInst = ''
  45. /*****************************************
  46. * Set up Source and Target Paths
  47. ******************************************/
  48.   parse source one two me
  49.   srcPath = filespec('Drive', me) || filespec('Path', me)
  50.   srcName = filespec('Name', me)
  51.  
  52.  
  53.   os2bootPath = SysSearchPath('PATH', 'os2boot')
  54.   if os2bootpath \= ''
  55.    then bootDrive = filespec('drive', os2bootPath)
  56.    else call MsgExit SysGetMessage(MSG_SYSINIT_BOOT_NOT_FD)
  57.  
  58. /******************************************
  59. * Verify options if any
  60. *******************************************/
  61.   if arg() == 0
  62.     then call Usage
  63.     else do
  64.        cmdline = arg(1)
  65.        parse value(cmdline) with tmp1 '/' option tmp2
  66.        if option \= ''
  67.        then do
  68.           if translate(option) == 'U'
  69.           then do
  70.              cidInst = ' /u'
  71.              cmdline = tmp1 || tmp2
  72.           end
  73.           else do
  74.              say MyGetMsg(SysGetMessage(MSG_MBS_INVALID_COMMAND,, '"' || '/' || option || '"'))
  75.              call Usage
  76.           end
  77.        end
  78.        parse value(cmdline) with gradd srcTmp bootTmp junk
  79.        if junk \= '' then call Usage
  80.        if wordpos(translate(gradd), GRADDKEYS) == 0
  81.          then call Usage
  82.          else dscFile = word(GRADDDSCS, wordpos(translate(gradd), GRADDKEYS)) || '.dsc'
  83.        if srcTmp \= ''
  84.          then do
  85.             if filespec('Drive',srcTmp) == strip(srcTmp, 'T', '\')
  86.               then srcChk = srcTmp
  87.               else srcChk = strip(srcTmp, 'T', '\') || '\'
  88.             call SysFileTree srcChk || srcName, 'file', 'F'
  89.             if file.0 == 0
  90.               then do
  91.                  say MyGetMsg(SysGetMessage(MSG_PRINT_FILE_NOT_FOUND, ,'"' || srcChk || srcName || '"'))
  92.                  say MyGetMsg(SysGetMessage(MSG_CHCP_INVALID_PARAMETER, ,srcTmp))
  93.                  call Usage
  94.               end
  95.               else srcPath = srcChk
  96.          end
  97.        if bootTmp \= ''
  98.          then do
  99.             bootTmp   = strip(bootTmp, 'T', '\')
  100.             call SysFileTree bootTmp || '\OS2BOOT', 'file', 'F'
  101.             if file.0 == 0
  102.               then do
  103.                  msg = MyGetMsg(SysGetMessage(MSG_SYSINIT_BOOT_NOT_FD))
  104.                  parse value(msg) with first 'OS2BOOT' last
  105.                  msg = first || '"' || bootTmp || '\OS2BOOT"' || last
  106.                  say msg
  107.                  say MyGetMsg(SysGetMessage(MSG_SYS_INV_DRIVE))
  108.                  call Usage
  109.               end
  110.               else bootDrive = bootTmp
  111.          end
  112.     end
  113.  
  114.  
  115. /*****************************************
  116. * Start logging
  117. ******************************************/
  118.  
  119.   installDir = bootDrive || '\os2\install'
  120.   call SysFileTree installDir, 'file', 'D'
  121.   if file.0 == 0 then call MsgExit MyGetMsg(SysGetMessage(MSG_COMP_INVALID_PATH, ,'"' || installDir || '"'))
  122.   logFile = installDir || '\display.log'
  123.   call SysFileTree logFile, 'file', 'F', ,'-----'
  124.   startmsg = MyGetMsg(SysGetMessage(MSG_UNP_INSERT_PI,, SubStr(dscFile,1, pos('.', dscFile)-1 ) ))
  125.   cmd = 'parse value(startmsg) with . '''D2c(10)''' installmsg '''D2c(13)''' junk'
  126.   interpret cmd
  127.   installmsg = strip(installmsg)
  128.   call LogIt '======================================================================'
  129.   say installmsg
  130.   call LogIt installmsg ' - ' Date('L')  Time()
  131.   '@if exist 'srcPath || 'build.lvl type 'srcPath || 'build.lvl >>'logFile
  132.  
  133.  
  134. /*******************************************************
  135. * Gradd is not supported on OS/2 Versions less than 3.0
  136. * and it also requires a certain fixpak level for both
  137. * version 3.x and 4.0.  Let us verify we have the right
  138. * levels now.
  139. ********************************************************/
  140.   parse value(SysOS2Ver()) with major '.' os2Ver
  141.   rc = 1
  142.   select
  143.      when major < 2 then call MsgExit MyGetMsg(SysGetMessage(MSG_INCORRECT_DOSVER))
  144.      when datatype(os2Ver) \= 'NUM' then call MsgExit MyGetMsg(SysGetMessage(MSG_INCORRECT_DOSVER))
  145.      when os2Ver < 30  then call MsgExit MyGetMsg(SysGetMessage(MSG_INCORRECT_DOSVER))
  146.      when os2Ver < 40  then needLevel = 2
  147.      otherwise needLevel = 1
  148.   end
  149.   parse value(GetGraddLevel(bootDrive || '\os2\dll\gre2vman.dll')) with graddLevel graddStamp
  150.   if \(graddLevel >= needLevel) then call MsgExit MyGetMsg(SysGetMessage(MSG_INCORRECT_DOSVER))
  151.   rc = 0
  152.  
  153.  
  154. /*******************************************************
  155. * Setup path and Copy required files to \os2\install
  156. ********************************************************/
  157.  
  158.   oldPath = value('PATH', , 'OS2ENVIRONMENT')
  159.   newPath = value('PATH', srcPath || ';' || oldPath, 'OS2ENVIRONMENT')
  160.  
  161.   rc = 0
  162.   unpackFiles = srcPath || 'dspinstl.ex_ 'srcPath || 'inscfg32.dl_'
  163.   do i = 1 to words(unpackFiles) while (rc == 0)
  164.     cmd = 'unpack 'word(unpackFiles, i) bootDrive
  165.     call LogIt cmd
  166.     '@' || cmd || ' >> 'logfile ' 2>&1'
  167.   end
  168.   if rc \= 0 then call MsgExit ""
  169.  
  170.  
  171. /********************************************************
  172. * Obtain .DSC file
  173. *********************************************************/
  174.  
  175.   call SysFileTree srcPath || dscFile, 'file', 'F'
  176.   if file.0 == 0 then call MsgExit MyGetMsg(SysGetMessage(MSG_PRINT_FILE_NOT_FOUND,, '"' || srcPath || '*.dsc' || '"')),
  177.                                    || MyGetMsg(SysGetMessage(MSG_NO_META_MATCH))
  178.                  else parse value(file.1) with . . . . dscFile
  179.  
  180.   cmd = 'copy 'dscFile installDir
  181.   dscFile = installDir || '\' || FileSpec('Name', dscFile)
  182.   call LogIt cmd
  183.   '@' || cmd || ' >> 'logfile ' 2>&1'
  184.   if rc \= 0 then call MsgExit ""
  185.  
  186.   if SysFileTree(bootDrive || '\os2\video.cfg','file','F',,'+****') == 0
  187.     then call SysFileDelete bootDrive || '\os2\video.cfg'
  188.  
  189.   if translate(gradd) == 'VGA' then call SysIni ,'PM_DISPLAYDRIVERS','DEFAULTSYSTEMRESOLUTION','DELETE:'
  190.  
  191.  
  192.  
  193.   cmd = 'copy 'srcPath || graddPackDSC installDir
  194.   '@' || cmd || '>nul 2>&1'
  195.   if rc \= 0 then graddPackDSC = ''
  196.              else do
  197.                 graddPackDSC = installDir || '\' || graddPackDSC
  198.                 parse value(GetGraddLevel(srcPath || 'gre2vman.dll')) with . newStamp
  199.              end
  200.  
  201.   dspInstall = bootDrive || '\os2\install\dspinstl.exe'
  202.   if filespec('Drive', srcPath) \= strip(srcPath, 'T', '\')
  203.     then srcPath = strip(srcPath, 'T', '\')
  204.  
  205.  
  206.   if ((symbol('newStamp') == 'VAR') & (newStamp \= ''))
  207.   then do
  208.      if ((graddStamp == '') | ( newStamp > graddStamp))
  209.        then '@' || dspInstall '/pk:other /s:' || srcPath || ' /t:' || bootDrive,
  210.                           || ' /pd:' || strip(graddPackDSC) || ' /l:' || logFile
  211.   end
  212.  
  213.  
  214.   '@' || dspInstall '/pk:svga /s:' || srcPath || ' /t:' || bootDrive,
  215.               || ' /pd:' || strip(dscFile) || ' /l:' || logFile || cidInst
  216.  
  217.   if ( (rc == 0) | ((cidInst \= '') & ( rc == SPTReboot)) )
  218.     then call MsgExit MyGetMsg(SysGetMessage(MSG_BOOT_MUST_RESTART))
  219.     else call MsgExit MyGetMsg(SysGetMessage(MSG_ERR_PROC_ARG,,dscFile))
  220.  
  221. /******************************************************
  222. * Procedure for determining level of Gradd subsystem
  223. *******************************************************/
  224. GetGraddLevel: Procedure
  225.  
  226. parse arg graddModule
  227.  
  228. gtvVer = ''
  229.  
  230. if stream(graddModule,'c', 'query exists') \= ''
  231. then do
  232.     newQueue = RxQueue('Create')
  233.     oldQueue = RxQueue('Set', newQueue)
  234.     '@bldlevel 'graddModule '| rxqueue' newQueue
  235.     do while queued() \=0
  236.        parse upper pull tag data
  237.        if tag == 'SIGNATURE:'
  238.        then
  239.           do while queued() \= 0
  240.             parse upper pull tag data
  241.             if tag == 'DESCRIPTION:'
  242.                then parse value(data) with  'V' gtvVer gtvStamp .
  243.           end
  244.     end
  245.     call RxQueue 'Delete', newQueue
  246.     call RxQueue 'Set', oldQueue
  247. end
  248.  
  249. if datatype(gtvVer)   \= 'NUM' then gtvVer = 0
  250. if datatype(gtvStamp) \= 'NUM' then gtvStamp = 0
  251.  
  252. return gtvVer gtvStamp
  253.  
  254.  
  255. /******************************************************
  256. * Error message processing and exit
  257. *******************************************************/
  258. MsgExit:
  259.  
  260.    parse arg errmsg
  261.  
  262.    if rc == 43
  263.     then do
  264.         say sigl'  +++      'SourceLine(sigl)
  265.         say 'REX0043: 'ErrorText(43)
  266.     end
  267.     else do
  268.       if errmsg == '' then errmsg = 'REXX' || right(rc,4,'0') || ': 'ErrorText(rc)
  269.       say errmsg
  270.       if ( (rc \= 0) & ((cidInst \= '') & ( rc \= SPTReboot)) )
  271.         then do
  272.            exitmsg = MyGetMsg(SysGetMessage(MSG_INSTALL_UNSUCCESSFUL))
  273.            say exitmsg
  274.         end
  275.  
  276.       if symbol('logfile') == 'VAR'
  277.         then do
  278.            if symbol('exitmsg') == 'VAR'
  279.              then do
  280.                call LogIt errmsg
  281.                call LogIt exitmsg
  282.                say MyGetMsg(SysGetMessage(MSG_INSTALL_HY_HDR)) || ' ' || logfile
  283.              end
  284.         end
  285.     end
  286.  
  287.    if symbol('oldPath') == 'VAR' then call value 'PATH' , oldPath, 'OS2ENVIRONMENT'
  288.    exit rc
  289.  
  290. /******************************************************
  291. * Safely write to logfile
  292. *******************************************************/
  293. LogIt: Procedure expose logfile
  294.  
  295.   parse arg message
  296.   call lineout logfile, message
  297.   call stream logfile, 'c', 'close'
  298.   return
  299.  
  300. /******************************************************
  301. * Remove SYSXXXX: from messages
  302. *******************************************************/
  303. MyGetMsg: Procedure
  304.   parse arg message
  305.  
  306.   if pos('SYS', word(message, 1)) == 1
  307.     then parse arg . message
  308.  
  309.   return message
  310.  
  311. /*****************************************************
  312. * Print usage and exit
  313. ******************************************************/
  314. Usage:
  315.  
  316.       msg = MyGetMsg(SysGetMessage(734,,srcName))
  317.       cmd = 'parse value(msg) with msg '''srcName''' .'
  318.       interpret cmd
  319.       indent = copies(' ',30)
  320.       say msg me || ' xxx [' || srcPath || '] [' || bootDrive || '] [/u]'
  321.       say ''
  322.       say '                          xxx:'
  323.       say indent || '"NV"    -   NVIDIA NV4'
  324.       say indent || '"GEN"   -   GENGRADD Generic SVGA'
  325.       say indent || '"VGA"   -   VGAGRADD Generic VGA'
  326.       say ''
  327.       exit 1
  328.