home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 8 Other / 08-Other.zip / ma9609.zip / OS2PInst.Cmd < prev    next >
OS/2 REXX Batch file  |  1995-04-29  |  7KB  |  206 lines

  1. /***************************************************************************/
  2. /* OS2PInst.Cmd                                                            */
  3. /*                                                                         */
  4. /* Installs the "OS/2 Periodical Database"                                 */
  5. /*                                                                         */
  6. /* Revisions:                                                              */
  7. /*     04/29/95 1.0 - Changed name of database to OS/2 Periodical Database.*/
  8. /*     09/07/94 1.0 - Created.                                             */
  9. /***************************************************************************/
  10.  
  11.    objectid = '<OS2PUBDB>'
  12.  
  13.    FATname = 'OS2PUBS'
  14.    INFname = 'OS!2 Periodical Database'
  15.    targetdir = 'OS!2 Pubs'
  16.    FATdir = 'OS!2PUBS'
  17.  
  18. /* Load REXX Utility Functions */
  19.  
  20.    if AddRexxUtil( 'SysCreateObject' ) then signal ERROR
  21.    if AddRexxUtil( 'SysFileTree' ) then signal ERROR
  22.    if AddRexxUtil( 'SysSetObjectData' ) then signal ERROR
  23.  
  24. /* Get arguments */
  25.  
  26.    parse upper arg targetdrive sourcepath location extra
  27.  
  28. /* Verify target drive argument */
  29.  
  30.    do forever
  31.    /* Make sure the target drive is a drive letter "d" or "d:" */
  32.       if LENGTH( targetdrive ) > 2 then
  33.          say 'Too many characters - enter a drive letter'
  34.       else if LENGTH( targetdrive ) > 0 then do
  35.          if DATATYPE( SUBSTR( targetdrive, 1, 1 ), 'Mixed case' ) = 0 then
  36.             say 'First character must be a drive letter'
  37.          else do
  38.             if LENGTH( targetdrive ) = 1 then do
  39.                targetdrive = targetdrive':'
  40.                leave
  41.             end  /* Do */
  42.             else do
  43.                if SUBSTR( targetdrive, 2, 1 ) = ':' then
  44.                   leave
  45.                else do
  46.                   say 'Second character must be : or omitted'
  47.                end  /* Do */
  48.             end  /* Do */
  49.          end  /* Do */
  50.       end  /* Do */
  51.    /* Get the target drive */
  52.       say 'Enter drive where the OS/2 Periodical Database is to be installed:'
  53.       pull targetdrive
  54.    end /* do */
  55.  
  56. /* Verify source path argument */
  57.  
  58.    do forever
  59.    /* Default to current directory */
  60.       if sourcepath = '' then
  61.          sourcepath = '.'
  62.    /* See if the .INF file exists in the given path */
  63.       filespec = sourcepath'\'FATname'.INF'
  64.       fullpath = stream( filespec, 'c', 'query exists' )
  65.       if fullpath = '' then do
  66.          if sourcepath = '.' then
  67.             sourcepath = directory()
  68.          say 'File' FATname'.INF not found in' sourcepath
  69.       end  /* Do */
  70.       else
  71.          leave
  72.    /* Get the path */
  73.       say 'Enter path where installation files are located [.]:'
  74.       pull sourcepath
  75.    end /* do */
  76.  
  77. /* See if the .INF file exists in the given path */
  78.  
  79.    filespec = sourcepath'\'FATname'.ICO'
  80.    iconfull = stream( filespec, 'c', 'query exists' )
  81.    if iconfull = '' then do
  82.       if sourcepath = '.' then
  83.          sourcepath = directory()
  84.       say 'File' FATname'.ICO not found in' sourcepath
  85.    end  /* Do */
  86.  
  87. /* If no location specified, put it on the desktop */
  88.  
  89.    if location = '' then
  90.       location = '<WP_DESKTOP>'
  91.  
  92. /* Suppress command display */
  93.  
  94.    '@echo off'
  95.  
  96. /* See if directory already exists */
  97.  
  98.    curdir = directory()
  99.    newdir = targetdrive'\'targetdir
  100.    if directory( newdir ) = newdir then do
  101.       say 'Directory "'targetdrive'\'targetdir'" (HPFS) already exists'
  102.    /* Change back to original directory */
  103.       call directory curdir
  104.    end  /* Do */
  105.    else do
  106.    /* Create directory */
  107.       'md "'targetdrive'\'targetdir'"'
  108.       if rc = 0 then
  109.          say 'Directory "'targetdrive'\'targetdir'" (HPFS) created'
  110.       else do
  111.       /* Try FAT file system */
  112.          targetdir = FATdir
  113.          INFname = FATname
  114.          newdir = targetdrive'\'targetdir
  115.          if directory( newdir ) = newdir then do
  116.             say 'Directory "'targetdrive'\'targetdir'" (FAT) already exists'
  117.          /* Change back to original directory */
  118.             call directory curdir
  119.          end  /* Do */
  120.          else do
  121.          /* Create FAT directory */
  122.             'md "'targetdrive'\'targetdir'"'
  123.             if rc = 0 then
  124.                say 'Directory "'targetdrive'\'targetdir'" (FAT) created'
  125.             else do
  126.                say 'Unable to create directory on' targetdrive
  127.                signal ERROR
  128.             end  /* Do */
  129.          end  /* Do */
  130.       end  /* Do */
  131.    end  /* Do */
  132.  
  133. /* Check the directory */
  134.  
  135.    rc = SysFileTree( newdir, 'files', 'D', '*+***' )
  136.  
  137.    if rc then do
  138.       say 'SysFileTree command was not successful'
  139.       signal ERROR
  140.    end  /* Do */
  141.  
  142. /* Make sure directory was found */
  143.  
  144.    if files.0 = 0 then do
  145.       say 'Directory' newdir 'was not found'
  146.       say 'This should not occur, since the directory is being created'
  147.       signal ERROR
  148.    end  /* Do */
  149.  
  150. /* Copy the .INF file to the specified directory */
  151.  
  152.    'copy' fullpath '"'targetdrive'\'targetdir'\'INFname'.Inf"' '/v'
  153.    if rc = 0 then
  154.       say INFname'.Inf copied to "'targetdrive'\'targetdir'"'
  155.    else do
  156.       say 'Unable to copy' INFname'.Inf to "'targetdrive'\'targetdir'"'
  157.       signal ERROR
  158.    end  /* Do */
  159.  
  160. /* Create the program object */
  161.  
  162.    classname = 'WPProgram'
  163.    title     = 'OS/2 Periodical^Database'
  164.    setup     = 'OBJECTID='objectid';' || ,
  165.                'EXENAME=VIEW.EXE;' || ,
  166.                'PARAMETERS="'targetdrive'\'targetdir'\'INFname'" ABOUT;' || ,
  167.                'ICONFILE='iconfull';' || ,
  168.                'PROGTYPE=PM;'
  169.  
  170.    result = SysCreateObject( classname, title, location, setup, 'f' )
  171.    if result = 1 /* created */ then
  172.       say 'Program object created'
  173.    else do
  174.    /* See if object already exists */
  175.       result = SysSetObjectData( objectid, setup )
  176.       if result = 1 /* updated */ then
  177.          say 'Program object already exists'
  178.       else do
  179.          say 'Unable to create program object'
  180.          signal ERROR
  181.       end  /* Do */
  182.    end  /* Do */
  183.  
  184. /* Exit the REXX procedure */
  185.  
  186.    exit x2d(0000)
  187.  
  188. ERROR:
  189.    exit x2d(1604)
  190.  
  191. /* AddRexxUtil procedure */
  192.  
  193. AddRexxUtil: procedure
  194.  
  195.    parse arg name
  196.  
  197.    if RxFuncQuery( name ) \= 0 /* not registered */ then do
  198.       if RxFuncAdd( name, 'RexxUtil', name ) \= 0 /* not successful */ then do
  199.           say 'Unable to register REXX Utility Function' name
  200.           return 1  /* failure */
  201.       end  /* Do */
  202.    end  /* Do */
  203.  
  204.    return 0  /* success */
  205.  
  206.