home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / GENFLD.ZIP / GENFLDR.CMD
OS/2 REXX Batch file  |  1993-02-19  |  15KB  |  272 lines

  1. /* Generic Folder Builder                                                    */
  2. /* Version 1.4                                                               */
  3. /*                                                                           */
  4. /* Builds folder and program objects on the OS/2 desktop based upon Novell   */
  5. /* group membership.  All previous objects created by this program are       */
  6. /* replaced by new ones or deleted if not in user's groups.                  */ 
  7. /*                                                                           */
  8. /* Novell group membership is determined by calling WHOAMI.EXE, which is     */
  9. /* assumed to be located in the PATH.  Map Z: to \PUBLIC\OS2, then add Z:    */
  10. /* to your PATH in CONFIG.SYS.                                               */
  11. /*                                                                           */
  12. /* This program requires one parameter and has an optional second parameter. */
  13. /*  Required: server name                                                    */
  14. /*  Optional: verbose flag (only checks for existence of third parameter)    */
  15. /* Verbose mode displays status of all object creations and deletions.       */
  16. /* Format:                                                                   */
  17. /*  GENFLDR server [verbose]                                                 */
  18. /* Examples:                                                                 */
  19. /*  Regular:                                                                 */
  20. /*   GENFLDR pcatd                                                           */
  21. /*  Verbose:                                                                 */
  22. /*   GENFLDR pcatd x                                                         */
  23. /*                                                                           */
  24. /* Folder and program objects are defined in a data file named OBJECTS.DAT.  */
  25. /* Each line in the data file represents one object and uses the format:     */
  26. /*    GROUP~LOCATION~CLASSNAME~TITLE~OBJECTID~SETUP~INITCMD                  */
  27. /* where these values, except for INITCMD, are defined in the CRTOBJ.TXT     */
  28. /* document.  INITCMD is the name of a batch file or program to run when the */
  29. /* object is created.  This command is run asynchronously from this file.    */
  30. /*                                                                           */
  31. /* Below are some sample records.                                            */
  32. /*                                                                           */
  33. /*  Create a folder named "LAN Folder" for members of group EVERYONE         */
  34. /*    EVERYONE~<WP_DESKTOP>~WPFolder~LAN Folder~<LAN_FOLDER>                 */
  35. /*                                                                           */
  36. /*  Create a program object for SYSCON to run in a window for members of     */
  37. /*  group EVERYONE in the previously created "LAN Folder".                   */
  38. /*    EVERYONE~<LAN_FOLDER>~WPProgram~Syscon~<LAN_SYSCON>~EXENAME=Z:SYSCON.EXE;PROGTYPE=WINDOWABLEVIO;  */
  39. /*                                                                           */
  40. /*  Create a program object for a DOS application that requires a customized */
  41. /*  batch to be created for the user.  The DOS batch file is SPECIAL.BAT and */
  42. /*  is generated by GENSPEC.CMD.                                             */
  43. /*    EVERYONE~<LAN_FOLDER>~WPProgram~Special~<LAN_SPECIAL>~EXENAME=D:\SPECIAL.BAT;PROGTYPE=WINDOWEDVDM;~GENSPEC.CMD */
  44. /*                                                                           */
  45. /*  Create a program object for a DOS application that requires multiple     */
  46. /*  DOS_DEVICE or DOS_VERSION statements.  The WPS replaces commas with      */
  47. /*  newlines, so use commas to separate the multiple entries.  To include a  */
  48. /*  comma as part of the value in DOS_VERSION, prefix it with a caret (^).   */
  49. /*    EVERYONE~<LAN_FOLDER>~WPProgram~3D-Data~<LAN_3DDATA>~EXENAME=D:\3D\3DDATA.EXE;PROGTYPE=WINDOWEDVDM;~SET DOS_DEVICE=C:\OS2\MDOS\LPTDD.SYS,C:\OS2\MDOS\ANSI.SYS,D:\3D\DATAGLOV.SYS;SET DOS_VERSION=BOGUS.EXE^,5^,00^,255;  */
  50. /*                                                                           */
  51. /*  To include comments, just begin the line with a tilde (~).               */
  52. /*    ~Create LAN Folder                                                     */
  53. /*                                                                           */
  54. /*  If a program or folder will no longer be included in the login process,  */
  55. /*  leave it in the data file, but give it a non-existent group name.  This  */
  56. /*  will still delete it, but won't create a new object for it.              */
  57. /*    REMOVED~<LAN_FOLDER>~WPProgram~WP 5.0~<LAN_WP50>                       */
  58. /*                                                                           */
  59. /* General Notes:                                                            */
  60. /*                                                                           */
  61. /*  If a folder is destroyed, then all of its contents are also destroyed.   */
  62. /*                                                                           */
  63. /*  The current version of the NetWare Requester contains a "feature" that   */
  64. /*  makes setting the NETWARE_RESOURCES tricky to use.  The setting is a     */
  65. /*  fixed length field, unlike all the other DOS Session settings.  The      */
  66. /*  field has a size of 7 characters, which is equal to the length of its    */
  67. /*  largest value, PRIVATE.  To change the setting to GLOBAL or NONE, append */
  68. /*  1 or 3 spaces.                                                           */
  69. /*     Example: SET NETWARE_RESOURCES=NONE   ;                               */
  70. /*                                                                           */
  71. /*  Apparently there is an upper limit on the setup string length imposed by */
  72. /*  REXX and/or OS/2.  Setup strings must be less than 234 characters to     */
  73. /*  create the objects correctly.  The first setup string that is too long   */
  74. /*  will cause subsequent creates to fail also.                              */
  75. /*  NOTE: This is listed as fixed in the Service Pack.                       */
  76. /*                                                                           */
  77. /* Version History                                                           */
  78. /*  1.0   Initial version .                                                  */
  79. /*  1.1   Eliminated need for temporary file and used WHOAMI to determine    */
  80. /*        group membership.                                                  */
  81. /*  1.1a  Changed brute force method of deleting all objects to just         */
  82. /*        deleting objects that are not created.                             */
  83. /*  1.2   Added data file option for an initialization command to be run     */
  84. /*        when the object is created.                                        */
  85. /*  1.3   Added translation of the | (vertical bar) character to hex 0A in   */
  86. /*        setup string to allow multiple values for settings like DEVICE or  */
  87. /*        VERSION.                                                           */
  88. /*  1.4   Finally got an answer on why the Service Pack handles commas       */
  89. /*        differently than previous releases.  Commas are translated to      */
  90. /*        newlines, so to use a comma in setting DOS_VERSION, prefix it with */
  91. /*        the caret escape character (e.g. ^,).  No code change, just        */
  92. /*        updated documentation.                                             */
  93. /*                                                                           */
  94. /* Lee S. Fields                                                             */
  95.  
  96. /*trace('I')*/
  97.  
  98. /* verify at least one parameter, server name, was passed */
  99. parse upper arg server verbose
  100. if (server = '') then
  101.   ErrorMessage('Server name is required.')
  102.  
  103. /* check for verbose parameter */
  104. if verbose = '' then verbose = 0 
  105. else verbose = 1
  106.  
  107. /* read user's group membership */
  108. call readgroups server
  109.  
  110. /* Load REXXUTIL */
  111. call rxfuncadd sysloadfuncs, rexxutil, sysloadfuncs
  112. call sysloadfuncs
  113.  
  114. /* load the object data from the specified file, OBJECTS.DAT */
  115. call LoadObj 'objects.dat'
  116.  
  117. say 'Managing LAN objects...'
  118.  
  119. /* create all objects */
  120. do j = 1 to objectcount
  121.   if MemberOf(groups.j) then do
  122.     call BldObj classnames.j, titles.j, locations.j, 'OBJECTID='objectids.j';'setups.j
  123.     if initcmds.j \= '' then '@start' initcmds.j
  124.     else nop
  125.     end
  126.   else
  127.     call DelObj objectids.j
  128. end
  129.  
  130. Exit
  131.  
  132.  
  133.  
  134. /*****************************************************************************/
  135. /* Subroutines:                                                              */
  136. /*****************************************************************************/
  137.  
  138. /*****************************************************************************/
  139. /* BldObj - Build object                                                     */
  140. /*                                                                           */
  141. /* Parameters: classname, title, location, and setup                         */
  142. /* Uses:       verbose                                                       */
  143. /* Modifies:                                                                 */
  144. /* Returns:                                                                  */
  145. /*****************************************************************************/
  146. BldObj: procedure expose verbose
  147. if verbose then call charout ,'Building: 'arg(2)
  148.  
  149. /* Build object using REPLACE as duplicateflag */
  150. result = SysCreateObject(arg(1), arg(2), arg(3), arg(4), 'R')
  151.  
  152. if verbose then do 
  153.   If result=1 Then call charout ,'...   Object created!'
  154.   Else             call charout ,'...   Not created! Return code='result
  155.  
  156.   Say '';
  157. end
  158. Return
  159.  
  160.  
  161. /*****************************************************************************/
  162. /* DelObj - Destroy object                                                   */
  163. /*                                                                           */
  164. /* Parameters: full path name or object id                                   */
  165. /* Uses:       verbose                                                       */
  166. /* Modifies:                                                                 */
  167. /* Returns:                                                                  */
  168. /*****************************************************************************/
  169. DelObj: procedure expose verbose
  170. if verbose then call charout ,'Destroying: 'arg(1)
  171.  
  172. result = SysDestroyObject(arg(1))
  173.  
  174. if verbose then do
  175.   If result=1 Then call charout ,'...   Object destroyed!'
  176.   Else             call charout ,'...   Not destroyed! Return code='result
  177.   Say '';
  178. end
  179. Return
  180.  
  181.  
  182. /*****************************************************************************/
  183. /* LoadObj - Load object data                                                */
  184. /*                                                                           */
  185. /* Parameters: file name                                                     */
  186. /* Uses:       objectcount, groups, classnames, titles, locations, objectids */
  187. /*             setups initcmds                                               */
  188. /* Modifies:   objectcount, groups, classnames, titles, locations, objectids */
  189. /*             setups initcmds                                               */
  190. /* Returns:                                                                  */
  191. /*****************************************************************************/
  192. LoadObj: procedure expose groups. classnames. titles. locations. objectids. setups. initcmds. objectcount
  193. objectfile = arg(1)
  194. /* verify name passed and file existence */
  195. if objectfile = '' then 
  196.   ErrorMessage('Data file of objects not specified.')
  197. if stream(objectfile,'c','query exists') = '' then 
  198.   ErrorMessage('Unable to open object data file')
  199.  
  200. objectcount = 0
  201. /* open file */
  202. call linein objectfile 1 0
  203. do while lines(objectfile)
  204.   objectcount = objectcount + 1
  205.   parse value linein(objectfile) with groups.objectcount '~' locations.objectcount '~' classnames.objectcount '~' titles.objectcount '~' objectids.objectcount '~' setups.objectcount '~' initcmds.objectcount
  206.   if groups.objectcount = '' 
  207.     then objectcount = objectcount - 1
  208.     else setups.objectcount = translate(setups.objectcount, '0A'X, '|')
  209. end
  210. call lineout objectfile /* close file */
  211. return
  212.  
  213.  
  214. /*****************************************************************************/
  215. /* ReadGroups - Reads list of user's groups                                  */
  216. /*                                                                           */
  217. /* Parameters: server                                                        */
  218. /* Uses:       usergroups                                                    */
  219. /* Modifies:   usergroups                                                    */
  220. /* Returns:                                                                  */
  221. /* Note:       Requires access to GROUPS.EXE                                 */
  222. /*****************************************************************************/
  223. ReadGroups: procedure expose usergroups.
  224. /* clear queue */
  225. '@rxqueue /clear'
  226.  
  227. /* run GROUPS to get group list in queue */
  228. '@whoami' arg(1) '/G |RXQUEUE'
  229.  
  230. counter = 1
  231. do i = 1 to lines("QUEUE:")
  232.   parse value linein("QUEUE:") with usergroups.counter stuff .
  233.   if stuff = '' then do
  234.     usergroups.0 = counter
  235.     counter = counter + 1
  236.   end
  237. end
  238.  
  239. if counter = 1 then
  240.   ErrorMessage('Unable to determine group membership.')
  241.  
  242. return
  243.  
  244.  
  245. /*****************************************************************************/
  246. /* MemberOf - Tests if user is member of a group                             */
  247. /*                                                                           */
  248. /* Parameters: test group                                                    */
  249. /* Uses:       usergroups                                                    */
  250. /* Modifies:                                                                 */
  251. /* Returns:    1 if member, 0 if not                                         */
  252. /*****************************************************************************/
  253. MemberOf: procedure expose usergroups.
  254. do i = 1 to usergroups.0
  255.   if usergroups.i = arg(1) then return 1
  256. end
  257. return 0
  258.  
  259.  
  260. /*****************************************************************************/
  261. /* ErrorMessage - Display error message and exit                             */
  262. /*                                                                           */
  263. /* Parameters: error message                                                 */
  264. /* Uses:                                                                     */
  265. /* Modifies:                                                                 */
  266. /* Returns:    DOES NOT RETURN                                               */
  267. /*****************************************************************************/
  268. ErrorMessage: procedure
  269. say arg(1)
  270. say 'No objects loaded, contact your LAN Administrator.'
  271. exit
  272.