home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / uupc2pop.zip / su.cmd < prev    next >
OS/2 REXX Batch file  |  1996-07-16  |  6KB  |  158 lines

  1. /*--------------------------------------------------------------------*/
  2. /*          Program:    su.cmd            3 May 1993                  */
  3. /*          Author:     Andrew H. Derbyshire                          */
  4. /*          Address:    Kendra Electronic Wonderworks                 */
  5. /*                      P.O. Box 132                                  */
  6. /*                      Arlington, MA 02174                           */
  7. /*          Internet:   help@kew.com                                  */
  8. /*          Language:   OS/2 2.0 REXX                                 */
  9. /*          Function:   Report mail waiting for users                 */
  10. /*        Parameters:   None                                          */
  11. /*       Environment:   Assumes OS/2 Environment variable             */
  12. /*                      UUPCSYSRC has been set to name of UUPC/       */
  13. /*                      extended system configuration file, and       */
  14. /*                      TEMP variable been set if not defined         */
  15. /*                      in UUPC/extended.                             */
  16. /*--------------------------------------------------------------------*/
  17.  
  18. /*--------------------------------------------------------------------*/
  19. /*       Copyright 1989-1996 By Kendra Electronic Wonderworks;        */
  20. /*       may be distributed freely if original documentation and      */
  21. /*       source are included, and credit is given to the authors.     */
  22. /*       For additional instructions, see README.PRN in UUPC/         */
  23. /*       extended documentation archive.                              */
  24. /*--------------------------------------------------------------------*/
  25.  
  26. /*--------------------------------------------------------------------*/
  27. /*       REXX function to change effective user id and optionally     */
  28. /*       run a command as that user.                                  */
  29. /*--------------------------------------------------------------------*/
  30.  
  31. /*  Revised for use with TIN and TRN news software (and maybe some others */
  32. /*  by John D. Carmack of Mome Raths BBS, 10 Nov 95.                      */
  33. /*                                                                        */
  34. /*  Revision update 26 Jan 96.                                            */
  35. /*  Namely, these changes affect the way that the HOME and USER variables */
  36. /*  are looked at.  Useful for TIN, TRN and Yarn, as well as some others. */
  37.  
  38. /*
  39.  *       $Id: su.cmd 1.10 1996/01/01 21:16:32 ahd Exp $
  40.  *
  41.  *       $Log: su.cmd $
  42.  *       Revision 1.10  1996/01/01 21:16:32  ahd
  43.  *       Annual Copyright Update
  44.  *
  45.  *       Revision 1.9  1995/01/02 00:32:29  ahd
  46.  *       Handle environment without UUPCUSRRC set (use LOGNAME)
  47.  *
  48.  *       Revision 1.8  1994/12/27 23:37:01  ahd
  49.  *       Add contributed fix to allow running rexx scripts within SU.CMD
  50.  *
  51.  *       Revision 1.7  1994/12/22 00:29:29  ahd
  52.  *       Annual Copyright Update
  53.  *
  54.  *       Revision 1.6  1994/05/23 23:16:48  ahd
  55.  *       Correct copyright
  56.  *       Normalize to only one trailing backslash in name
  57.  *
  58.  *       Revision 1.5  1994/05/04  02:05:03  ahd
  59.  *       Also set LOGNAME for various OS/2 programs
  60.  *
  61.  *Revision 1.4  1994/01/01  19:16:19  ahd
  62.  *Annual Copyright Update
  63.  *
  64.  *      Revision 1.3  1993/05/09  03:51:26  ahd
  65.  *      Don't uppercase the input
  66.  *
  67.  *      Revision 1.2  1993/05/04  00:25:58  ahd
  68.  *      COnvert to REXX
  69.  *
  70.  *
  71.  */
  72.  
  73. '@echo off'
  74. signal on novalue
  75. parse source stuff
  76. Call RxFuncAdd 'SysLoadFuncs','RexxUtil','SysLoadFuncs'
  77. Call 'SysLoadFuncs'
  78. parse arg who what;
  79. if words(who) = 0 then
  80. do;
  81.    say 'SU.CMD Copyright 1989-1996 Kendra Electronic Wonderworks';
  82.    say 'No user specified to SU to';
  83.    exit 1;
  84. end;
  85. who = strip(who);
  86.  
  87. confdir = getuupc("CONFDIR")
  88. if confdir == '' then
  89. do
  90.    say 'No configuration directory defined, cannot continue'
  91.    exit 98
  92. end
  93. /*--------------------------------------------------------------------*/
  94. /*                  Don't double the last backslash                   */
  95. /*--------------------------------------------------------------------*/
  96. if  right( confDir , 1 ) == '\' then
  97.    confDir = left(confDir, length( confdir ) - 1);
  98.  
  99. uupcusrc = confDir || '\' || who || '.RC'
  100. who      = getuupc("MAILBOX",who,uupcusrc)
  101. home = getuupc("HOME",who,uupcusrc)
  102.  
  103. if \ exist( uupcusrc ) then
  104. do;
  105.    say uupcusrc 'does not exist!  Please verify' who 'is a valid user'
  106.    exit 97;
  107. end;
  108.  
  109. call SetLocal;
  110. uupcusrc = value( 'UUPCUSRRC',uupcusrc,'OS2ENVIRONMENT');
  111. logname = value( 'LOGNAME',who,'OS2ENVIRONMENT');
  112. user = value( 'USER',who,'OS2ENVIRONMENT');
  113. home = value('HOME',home,'OS2ENVIRONMENT');
  114.  
  115. if words(what) == 0 then
  116. do;
  117.    prompt = 'Enter EXIT to logout from' who || '$_' || ,
  118.             value( 'PROMPT',,'OS2ENVIRONMENT');       /* Make new prompt */
  119.    prompt = value( 'PROMPT',prompt,'OS2ENVIRONMENT'); /* Set new prompt  */
  120.    value( 'COMSPEC',,'OS2ENVIRONMENT');
  121.    prompt = value( 'PROMPT',prompt,'OS2ENVIRONMENT'); /* Restore prompt   */
  122. end;
  123. else
  124.    value( 'COMSPEC',, 'OS2ENVIRONMENT') "/C" what
  125.  
  126. uupcusrc = value( 'UUPCUSRRC',uupcusrc,'OS2ENVIRONMENT');
  127.                                  /* Restore original value           */
  128. logname = value( 'LOGNAME',logname,'OS2ENVIRONMENT');
  129. user = value('USER',user,'OS2ENVIRONMENT');
  130. home = value('HOME',home,'OS2ENVIRONMENT');
  131. call endlocal;
  132. exit rc;
  133.  
  134. /*--------------------------------------------------------------------*/
  135. /*    e x i s t                                                       */
  136. /*                                                                    */
  137. /*    Report whether or not a file exists                             */
  138. /*--------------------------------------------------------------------*/
  139. exist: procedure
  140. parse arg file
  141. xrc = SysFileTree(file, 'data.','F')
  142. if data.0 == 0 then
  143.    return 0
  144. else
  145.    return 1
  146.  
  147. /*--------------------------------------------------------------------*/
  148. /*    n o v a l u e                                                   */
  149. /*                                                                    */
  150. /*    Trap for uninitialized variables                                */
  151. /*--------------------------------------------------------------------*/
  152.  
  153. novalue:
  154. trace n
  155. signal off novalue;           /* Avoid nasty recursion         */
  156. say 'Uninitialized variable in line' sigl || ':';
  157. say sourceline( sigl );
  158.