home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 33 VDrivers / 33-VDrivers.zip / sddse704.zip / setup.cmd < prev    next >
OS/2 REXX Batch file  |  2000-07-31  |  16KB  |  457 lines

  1. /*******************************************************/
  2. /* Before running, SET LANG= to the correct language.  */
  3. /* It may already be correctly set in your CONFIG.SYS. */
  4. /* For examples:                                       */
  5. /* SET LANG=ar_AA for Arabic                           */
  6. /* SET LANG=pt_BR for Brazil                           */
  7. /* SET LANG=zh_CN for Simplified Chinese               */
  8. /* SET LANG=de_DE for Germany                          */
  9. /* SET LANG=da_DK for Denmark                          */
  10. /* SET LANG=es_ES for Spain                            */
  11. /* SET LANG=el_GR for Greece                           */
  12. /* SET LANG=fi_FI for Finland                          */
  13. /* SET LANG=fr_FR for France                           */
  14. /* SET LANG=iw_IL for Israel                           */
  15. /* SET LANG=it_IT for Italy                            */
  16. /* SET LANG=ja_JP for Japan                            */
  17. /* SET LANG=ko_KR for Korea                            */
  18. /* SET LANG=nl_NL for Netherlands                      */
  19. /* SET LANG=no_NO for Norway                           */
  20. /* SET LANG=sv_SE for Sweden                           */
  21. /* SET LANG=zh_TW for Taiwan                           */
  22. /* SET LANG=en_US for English (default)                */
  23. /*******************************************************/
  24.  
  25. /*****************************************
  26. * Intialize Rexxutil Functions
  27. ******************************************/
  28.  
  29.   call RxFuncAdd 'SysLoadFuncs' , 'REXXUTIL', 'SysLoadFuncs'
  30.  
  31.   signal on syntax name MsgExit
  32.  
  33.   call SysLoadFuncs
  34.  
  35.   numeric digits 12
  36.  
  37. /******************************************
  38. * Define message ids from *mid*.h
  39. *******************************************/
  40.  
  41.   MSG_NO_ERROR               =    0
  42.   MSG_SYSINIT_BOOT_NOT_FD    = 1475
  43.   MSG_INCORRECT_DOSVER       = 1210
  44.   MSG_NO_META_MATCH          =  257
  45.   MSG_PRINT_FILE_NOT_FOUND   = 1533
  46.   MSG_COMP_INVALID_PATH      = 1171
  47.   MSG_BOOT_MUST_RESTART      = 1716
  48.   MSG_INSTALL_UNSUCCESSFUL   = 1975
  49.   MSG_INSTALL_HY_HDR         = 1976
  50.   MSG_PROC_NOT_FOUND         =  127
  51.   MSG_REP_SOUR_PATH_REQ      = 1137
  52.   MSG_SYS_INV_DRIVE          = 1461
  53.   MSG_CHCP_INVALID_PARAMETER = 1761
  54.   MSG_UNP_INSERT_PI          = 1218
  55.   MSG_ERR_PROC_ARG           = 1249
  56.   MSG_MBS_INVALID_COMMAND    =  872
  57.   MSG_USAGE                  =  734
  58.   MSG_BAD_UNIT               =   20
  59.   MSG_CANNOT_MAKE            =   82
  60.   REXX_FUNCTION_NOT_FOUND    =   43
  61.   SPTReboot                  = x2d('FE00',4)
  62.   SPTRebootErr               = x2d('FE08',4)
  63.   SPTWithErr                 = x2d('0008',4)
  64.  
  65. /*****************************************
  66. * Initialized globals
  67. ******************************************/
  68.  
  69.   env = 'OS2ENVIRONMENT'
  70.   lang = value('LANG',,env)
  71.   nlv = SubStr(lang,4)
  72.   if nlv = ''
  73.   then nlv = 'en'
  74.   parse source one two me
  75.   if arg() == 0
  76.   then cmdline = ''
  77.   else cmdline = arg(1)
  78.   srcPath = filespec('Drive', me) || filespec('Path', me)
  79.   files = srcPath || nlv || '\*.*'
  80.   if stream(files, 'c', 'query exists') = ''
  81.   then nlv = 'en'
  82.   if nlv == 'cn' or nlv == 'jp' or nlv == 'kr' or nlv = 'tw'
  83.   then cs = 'dbcs'
  84.   else cs = 'sbcs'
  85.   if nlv == 'kr'
  86.   then dos = 'kr'
  87.   else dos = cs
  88.   cidInst = ''
  89.  
  90. /*****************************************
  91. * GRADD only globals
  92. ******************************************/
  93.  
  94.   GRADDKEYS    = 'GEN SDD VGA'
  95.   GRADDDSCS    = 'gengrdbb sddgrdbb vgagrdbb'
  96.   graddPackDSC = 'grdpack.dsc'
  97.  
  98. /*****************************************
  99. * Set up Source and Target Paths
  100. ******************************************/
  101.  
  102.   srcName = filespec('Name', me)
  103.   os2bootPath = SysSearchPath('PATH', 'os2boot')
  104.   if os2bootpath \= ''
  105.    then bootDrive = filespec('drive', os2bootPath)
  106.    else call MsgExit SysGetMessage(MSG_SYSINIT_BOOT_NOT_FD)
  107.   installDir = bootDrive || '\os2\install'
  108.   restoreDir = installDir || '\vga'
  109.  
  110. /******************************************
  111. * Verify options if any
  112. *******************************************/
  113.  
  114.   if arg() == 0
  115.     then call Usage
  116.     else do
  117.        parse value(cmdline) with tmp1 '/' option tmp2
  118.        if option \= ''
  119.        then do
  120.           if translate(option) == 'U'
  121.           then do
  122.              cidInst = ' /u'
  123.              cmdline = tmp1 || tmp2
  124.           end
  125.           else do
  126.              say MyGetMsg(SysGetMessage(MSG_MBS_INVALID_COMMAND,, '"' || '/' || option || '"'))
  127.              call Usage
  128.           end
  129.        end
  130.        parse value(cmdline) with gradd srcTmp bootTmp junk
  131.        if junk \= '' then call Usage
  132.        if wordpos(translate(gradd), GRADDKEYS) == 0
  133.          then call Usage
  134.          else dscFile = word(GRADDDSCS, wordpos(translate(gradd), GRADDKEYS)) || '.dsc'
  135.        if srcTmp \= ''
  136.          then do
  137.             if filespec('Drive',srcTmp) == strip(srcTmp, 'T', '\')
  138.               then srcChk = srcTmp
  139.               else srcChk = strip(srcTmp, 'T', '\') || '\'
  140.             file1 = srcChk || srcName
  141.             call SysFileTree file1, 'file', 'F'
  142.             if file.0 == 0
  143.               then do
  144.                  say FileNotFound( file1 )
  145.                  say MyGetMsg(SysGetMessage(MSG_CHCP_INVALID_PARAMETER,,srcTmp))
  146.                  call Usage
  147.               end
  148.               else srcPath = srcChk
  149.          end
  150.        if bootTmp \= ''
  151.          then do
  152.             bootTmp   = strip(bootTmp, 'T', '\')
  153.             file1 = bootTmp || '\OS2BOOT'
  154.             call SysFileTree file1, 'file', 'F'
  155.             if file.0 == 0
  156.               then do
  157.                  msg = MyGetMsg(SysGetMessage(MSG_SYSINIT_BOOT_NOT_FD))
  158.                  parse value(msg) with first 'OS2BOOT' last
  159.                  msg = first || '"' || file1 || '"' || last
  160.                  say msg
  161.                  say MyGetMsg(SysGetMessage(MSG_SYS_INV_DRIVE))
  162.                  call Usage
  163.               end
  164.               else bootDrive = bootTmp
  165.          end
  166.     end
  167.   if filespec('Drive', srcPath) \= strip(srcPath, 'T', '\')
  168.   then srcDir = strip(srcPath, 'T', '\')
  169.   else srcDir = srcPath
  170.  
  171. /*****************************************
  172. * Start logging
  173. ******************************************/
  174.  
  175.   call SysFileTree installDir, 'file', 'D'
  176.   if file.0 == 0 then call MsgExit MyGetMsg(SysGetMessage(MSG_COMP_INVALID_PATH,,'"' || installDir || '"'))
  177.   logFile = installDir || '\display.log'
  178.   call SysFileTree logFile, 'file', 'F', ,'-----'
  179.   startmsg = MyGetMsg(SysGetMessage(MSG_UNP_INSERT_PI,, SubStr(dscFile,1, pos('.', dscFile)-1 ) || ' ' ))
  180.   cmd = 'parse value(startmsg) with . '''D2c(10)''' installmsg '''D2c(13)''' junk'
  181.   interpret cmd
  182.   installmsg = strip(installmsg)
  183.   call LogIt '======================================================================'
  184.   say installmsg
  185.   call LogIt installmsg ' - ' Date('L')  Time()
  186.   file1 = srcPath || 'build.lvl'
  187.   call SysFileTree file1,'file','F'
  188.   if file.0 == 0
  189.   then call LogFileNotFound file1
  190.   else '@type ' || file1 || ' >> ' || logFile
  191.  
  192. /*******************************************************
  193. * Gradd is not supported on OS/2 Versions less than 3.0
  194. * and it also requires a certain fixpak level for both
  195. * version 3.x and 4.0.  Let us verify we have the right
  196. * levels now.
  197. ********************************************************/
  198.   parse value(SysOS2Ver()) with major '.' os2Ver
  199.   rc = MSG_INCORRECT_DOSVER
  200.   select
  201.      when major < 2 then call MsgExit MyGetMsg(SysGetMessage(MSG_INCORRECT_DOSVER))
  202.      when datatype(os2Ver) \= 'NUM' then call MsgExit MyGetMsg(SysGetMessage(MSG_INCORRECT_DOSVER))
  203.      when os2Ver < 30  then call MsgExit MyGetMsg(SysGetMessage(MSG_INCORRECT_DOSVER))
  204.      when os2Ver < 40   /* Warp 3.0 needs fixpak 35 or later */
  205.         then do
  206.            needFPLevel = 8.259
  207.         end
  208.      when os2Ver < 45   /* Warp 4.0 needs fixpak 5 or later */
  209.         then do
  210.            needFPLevel = 9.029
  211.         end
  212.      otherwise          /* Releases after Warp 4.0 should be GRADD ready */
  213.         do
  214.            needFPLevel = 0
  215.         end
  216.   end
  217.   parse value(GetGraddLevel(bootDrive || '\os2\dll\gre2vman.dll')) with graddLevel graddStamp
  218.  
  219.   if (GetFPLevel() >= needFPLevel)
  220.   then do
  221.      newStamp   = 1
  222.   end
  223.   else call MsgExit MyGetMsg(SysGetMessage(MSG_INCORRECT_DOSVER))
  224.   rc = MSG_NO_ERROR
  225.  
  226. /*******************************************************
  227. * Setup path and Copy required files to \os2\install
  228. ********************************************************/
  229.  
  230.   oldPath = value('PATH',,env)
  231.   newPath = value('PATH', srcPath || ';' || oldPath, env)
  232.  
  233.   file1 = srcPath || 'unpack2.exe'
  234.   call SysFileTree file1,'file','F'
  235.   if file.0 == 0
  236.   then call LogFileNotFound file1
  237.   else call LogAndDoCmd 'copy ' || file1 || ' ' || installDir
  238.   rc = MSG_NO_ERROR
  239.   unpackFiles =                       'dspinstl.ex_'
  240.   unpackFiles = unpackFiles || ' ' || 'inscfg32.dl_'
  241.   unpackFiles = unpackFiles || ' ' || nlv || '\unpack'
  242.   unpackFiles = unpackFiles || ' ' || nlv || '\vgamri'
  243.   do i = 1 to words(unpackFiles)
  244.     call LogAndDoCmd 'unpack2 ' || srcPath || word(unpackFiles, i) || ' ' || bootDrive
  245.     if rc \= MSG_NO_ERROR then call MsgExit ""
  246.   end
  247.   call LogAndDoCmd 'unpack2 ' || srcPath || 'dspinstl.ex_ ' || restoreDir
  248.   if rc \= MSG_NO_ERROR then call MsgExit ""
  249.   call LogAndDoCmd 'copy ' || bootDrive || '\os2\dll\dspimri.dll ' || restoreDir
  250.   if rc \= MSG_NO_ERROR then call MsgExit ""
  251.  
  252. /********************************************************
  253. * Obtain .DSC file
  254. *********************************************************/
  255.  
  256.   call SysFileTree installDir || '\' || dscFile, 'file', 'F'
  257.   if file.0 == 0 then call MsgExit MyGetMsg(SysGetMessage(MSG_PRINT_FILE_NOT_FOUND,, '"' || installDir || '\' || dscFile || '"')),
  258.                                    || MyGetMsg(SysGetMessage(MSG_NO_META_MATCH))
  259.                  else parse value(file.1) with . . . . dscFile
  260.   dscFile = installDir || '\' || FileSpec('Name', dscFile)
  261.  
  262.   if SysFileTree(bootDrive || '\os2\video.cfg','file','F',,'+****') == 0
  263.     then call SysFileDelete bootDrive || '\os2\video.cfg'
  264.  
  265.   if translate(gradd) == 'VGA' then call SysIni ,'PM_DISPLAYDRIVERS','DEFAULTSYSTEMRESOLUTION','DELETE:'
  266.  
  267.   graddPackDSC = installDir || '\' || graddPackDSC
  268.   parse value(GetGraddLevel(srcPath || 'gre2vman.dll')) with . tmpStamp
  269.   if datatype(tmpStamp) == 'NUM' then newStamp = tmpStamp
  270.  
  271.   dspInstall = installDir || '\dspinstl.exe'
  272.  
  273.   if ((symbol('newStamp') == 'VAR') & (newStamp \= ''))
  274.   then
  275.      if ((graddStamp == '') | ( newStamp > graddStamp))
  276.      then do
  277.         '@' || dspInstall '/pk:other /s:' || srcDir,
  278.                        || ' /t:' || bootDrive,
  279.                        || ' /pd:' || strip(graddPackDSC),
  280.                        || ' /l:' || logFile || cidInst
  281.      end
  282.  
  283.   '@' || dspInstall '/pk:svga /s:' || srcDir,
  284.                  || ' /t:' || bootDrive,
  285.                  || ' /pd:' || strip(dscFile),
  286.                  || ' /l:' || logFile || cidInst
  287.  
  288.   if ( (rc == MSG_NO_ERROR) | ((cidInst \= '') & ( rc == SPTReboot)) )
  289.     then do
  290.       call LogAndDoCmd 'call ' || srcPath || nlv || '\makewps'
  291.       call MsgExit MyGetMsg(SysGetMessage(MSG_BOOT_MUST_RESTART))
  292.     end
  293.     else call MsgExit MyGetMsg(SysGetMessage(MSG_ERR_PROC_ARG,,dscFile))
  294.  
  295. /******************************************************
  296. * Procedure for determining level of Gradd subsystem
  297. *******************************************************/
  298.  
  299. GetGraddLevel: Procedure
  300.  
  301.    parse arg graddModule
  302.  
  303.    gtvVer = ''
  304.  
  305.    if stream(graddModule,'c', 'query exists') \= ''
  306.    then do
  307.        newQueue = RxQueue('Create')
  308.        oldQueue = RxQueue('Set', newQueue)
  309.        '@bldlevel 'graddModule '| rxqueue' newQueue
  310.        do while queued() \=0
  311.           parse upper pull tag data
  312.           if tag == 'SIGNATURE:'
  313.           then
  314.              do while queued() \= 0
  315.                parse upper pull tag data
  316.                if tag == 'DESCRIPTION:'
  317.                   then parse value(data) with  'V' gtvVer gtvStamp .
  318.              end
  319.        end
  320.        call RxQueue 'Delete', newQueue
  321.        call RxQueue 'Set', oldQueue
  322.    end
  323.  
  324.    if datatype(gtvVer)   \= 'NUM' then gtvVer = 0
  325.    if datatype(gtvStamp) \= 'NUM' then gtvStamp = 0
  326.  
  327.    return gtvVer gtvStamp
  328.  
  329. /******************************************************
  330. * Procedure for determining fix pack level of system
  331. *******************************************************/
  332.  
  333. GetFPLevel: Procedure
  334.  
  335.    newQueue = RxQueue('Create')
  336.    oldQueue = RxQueue('Set', newQueue)
  337.    '@ver /r | rxqueue' newQueue
  338.    do while queued() \=0
  339.       parse upper pull tag data
  340.       if tag == 'REVISION'
  341.       then leave
  342.    end
  343.    call RxQueue 'Delete', newQueue
  344.    call RxQueue 'Set', oldQueue
  345.  
  346.    return data
  347.  
  348. /******************************************************
  349. * Error message processing and exit
  350. *******************************************************/
  351.  
  352. MsgExit:
  353.  
  354.    parse arg errmsg
  355.  
  356.    result = rc
  357.    if rc == REXX_FUNCTION_NOT_FOUND
  358.     then do
  359.         say sigl'  +++      'SourceLine(sigl)
  360.         say 'REX0043: 'ErrorText(REXX_FUNCTION_NOT_FOUND)
  361.     end
  362.     else do
  363.       if errmsg == '' then errmsg = 'REXX' || right(rc,4,'0') || ': 'ErrorText(rc)
  364.       say errmsg
  365.       if ( (rc \= MSG_NO_ERROR) & ((cidInst \= '') & ( rc \= SPTReboot)) )
  366.         then do
  367.            exitmsg = MyGetMsg(SysGetMessage(MSG_INSTALL_UNSUCCESSFUL))
  368.            say exitmsg
  369.         end
  370.       if symbol('logfile') == 'VAR'
  371.         then do
  372.            call LogIt errmsg
  373.            if symbol('exitmsg') == 'VAR'
  374.              then do
  375.                call LogIt exitmsg
  376.                say MyGetMsg(SysGetMessage(MSG_INSTALL_HY_HDR)) || ' ' || logfile
  377.              end
  378.         end
  379.     end
  380.    if rc == MSG_INCORRECT_DOSVER
  381.    then '@pause && e ' || srcPath || nlv || '\readme.txt'
  382.    if symbol('oldPath') == 'VAR' then call value 'PATH' , oldPath, env
  383.    exit result
  384.  
  385. /******************************************************
  386. * Safely write to logfile
  387. *******************************************************/
  388.  
  389. LogAndDoCmd:
  390.  
  391.   call LogIt arg(1)
  392.   '@' || arg(1) || ' >> ' || logfile || ' 2>&1'
  393.   return
  394.  
  395. /******************************************************
  396. * Log File Not Found
  397. *******************************************************/
  398.  
  399. LogFileNotFound:
  400.  
  401.   call LogIt FileNotFound( arg(1) )
  402.   return
  403.  
  404. /******************************************************
  405. * File Not Found
  406. *******************************************************/
  407.  
  408. FileNotFound:
  409.  
  410.   return MyGetMsg(SysGetMessage(MSG_PRINT_FILE_NOT_FOUND,, '"' || arg(1) || '"'))
  411.  
  412. /******************************************************
  413. * Safely write to logfile
  414. *******************************************************/
  415.  
  416. LogIt: Procedure expose logfile
  417.  
  418.   parse arg message
  419.   call lineout logfile, message
  420.   call stream logfile, 'c', 'close'
  421.   return
  422.  
  423. /******************************************************
  424. * Remove SYSXXXX: from messages
  425. *******************************************************/
  426.  
  427. MyGetMsg: Procedure
  428.  
  429.   parse arg message
  430.   if pos('SYS', word(message, 1)) == 1
  431.     then parse arg . message
  432.   return message
  433.  
  434. /*****************************************************
  435. * Print usage and exit
  436. ******************************************************/
  437.  
  438. Usage:
  439.  
  440.   msg = MyGetMsg(SysGetMessage(MSG_USAGE,,srcName))
  441.   cmd = 'parse value(msg) with msg '''srcName''' .'
  442.   interpret cmd
  443.   say msg
  444.   say 'SET LANG = ll_cc'
  445.   say me || ' xxx [' || srcPath || '] [' || bootDrive || '] [/u]'
  446.   say ''
  447.   say '   ll_cc = ar_AA | pt_BR | zh_CN | de_DE | da_DK |'
  448.   say '           es_ES | el_GR | fi_FI | fr_FR | iw_IL |'
  449.   say '           it_IT | jp_JP | ko_KR | nl_NL | no_NO |'
  450.   say '           sv_SE | zh_TW | en_US | ...'
  451.   say ''
  452.   say '   xxx = GEN | SDD | VGA'
  453.   say ''
  454.   say '   MORE < ' srcPath || nlv || '\README.TXT'
  455.   say ''
  456.   exit 1
  457.