home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / netdorup.zip / ip20073.zip / NDCSD1.DSK / unc.dsk / LS30SP.CMD < prev    next >
OS/2 REXX Batch file  |  1993-09-29  |  19KB  |  399 lines

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