home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / rc321.zip / install.cmd < prev    next >
OS/2 REXX Batch file  |  1997-12-01  |  16KB  |  376 lines

  1. /* ------------------------------------------------------------------ */
  2. /* install program for REXXCC.CMD                                     */
  3. /*                                                                    */
  4. /* Initial Release:                                                   */
  5. /*    11.08.1994 /bs                                                  */
  6. /* Last Update:                                                       */
  7. /*    04.06.1995 /bs                                                  */
  8. /*      - corrected a bug, if installing in a relativ entered         */
  9. /*        directory (like for example: "..")                          */
  10. /*      - added code to support archives with missing                 */
  11. /*        EAs for REXXCC.                                             */
  12. /*      - added code to cleanup the install directory                 */
  13. /*        after the installation                                      */
  14. /*      - deleted code to install REXXCCW                             */
  15. /*      - added code to install REXXCC/2 instead of                   */
  16. /*        the old WPS frontend REXXCCW                                */
  17. /*    16.10.1995 /bs                                                  */
  18. /*      - added code to install UPCKREXX.CMD                          */
  19. /*    09.09.1997 /bs                                                  */
  20. /*      - added code to install REXXCCM.CMD                           */
  21. /*      - corrected some errors in the statements to call CMD         */
  22. /*        commands.                                                   */
  23. /*                                                                    */
  24. /*                                                                    */
  25. /* Usage:                                                             */
  26. /*    install                                                         */
  27. /*                                                                    */
  28. /* written by: Bernd Schemmer, Baeckerweg 48, D-60316 Frankfurt       */
  29. /*             Germany, CompuServe: 100104,613                        */
  30. /*                                                                    */
  31. /* Note: This file needs the OS/2 REXX dll REXXUTIL                   */
  32. /* ------------------------------------------------------------------ */
  33.  
  34. /* ------------------------------------------------------------------ */
  35.                         /* install error handlers                     */
  36.  
  37.   signal on error  Name ErrorAbort
  38.   signal on halt   Name UserAbort
  39.   signal on syntax Name ErrorAbort
  40.  
  41. /* ------------------------------------------------------------------ */
  42.                         /* get drive, path and name of this program   */
  43.  
  44.   parse source . . prog.__FullName
  45.   prog.__Drive     = filespec( "drive", prog.__FullName )
  46.   prog.__Path      = filespec( "path",  prog.__FullName )
  47.   prog.__Dir       = prog.__Drive || prog.__Path
  48.   prog.__Name      = filespec( "name",  prog.__FullName )
  49.   prog.__Env       = 'OS2ENVIRONMENT'
  50.   prog.__Version   = 'V3.21'
  51.   prog.__CurDir    = directory()
  52.   prog.__ExitCode  = 1          /* return code of INSTALL.CMD         */
  53.   prog.__Files     = 'REXXCC*.*'
  54.   prog.__UFiles    = 'UPCKREXX.*'
  55.   prog.__rxFiles   = 'RX*.*'    /* files for Rexx Dialog              */
  56.  
  57. /* ------------------------------------------------------------------ */
  58.                         /* save the OS/2 environment                  */
  59.   call setlocal
  60.  
  61. /* ------------------------------------------------------------------ */
  62.                         /* flush the keyobard buffer                  */
  63.   do while lines() <> 0
  64.     dummy = lineIn()
  65.   end /* do while lines() <> 0 */
  66.  
  67. /* ------------------------------------------------------------------ */
  68.                         /* load REXXUTIL                              */
  69.   call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs' 
  70.   call SysLoadFuncs
  71.  
  72. /* ------------------------------------------------------------------ */
  73.                         /* show the logo                              */
  74.  
  75.   do until InstallPath <> ''
  76.     '@cls'
  77.     Say '1B'x || '[0;m ' || '1B'x || '[7;m' || '╔' || Left( '═', 75, '═' ) || '╗ '
  78.     Say '1B'x || '[0;m ' || '1B'x || '[7;m' || '║' || Center( ' Installation program for REXXCC',75 ) || '║ '
  79.     Say '1B'x || '[0;m ' || '1B'x || '[7;m' || '║' || Center( 'Version ' || prog.__Version, 75 ) || '║ '
  80.     Say '1B'x || '[0;m ' || '1B'x || '[7;m' || '║' || Center( '(c) Bernd Schemmer 1994,1997',75 ) || '║ '
  81.     Say '1B'x || '[0;m ' || '1B'x || '[7;m' || '╚' || Left( '═',75,'═' ) || '╝ '
  82.     Say '1B'x || '[0;m'
  83.  
  84.     say ' Enter the target directory for REXXCC ("." for current dir, "exit" to abort)'
  85.     call CharOut , ' >> '
  86.  
  87.     parse upper pull installPath
  88.     installPath = strip( InstallPath )
  89.     if installPath = 'EXIT' then
  90.       signal UserAbort
  91.   end /* do until InstallPath <> '' */
  92.  
  93.                     /* delete a trailing backslash if neccessary      */
  94.   if right( installPath, 1 ) = '\' then
  95.     installPath = substr( installPath, 1, length( installPath ) - 1 )
  96.  
  97.                     /* get the full name of the target directory      */
  98.   testPath = stream( installPath || '\*.*', 'c', 'QUERY EXIST' )
  99.  
  100.   if testPath <> '' then
  101.     testPath = fileSpec( "drive", TestPath ) || ,
  102.                fileSpec( "path",  TestPath )
  103.   else
  104.     testPath = installPath
  105.  
  106.                     /* delete a trailing backslash if neccessary      */
  107.   if right( testPath, 1 ) = '\' then
  108.     testPath = substr( testPath, 1, length( testPath ) - 1 )
  109.  
  110.   say ''
  111.   say ' Installing REXXCC into the directory '
  112.   say '  ' || testPath || ' '
  113.  
  114.   if translate( testPath ) || '\' = translate( prog.__dir ) then
  115.     call ShowError  'You can not use the installation directory as target directory!'
  116.  
  117.                     /* check if the target directory exist            */
  118.   curDir = directory()
  119.   newDirExist = directory( installPath ) <> ''
  120.   call directory curDir
  121.  
  122.   if NewDirExist = 0 then
  123.   do
  124.     say ''
  125.     thisKey = AskUser( 'YNQX', ' The directory does not exist. Create it (Y/N)? ' )
  126.     if thisKey <> 'Y' then
  127.       signal programAbort
  128.  
  129.     say ' Creating the directory'
  130.     say '  ' || installPath || ' ...'
  131.     '@md ' installPath '1>NUL'
  132.     if rc <> 0 then
  133.       call ShowError 'OS Error ' || rc || ' creating the directory "' || installPath || '"!'
  134.   end /* if directory( installPath = '' ) then */
  135.  
  136.                     /* get the full name of the target directory      */
  137.   call directory installpath
  138.   installPath = directory()
  139.   call directory curDir
  140.  
  141.   if stream( installPath || '\' || prog.__Files, 'c', 'QUERY EXIST' ) <> '' then
  142.   do
  143.     say ''
  144.     say ' Installed version of REXXCC detected in the target directory.'
  145.     thisKey = AskUser( 'YNQX', ' Delete the old version (Y/N)? ')
  146.     if thisKey <> 'Y' then
  147.       signal programAbort
  148.  
  149.     say ''
  150.     say ' Deleting the old version of REXXCC in the directory '
  151.     say '  ' || installPath || ' ...'
  152.  
  153.     '@attrib -r ' installPath || '\' || prog.__Files '1>NUL'
  154.     if rc <> 0 then
  155.       '@del ' installPath || '\' || prog.__Files '1>NUL'
  156.  
  157.     if rc <> 0 then
  158.       call ShowError 'OS Error ' || rc || ' deleting the old version!'
  159.  
  160.             /* delete the object for the old WPS frontend REXXCCW     */
  161.     call SysDestroyObject '<REXXCCW>'
  162.  
  163.         /* delete an existing object for the new frontend REXXCC/2    */
  164.     call SysDestroyObject '<REXXCC/2>'
  165.   end /* if stream( ... */
  166.  
  167.   say ''
  168.   say ' Copying the files for REXXCC to '
  169.   say '  ' || installPath || ' ...'
  170.   '@copy /f  ' prog.__dir || prog.__Files ' ' installPath || '\' || prog.__Files '1>NUL'
  171.   if rc <> 0 then
  172.     call ShowError 'OS Error ' || rc || ' copying the files!'
  173.  
  174.   say ''
  175.   say ' Copying the files for UPCKREXX to '
  176.   say '  ' || installPath || ' ...'
  177.   '@copy /f  ' prog.__dir || prog.__uFiles ' ' installPath || '\' || prog.__uFiles '1>NUL'
  178.   if rc <> 0 then
  179.     call ShowError 'OS Error ' || rc || ' copying the files!'
  180.  
  181.   say ''
  182.   say ' Copying the files for REXXCC/2 to '
  183.   say '  ' || installPath || ' ...'
  184.   '@copy /f  ' prog.__dir || prog.__rxFiles ' ' installPath || '\' || prog.__rxFiles '1>NUL'
  185.   if rc <> 0 then
  186.     call ShowError 'OS Error ' || rc || ' copying the files!'
  187.  
  188.                                 /* check the EAs of REXXCC.CMD        */
  189.   thisRC = SysGetEA( InstallPath || '\' || 'REXXCC.CMD',,
  190.                'REXX.TOKENSIMAGE' ,,
  191.                testVar )
  192.  
  193.   if thisRC <> 0 | length( testVar ) < 100  then
  194.   do
  195.                         /* EAs are missing or invalid -- reAttach     */
  196.                         /* the EAs to the file REXXCC.CMD             */
  197.     say ' The EAs of REXXCC are missing or invalid. Reattaching the EAs to REXXCC ...'
  198.     '@attrib -r '  InstallPath || '\' || 'REXXCC.CMD >NUL'
  199.     '@EAUTIL ' InstallPath || '\' || 'REXXCC.CMD' InstallPath || '\' || 'REXXCC.EA' '/J /O /P'
  200.   end /* if SysGetEA( ...*/
  201.  
  202.                         /* set the read-only attribute for the files  */
  203.                         /* to avoid deleting them                     */
  204.   '@attrib +r  ' installPath || '\' || prog.__Files '1>NUL'
  205.   '@cls'
  206.   say '1B'x || '[0;m ' || '1B'x || '[7;m' || '╔' || Left( '═', 75, '═' ) || '╗'
  207.   say '1B'x || '[0;m ' || '1B'x || '[7;m' || '║' || Center( '',75 ) || '║'
  208.   say '1B'x || '[0;m ' || '1B'x || '[7;m' || '║' || Center( ' REXXCC includes a WPS frontend named REXXCC/2. This is a little program',75 ) || '║'
  209.   say '1B'x || '[0;m ' || '1B'x || '[7;m' || '║' || Center( ' to enter the parameter for REXXCC in common dialog boxes rather',75 ) || '║'
  210.   say '1B'x || '[0;m ' || '1B'x || '[7;m' || '║' || Center( ' than entering them on the commandline.',75 ) || '║'
  211.   say '1B'x || '[0;m ' || '1B'x || '[7;m' || '║' || Center( '',75 ) || '║'
  212.   say '1B'x || '[0;m ' || '1B'x || '[7;m' || '║' || Center( ' Note for users of previous versions of REXXCC:',75 ) || '║'
  213.   say '1B'x || '[0;m ' || '1B'x || '[7;m' || '║' || Center( ' REXXCC/2 is the successor of REXXCCW. REXXCC/2 won''t need VREXX2 anymore.',75 ) || '║'
  214.   say '1B'x || '[0;m ' || '1B'x || '[7;m' || '║' || Center( '',75 ) || '║'
  215.   say '1B'x || '[0;m ' || '1B'x || '[7;m' || '╚' || Left( '═',75,'═' ) || '╝'
  216.   say '1B'x || '[0;m'
  217.   thisKey = AskUser( 'YNQ', ' Should I create an object for REXXCC/2 (Y/N)? ' )
  218.  
  219.   if thisKey = 'Y' then
  220.   do
  221.     say ' Creating an object for REXXCC/2 on your desktop ...'
  222.  
  223.      objectID  = '<REXXCC/2>'
  224.         title  = 'REXXCC/2'
  225.     className  = 'WPProgram'
  226.      location  = '<WP_DESKTOP>'
  227.         setup  = 'EXENAME=' || installPath || '\RX.EXE'          || ';' || ,
  228.                  'PARAMETERS=' || installPath || '\REXXCC2.CMD'  || ';' || ,
  229.                  'STARTUPDIR=' || installpath                    || ';' || ,
  230.                  'ICONFILE=' || installPath || '\REXXCC2.ICO'    || ';' || ,
  231.                  'PROGTYPE='   || 'PM'                           || ';' || ,
  232.                  'NODROP='     || 'YES'                          || ';' || ,
  233.                  'OBJECTID='   || objectID                       || ';'
  234.     UpdateFlag = 'U'
  235.  
  236.     thisRC = SysCreateObject( className, title, location, setup , updateFlag )
  237.     if thisRC <> 1 then
  238.     do
  239.       say ' Oops, can not create the object for REXXCC/2.' || '07'x
  240.       say ' You must create it by hand.'
  241.       say ''
  242.     end /* if thisRC <> 1 */
  243.     else
  244.       prog.__ExitCode = 0
  245.  
  246.   end /* if thisKey = 'Y' then */
  247.  
  248.   thisKey = AskUser( 'YNQ', ' Should I cleanup the installation directory (Y/N)? ' )
  249.   if thiskey= 'Q' then
  250.     signal ProgramAbort
  251.  
  252.   if thiskey = 'Y' then
  253.   do
  254.     say ' Cleaning the directory '
  255.     say '  ' || prog.__dir ' ...'
  256.  
  257.      call directory prog.__dir
  258.      filesToDelete = prog.__files prog.__uFiles prog.__rxFiles ,
  259.                      'INSTALL.CMD INSTALL.ICO README.CMD FILE_ID.DIZ'
  260.      do i = 1 to words( filesToDelete )
  261.        SIGNAL OFF ERROR
  262.        curFile = word( filesToDelete, i )
  263.        '@attrib -r ' || curFile  '2>NUL 1>NUL'
  264.        '@del ' curFile '2>NUL 1>NUL'
  265.      end /* do */
  266.  
  267.   end /* if thisKey = 'Y' then */
  268.  
  269.   prog.__ExitCode = 0
  270.  
  271. programEnd:
  272.  
  273.   say ' REXXCC successfully installed in the directory '
  274.   say '  ' || installPath || '.'
  275.  
  276. programExit:
  277.                         /* restore the OS/2 environment               */
  278.   call endlocal
  279. exit prog.__ExitCode
  280.  
  281. /* ------------------------------------------------------------------ */
  282. /* AskUser - get input from the user                                  */
  283. /*                                                                    */
  284. /* Usage:    AskUser akeys, prompt                                    */
  285. /*                                                                    */
  286. /* where:    akeys - allowed keys (all keys are translated to         */
  287. /*                   uppercase)                                       */
  288. /*           prompt - prompt for the ask                              */
  289. /*                                                                    */
  290. /* Returns:  the pressed key in uppercase                             */
  291. /*                                                                    */
  292. AskUser:
  293.   parse arg aKeys, prompt
  294.  
  295.   aKeys = translate( akeys )
  296.  
  297.   call charout ,  prompt
  298.  
  299.   thisKey = ' '
  300.   do UNTIL pos( thisKey ,  aKeys ) <> 0
  301.     call charOut ,'1B'x || '[s' || '1B'x || '[K' || '' || '07'x
  302.     thisKey = translate( charIn() )
  303.     call CharOut , '1B'x || '[u'
  304.     dummy = lineIn()
  305.   end /* do until ... */
  306.   say ''
  307.  
  308. RETURN thisKey
  309.  
  310. /* ------------------------------------------------------------------ */
  311. /* show an error message and end the program                          */
  312. /*                                                                    */
  313. ShowError:
  314.   parse arg errorMessage
  315.  
  316.   say ''
  317.   say ' REXXCC Install - Error: '
  318.   say '  ' || errorMessage || '07'x
  319.  
  320. programAbort:
  321.   say ''
  322.   say ' Installation aborted.'
  323. signal ProgramExit
  324.  
  325. /* ------------------------------------------------------------------ */
  326. /* error handler                                                      */
  327.  
  328. ErrorAbort:
  329.   thisLineNo = sigl
  330.  
  331.   say ''
  332.   say ''
  333.   say ' ------------------------------------------------------------------ '
  334.   say ' ' || prog.__Name || ' - Unexpected error ' || rc || ' in line ' || thisLineNo || ' detected!'
  335.   say ''
  336.  
  337.   say ' The line reads: '
  338.  
  339.   thisprefix = ' *-* '
  340.  
  341.   do forever
  342.     thisSourceLine = sourceLine( thisLineNo )
  343.     say thisPrefix || thisSourceLine
  344.     if right( strip( thisSourceLine ) ,1,1 ) <> ',' then
  345.       leave
  346.     thisLineNo = thisLineNo +1
  347.     thisPrefix = '     '
  348.   end /* do forever */
  349.  
  350.   if datatype( rc, 'W' ) = 1 then
  351.     if rc > 0 & rc < 100 then
  352.     do
  353.      say ''
  354.      say ' The REXX error message is: ' errorText( rc )
  355.     end /* if datatype( rc, 'W' ) = 1 then */
  356.  
  357.   say ' ------------------------------------------------------------------ '
  358.   say ''
  359.  
  360.   prog.__ExitCode = 255
  361. signal ProgramExit
  362.  
  363. /* break handler */
  364. UserAbort:
  365.     say ''
  366.     say ' ------------------------------------------------------------------ '
  367.     say ' ' || prog.__Name || ' - Unexpected error 997 detected!'
  368.     say ''
  369.     say ' The error message is: Program aborted by the user!'
  370.     say ' ------------------------------------------------------------------ '
  371.     say ''
  372.  
  373.   prog.__ExitCode = 254
  374. signal ProgramExit
  375.  
  376.