home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 29 Fixes_o / 29-Fixes_o.zip / us6035b1.dsk / CID_6035.CMD next >
OS/2 REXX Batch file  |  1993-11-10  |  19KB  |  398 lines

  1. /* REXX command file SERVPK  */
  2.  
  3. /*---------------------------------------------------*/
  4. /*                                                   */
  5. /*      This sample CID file is provided for use     */
  6. /*      as a template for remote installation of:    */
  7. /*                                                   */
  8. /*      OS/2 Extended Services 1.0                   */
  9. /*      Database Manager ServicePak                  */
  10. /*                                                   */
  11. /*---------------------------------------------------*/
  12. /*         DO NOT MODIFY THE NEXT EIGHT LINES        */
  13. /*---------------------------------------------------*/
  14.  
  15. parse ARG client logfile additional
  16.  
  17. QUEUE_REBOOT = 0
  18. CALL_AGAIN = 0
  19.  
  20. Call AddDLLFunctions
  21.  
  22. x.0.instprog = ''
  23. x.0.rspdir   = ''
  24. x.0.statevar = 'CAS_STATE'
  25. x.0.default  = ''
  26.  
  27.  
  28. /*---------------------------------------------------*/
  29. /*             MODIFICATIONS START HERE              */
  30. /*---------------------------------------------------*/
  31.  
  32. /*****************************************************/
  33. /*                 VARIABLES SECTION                 */
  34. /*****************************************************/
  35.  
  36. /*---------------------------------------------------*/
  37. /*         DO NOT REMOVE THE NEXT FOUR LINES         */
  38. /*              (They may be modified)               */
  39. /*---------------------------------------------------*/
  40.  
  41. bootdrive='c:'                                                  /* Boot Drive                             */
  42. configsys = bootdrive || '\CONFIG.SYS'                          /* Fully qualified path to CONFIG.SYS     */
  43. exepath = 'X:\EXE'                                              /* Path to executable directory on server */
  44. dllpath = 'X:\DLL;X:\IMG\LCU'                                   /* Paths to the DLL directories on server */
  45.  
  46.  
  47. /*---------------------------------------------------*/
  48. /* The next four lines are included to make it       */
  49. /* easier to change the version of OS/2 2.0 that is  */
  50. /* to be installed.                                  */
  51. /*                                                   */
  52. /* These variables are referenced in the product     */
  53. /* data sections for SEINST and SEMAINT.             */
  54. /*---------------------------------------------------*/
  55.  
  56. os2dir  = 'OS2V20'                                              /* Name of OS/2 2.0 directories         */
  57. os2img  = 'X:\IMG\' || os2dir                                   /* - product image directory            */
  58. os2rsp  = 'X:\RSP\' || os2dir                                   /* - response file directory            */
  59. os2log  = 'X:\LOG\' || os2dir                                       /* - log file directory                 */
  60.  
  61.  
  62. /*****************************************************/
  63. /*               PRODUCT DATA SECTION                */
  64. /*****************************************************/
  65.  
  66.  
  67. x.fservice = 12                                                 /* structure index                      */
  68. x.12.name='Extended Services 1.0 - Database Manager'            /* product name                         */
  69. x.12.statevar = 'CAS_' || x.12.name                             /* state variable name                  */
  70. x.12.instprog = 'x:\csd\cid_6035\fservice.exe                 ',  /* fully qualified install program name */
  71.                 '/s:x:\csd\cid_6035                           ',  /* - source directory                   */
  72.                 '/l1:x:\log\csd\cid_6035\' || client || '.log ',  /* - log file                           */
  73.                ' /r:'                                           /* - response file flag (auto selection)*/
  74. x.12.rspdir   = 'x:\csd\cid_6035'                                 /* response file directory              */
  75. x.12.default  = 'response.fil'                                  /* default response file                */
  76.  
  77. /*---------------------------------------------------*/
  78. /*         NUMBER OF PROGRAMS SET UP IN THE          */
  79. /*               PRODUCT DATA SECTION                */
  80. /*---------------------------------------------------*/
  81.  
  82. NUM_INSTALL_PROGS = 13
  83.  
  84.  
  85. /*---------------------------------------------------*/
  86. /*       DO NOT MODIFY OR REMOVE THE NEXT LINE       */
  87. /*---------------------------------------------------*/
  88.  
  89. OVERALL_STATE = GetEnvironmentVars()
  90.  
  91.  
  92. /*****************************************************/
  93. /*                  INSTALL SECTION                  */
  94. /*****************************************************/
  95.  
  96. Do Forever
  97.   Select
  98.     when OVERALL_STATE = 0 then do
  99.       if RunInstall(x.fservice)  == BAD_RC then exit            /* Install OS/2 Service Pak     */
  100.       Call CheckBoot                                            /* Reboot if it was requested   */
  101.     end
  102.   end
  103. end
  104. exit
  105.  
  106. /*    when OVERALL_STATE = 4 then do                     */
  107. /*      if RunInstall(x.esainst)  == BAD_RC then exit    */         /* Install ES                   */
  108. /*      Call CheckBoot                                   */         /* Reboot if it was requested   */
  109. /*    end                                                */
  110.  
  111. /*************************************************************/
  112. /*         DO NOT MODIFY ANY CODE BELOW THIS LINE !!!        */
  113. /*************************************************************/
  114.  
  115. RunInstall: procedure expose x. queue_reboot call_again configsys logfile client OVERALL_STATE
  116.   parse arg index, new_state, other
  117.   install = SetEnvironmentVar(x.index.statevar)
  118.   if install == YES then do
  119.     rc2 = LogMessage(72, x.index.name, '', logfile)             /* log an install starting msg  */
  120.     install_prog = 'CMD /C ' || strip(x.index.instprog)         /* build the command string     */
  121.  
  122.                                                 /* If automatic responst file selection was     */
  123.                                                 /* indicated, then get the response file name   */
  124.                                                 /* and append it to the command string.         */
  125.     if x.index.default <> '' then do
  126.       response_file = DetermineResponseFile(x.index.rspdir, client,
  127.                                             , x.index.default, x.index.name,
  128.                                             , logfile)
  129.       if response_file == '' then exit
  130.       install_prog = install_prog || response_file
  131.     end
  132.  
  133.     install_prog                                                /* Execute the install program  */
  134.  
  135.     state = value(x.index.statevar,,'OS2ENVIRONMENT')           /* Get the current install state*/
  136.                                                                 /* for this install program from*/
  137.                                                                 /* the environment.             */
  138.  
  139.                                                 /* Check the return code and set the global     */
  140.                                                 /* variables accordingly.                       */
  141.  
  142.     parse value ProcessReturnCode(rc, state, QUEUE_REBOOT, CALL_AGAIN, logfile),
  143.            with rc ',' state ',' QUEUE_REBOOT ',' CALL_AGAIN
  144.  
  145.     rc2 = value(x.index.statevar, state, 'OS2ENVIRONMENT')      /* Set the new install state for*/
  146.                                                                 /* this install program.        */
  147.  
  148.                                                 /* Put the install state into the CONFIG.SYS,   */
  149.                                                 /* if this action was unsuccessful, then exit.  */
  150.  
  151.     if PutStateVar(x.index.statevar, state, configsys, logfile) <> 0 then exit
  152.  
  153.     if rc == GOOD_RC then do
  154.       if pos('\SEMAINT', translate(install_prog)) <> 0 then     /* If the install program was   */
  155.         Call PreserveStartupCmd(install_prog)                   /* SEMAINT, then make sure      */
  156.                                                                 /* STARTUP.CMD won't be copied  */
  157.                                                                 /* over when SEINST runs.       */
  158.  
  159.       rc2 = LogMessage(70, x.index.name, '', logfile)           /* log an install successful msg*/
  160.       return GOOD_RC                                            /* return a good return code    */
  161.     end
  162.  
  163.     else do
  164.       rc2 = LogMessage(71, x.index.name, '', logfile)           /* log an install failed msg    */
  165.       if (new_state <> '') then                                 /* If a new state was requested,*/
  166.                                                                 /* then set OVERALL_STATE to the*/
  167.         rc2 = SetState(new_state, 'RunInstall', 2)              /* new state.                   */
  168.  
  169.       return BAD_RC                                             /* return a bad return code     */
  170.     end
  171.   end
  172.   return GOOD_RC
  173.  
  174.  
  175. /*************************************************************/
  176. PreserveStartupCmd: procedure
  177.  
  178.   parse upper arg string, other
  179.  
  180.   if pos('/T:', string) <> 0 then                               /* Determine if there is a      */
  181.     findvalue = '/T:'                                           /* target parameter.  If there  */
  182.   else                                                          /* is none, return.             */
  183.     if pos('-T:',string) <> 0 then
  184.       findvalue = '-T:'
  185.     else
  186.       return 0
  187.  
  188.   remain = substr(string, pos(findvalue, string) + 3)           /* Get the value of the target  */
  189.                                                                 /* parameter.                   */
  190.   blank = pos(' ', remain)
  191.  
  192.   if (blank <> 0) then
  193.     param = substr(remain, 1, blank-1)
  194.   else
  195.     param = remain
  196.                                                 /* Erase startup.lcu in the target directory,  */
  197.                                                 /* then rename startup.s13 to startup.lcu      */
  198.  
  199.   'if exist ' param || '\startup.lcu erase  ' param || '\startup.lcu'
  200.   'if exist ' param || '\startup.s13 rename ' param || '\startup.s13 *.lcu'
  201.  
  202.   return 0
  203.  
  204. /*************************************************************/
  205. GetEnvironmentVars: procedure expose X. NUM_INSTALL_PROGS
  206.  
  207.  
  208.   OVERALL_STATE = value(x.0.statevar,,'OS2ENVIRONMENT')         /* Get the overall install state */
  209.                                                                 /* from the environment.         */
  210.  
  211.   if OVERALL_STATE == '' then do                                /* If the overall install state  */
  212.     OVERALL_STATE = 0                                           /* has not been set yet, reset   */
  213.     do I=0 to NUM_INSTALL_PROGS by 1                            /* all the state vars to 0.      */
  214.       if x.I.statevar <> '' then
  215.         rc = value(x.I.statevar,'0','OS2ENVIRONMENT')
  216.     end
  217.   end
  218.  
  219.   return OVERALL_STATE
  220.  
  221.  
  222. /*************************************************************/
  223. SetEnvironmentVar: procedure
  224.   parse arg env_string, other
  225.   if env_string == '' then do                                   /* If the install program has   */
  226.                                                                 /* no state variable, then ...  */
  227.  
  228.     rc = value('REMOTE_INSTALL_STATE','0','OS2ENVIRONMENT')     /* Set the REMOTE_INSTALL_STATE */
  229.                                                                 /* to 0 so that the program     */
  230.                                                                 /* being run can know that is   */
  231.                                                                 /* being run in an unattended   */
  232.                                                                 /* environment.                 */
  233.  
  234.     return YES                                                  /* return install=yes           */
  235.  
  236.   end
  237.  
  238.   state = value(env_string,,'OS2ENVIRONMENT')                   /* Otherwise, get the value of  */
  239.                                                                 /* the state variable from the  */
  240.                                                                 /* environment.                 */
  241.  
  242.   if state <> '' then do                                        /* If the state variable exists */
  243.  
  244.     rc = value('REMOTE_INSTALL_STATE',state,'OS2ENVIRONMENT')   /* Set the REMOTE_INSTALL_STATE */
  245.                                                                 /* environment variable to the  */
  246.                                                                 /* value of the state variable. */
  247.  
  248.     return YES                                                  /* return install=yes           */
  249.   end
  250.   else                                                          /* Otherwise,                   */
  251.     return NO                                                   /* return install=no            */
  252.  
  253.  
  254. /*************************************************************/
  255. BootDriveIsDiskette:
  256.  
  257.   if IsBootDriveRemovable() == 1 then do                        /* If the drive booted from is  */
  258.                                                                 /* a diskette drive, then set   */
  259.     rc2 = SetState(OVERALL_STATE+1)                             /* the OVERALL_STATE to the     */
  260.                                                                 /* requested value.             */
  261.     return 'YES'
  262.  
  263.   end
  264.  
  265.   else                                                          /* else the machine was booted  */
  266.                                                                 /* from the hardfile.           */
  267.     return 'NO'
  268.  
  269. /*************************************************************/
  270. BootDriveIsFixedDisk:
  271.  
  272.   if IsBootDriveRemovable() == 0 then do                        /* If the drive booted from is  */
  273.                                                                 /* a fixed disk, then set       */
  274.     rc2 = SetState(OVERALL_STATE+1)                             /* the OVERALL_STATE to the     */
  275.                                                                 /* requested value.             */
  276.     return 'YES'
  277.  
  278.   end
  279.  
  280.   else                                                          /* else the machine was booted  */
  281.                                                                 /* from a diskette.             */
  282.     return 'NO'
  283.  
  284. /*************************************************************/
  285. SetState:
  286.   parse arg new_state, proc_name, param_num, other
  287.  
  288.     if datatype(new_state, number) <> 1 then do                 /* If the new state requested is*/
  289.                                                                 /* not numeric, then log an     */
  290.       if proc_name <> '' then                                   /* error.                       */
  291.         LogMessage(63, proc_name, param_num, logfile)
  292.       else
  293.         LogMessage(63, 'SetState', 1, logfile)
  294.  
  295.       exit
  296.     end
  297.  
  298.     OVERALL_STATE = new_state                                   /* Set the OVERALL_STATE to the */
  299.                                                                 /* new state requested.         */
  300.  
  301.     rc = value(x.0.statevar, new_state, 'OS2ENVIRONMENT')       /* Save the OVERALL_STATE in the*/
  302.                                                                 /* environment.                 */
  303.     return 'NO_ERROR'
  304.  
  305.  
  306. /*************************************************************/
  307. SaveStates:
  308.  
  309.   do I=0 to NUM_INSTALL_PROGS by 1            /* Put the install states into the CONFIG.SYS,  */
  310.     if x.I.statevar <> '' then                /* if this action was unsuccessful, then exit.  */
  311.  
  312.       if PutStateVar(x.I.statevar, value(x.I.statevar,,'OS2ENVIRONMENT'),
  313.                      , configsys, logfile) <> 0 then exit
  314.   end
  315.  
  316.   return
  317.  
  318. /*************************************************************/
  319. RebootAndGotoState:
  320.   parse arg new_state, other
  321.  
  322.   rc2 = SetState(new_state, 'RebootAndGotoState', 1)           /* Set the state to go to in    */
  323.                                                                /* OVERALL_STATE.               */
  324.  
  325.   Call SaveStates                                              /* Save the environment vars    */
  326.  
  327.   Call Reboot                                                  /* Reboot the machine           */
  328.  
  329.   return
  330.  
  331.  
  332. /*************************************************************/
  333. CheckBoot:
  334.   if QUEUE_REBOOT <> 0 then do                                  /* If a reboot has been queued  */
  335.                                                                 /* by an install program ...    */
  336.  
  337.     if CALL_AGAIN == 0 then                                     /* If no install programs want  */
  338.                                                                 /* to be recalled ...           */
  339.  
  340.       rc = SetState(OVERALL_STATE+1)                            /* Increment the overall state  */
  341.                                                                 /* variable.                    */
  342.  
  343.     Call SaveStates                                             /* Save the environment vars    */
  344.  
  345.     Call Reboot                                                 /* Reboot the machine           */
  346.  
  347.   end
  348.  
  349.   else                                                          /* Otherwise, increment the     */
  350.     rc = SetState(OVERALL_STATE+1)                              /* state variable and go on.    */
  351.  
  352.   return
  353.  
  354.  
  355. /*************************************************************/
  356. Reboot:
  357.   bootdrive
  358.  
  359.   rc = value('OS2_SHELL', bootdrive || '\OS2\CMD.EXE', 'OS2ENVIRONMENT')
  360.   rc = value('COMSPEC',   bootdrive || '\OS2\CMD.EXE', 'OS2ENVIRONMENT')
  361.  
  362.   'cls'
  363.   rc = AskRemoveDiskIfFloppy()
  364.  
  365.   pathlen = length(exepath)                                     /* Get length of exepath        */
  366.   posslash = lastpos("\",strip(exepath))                        /* Determine the last occurcnce */
  367.                                                                 /*   of '\' in exepath          */
  368.  
  369.   if posslash = pathlen then                                    /* If '\' is the last character */
  370.  
  371.     cmdline = exepath || 'SETBOOT /IBD:' || bootdrive           /* Then append 'SETBOOT'        */
  372.  
  373.   else
  374.  
  375.     cmdline = exepath || '\SETBOOT /IBD:' || bootdrive          /* Else append '\SETBOOT'       */
  376.  
  377.   LogMessage(74, '', '', logfile)                               /* Log a message indicating     */
  378.                                                                 /* reboot.                      */
  379.   cmdline
  380.  
  381.   LogMessage(73, 'SETBOOT', '', logfile)                        /* If the code gets to here, the*/
  382.                                                                 /* reboot failed.  Log a message*/
  383.   exit                                                          /* and exit.                    */
  384.  
  385.   return
  386.  
  387.  
  388. /*************************************************************/
  389. AddDLLFunctions:
  390.   Call RxFuncAdd 'ProcessReturnCode',     'CASAGENT', 'PROCESSRETURNCODE'
  391.   Call RxFuncAdd 'DetermineResponseFile', 'CASAGENT', 'DETERMINERESPONSEFILE'
  392.   Call RxFuncAdd 'PutStateVar',           'CASAGENT', 'PUTSTATEVAR'
  393.   Call RxFuncAdd 'LogMessage',            'CASAGENT', 'GETANDLOGMESSAGE'
  394.   Call RxFuncAdd 'AskRemoveDiskIfFloppy', 'CASAGENT', 'ASKREMOVEDISKIFFLOPPY'
  395.   Call RxFuncAdd 'IsBootDriveRemovable',  'CASAGENT', 'ISBOOTDRIVEREMOVABLE'
  396.  
  397.   return
  398.