home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / belongs2.zip / B2Inst.Cmd next >
OS/2 REXX Batch file  |  1995-08-26  |  7KB  |  224 lines

  1. /***************************************************************************/
  2. /* B2Inst.Cmd                                                              */
  3. /*                                                                         */
  4. /* Installs the "Belongs2" program in a hidden Startup folder.             */
  5. /*                                                                         */
  6. /* Revisions:                                                              */
  7. /*     08/26/95 1.1 - Added zipname and changed FATname to "Belongs2".     */
  8. /*     03/12/94 1.0 - Added return codes for CID.                          */
  9. /*     01/22/94 1.0 - Added code to hide subdirectory created for the      */
  10. /*                    Belongs2 executable file.                            */
  11. /*     12/20/93 1.0 - Created.                                             */
  12. /***************************************************************************/
  13.  
  14.    zipname = 'sample'
  15.    FATname = 'Belongs2'
  16.    exename = 'B e l o n g s 2'
  17.    targetdir = 'Belongs 2'
  18.    FATdir = 'BELONGS2'
  19.  
  20. /* Load REXX Utility Functions */
  21.  
  22.    if AddRexxUtil( 'SysCreateObject' ) then signal ERROR
  23.    if AddRexxUtil( 'SysFileTree' ) then signal ERROR
  24.    if AddRexxUtil( 'SysSetObjectData' ) then signal ERROR
  25.  
  26. /* Get arguments */
  27.  
  28.    parse upper arg targetdrive sourcepath extra
  29.  
  30. /* Verify target drive argument */
  31.  
  32.    do forever
  33.    /* Make sure the target drive is a drive letter "d" or "d:" */
  34.       if LENGTH( targetdrive ) > 2 then
  35.          say 'Too many characters - enter a drive letter'
  36.       else if LENGTH( targetdrive ) > 0 then do
  37.          if DATATYPE( SUBSTR( targetdrive, 1, 1 ), 'Mixed case' ) = 0 then
  38.             say 'First character must be a drive letter'
  39.          else do
  40.             if LENGTH( targetdrive ) = 1 then do
  41.                targetdrive = targetdrive':'
  42.                leave
  43.             end  /* Do */
  44.             else do
  45.                if SUBSTR( targetdrive, 2, 1 ) = ':' then
  46.                   leave
  47.                else do
  48.                   say 'Second character must be : or omitted'
  49.                end  /* Do */
  50.             end  /* Do */
  51.          end  /* Do */
  52.       end  /* Do */
  53.    /* Get the target drive */
  54.       say 'Enter drive where program executable is to be installed:'
  55.       pull targetdrive
  56.    end /* do */
  57.  
  58. /* Verify source path argument */
  59.  
  60.    do forever
  61.    /* Default to current directory */
  62.       if sourcepath = '' then
  63.          sourcepath = '.'
  64.    /* See if executable file exists in given path */
  65.       filespec = sourcepath'\'zipname'.EXE'
  66.       fullpath = stream( filespec, 'c', 'query exists' )
  67.       if fullpath = '' then do
  68.          if sourcepath = '.' then
  69.             sourcepath = directory()
  70.          say 'File' zipname'.EXE not found in' sourcepath
  71.       end  /* Do */
  72.       else
  73.          leave
  74.    /* Get the path */
  75.       say 'Enter path where installation files are located [.]:'
  76.       pull sourcepath
  77.    end /* do */
  78.  
  79. /* Suppress command display */
  80.  
  81.    '@echo off'
  82.  
  83. /* See if directory already exists */
  84.  
  85.    curdir = directory()
  86.    newdir = targetdrive'\'targetdir
  87.    if directory( newdir ) = newdir then do
  88.       say 'Directory "'targetdrive'\'targetdir'" (HPFS) already exists'
  89.    /* Change back to original directory */
  90.       call directory curdir
  91.    end  /* Do */
  92.    else do
  93.    /* Create directory */
  94.       'md "'targetdrive'\'targetdir'"'
  95.       if rc = 0 then
  96.          say 'Directory "'targetdrive'\'targetdir'" (HPFS) created'
  97.       else do
  98.       /* Try FAT file system */
  99.          targetdir = FATdir
  100.          exename = FATname
  101.          newdir = targetdrive'\'targetdir
  102.          if directory( newdir ) = newdir then do
  103.             say 'Directory "'targetdrive'\'targetdir'" (FAT) already exists'
  104.          /* Change back to original directory */
  105.             call directory curdir
  106.          end  /* Do */
  107.          else do
  108.          /* Create FAT directory */
  109.             'md "'targetdrive'\'targetdir'"'
  110.             if rc = 0 then
  111.                say 'Directory "'targetdrive'\'targetdir'" (FAT) created'
  112.             else do
  113.                say 'Unable to create directory on' targetdrive
  114.                signal ERROR
  115.             end  /* Do */
  116.          end  /* Do */
  117.       end  /* Do */
  118.    end  /* Do */
  119.  
  120. /* Hide the directory */
  121.  
  122.    rc = SysFileTree( newdir, 'files', 'D', '*+***', '**+**' )
  123.  
  124.    if rc then do
  125.       say 'SysFileTree command was not successful'
  126.       signal ERROR
  127.    end  /* Do */
  128.  
  129. /* Make sure directory was found */
  130.  
  131.    if files.0 = 0 then do
  132.       say 'Directory' newdir 'was not found'
  133.       say 'This should not occur, since the directory is being created'
  134.       signal ERROR
  135.    end  /* Do */
  136.  
  137. /* Make sure the directory was hidden */
  138.  
  139.    do i = 1 to files.0
  140.       if SUBSTR( files.i, 33, 1 ) = 'H' then
  141.          say 'Directory' SUBSTR( files.i, 38 ) 'has been hidden'
  142.       else do
  143.          say 'Directory' SUBSTR( files.i, 38 ) 'was not hidden'
  144.       end  /* Do */
  145.    end /* do */
  146.  
  147. /* Copy the executable file to the directory */
  148.  
  149.    'copy' fullpath '"'targetdrive'\'targetdir'\'exename'.EXE"' '/v'
  150.    if rc = 0 then
  151.       say 'Executable file copied to "'targetdrive'\'targetdir'"'
  152.    else do
  153.       say 'Unable to copy executable file to "'targetdrive'\'targetdir'"'
  154.       signal ERROR
  155.    end  /* Do */
  156.  
  157. /* Create hidden Startup folder */
  158.  
  159.    classname = 'WPStartup'
  160.    title     = '.'
  161.    location  = '<WP_NOWHERE>'
  162.    setup     = 'OBJECTID=<HIDDEN_STARTUP>;'
  163.  
  164.    result = SysCreateObject( classname, title, location, setup, 'f' )
  165.    if result = 1 /* created */ then
  166.       say 'Hidden startup folder created'
  167.    else do
  168.    /* See if object already exists */
  169.       result = SysSetObjectData( '<HIDDEN_STARTUP>', setup )
  170.       if result = 1 /* updated */ then
  171.          say 'Hidden startup folder already exists'
  172.       else do
  173.          say 'Unable to create hidden Startup folder'
  174.          signal ERROR
  175.       end  /* Do */
  176.    end  /* Do */
  177.  
  178. /* Create the program object */
  179.  
  180.    classname = 'WPProgram'
  181.    title     = '.'
  182.    location  = '<HIDDEN_STARTUP>'
  183.    setup     = 'OBJECTID=<BELONGS2_PROGRAM>;' || ,
  184.                'EXENAME='targetdrive'\'targetdir'\'exename'.EXE;' || ,
  185.                'PROGTYPE=PM;' || ,
  186.                'NODELETE=YES;NOMOVE=YES;NOTVISIBLE=YES;'
  187.  
  188.    result = SysCreateObject( classname, title, location, setup, 'f' )
  189.    if result = 1 /* created */ then
  190.       say 'Program object created'
  191.    else do
  192.    /* See if object already exists */
  193.       result = SysSetObjectData( '<BELONGS2_PROGRAM>', setup )
  194.       if result = 1 /* updated */ then
  195.          say 'Program object already exists'
  196.       else do
  197.          say 'Unable to create program object'
  198.          signal ERROR
  199.       end  /* Do */
  200.    end  /* Do */
  201.  
  202. /* Exit the REXX procedure */
  203.  
  204.    exit x2d(0000)
  205.  
  206. ERROR:
  207.    exit x2d(1604)
  208.  
  209. /* AddRexxUtil procedure */
  210.  
  211. AddRexxUtil: procedure
  212.  
  213.    parse arg name
  214.  
  215.    if RxFuncQuery( name ) \= 0 /* not registered */ then do
  216.       if RxFuncAdd( name, 'RexxUtil', name ) \= 0 /* not successful */ then do
  217.           say 'Unable to register REXX Utility Function' name
  218.           return 1  /* failure */
  219.       end  /* Do */
  220.    end  /* Do */
  221.  
  222.    return 0  /* success */
  223.  
  224.