copy.ck 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. /*++
  2. Copyright (c) 2017 Minoca Corp.
  3. This file is licensed under the terms of the GNU General Public License
  4. version 3. Alternative licensing terms are available. Contact
  5. info@minocacorp.com for details. See the LICENSE file at the root of this
  6. project for complete licensing information.
  7. Module Name:
  8. copy.ck
  9. Abstract:
  10. This module implements package presentation based on copying files from
  11. storage into their final destination.
  12. Author:
  13. Evan Green 25-May-2017
  14. Environment:
  15. Chalk
  16. --*/
  17. //
  18. // ------------------------------------------------------------------- Includes
  19. //
  20. from santa.config import config;
  21. from santa.file import cptree, exists, mkdir, isdir;
  22. from santa.presentation import Presentation, PresentationError;
  23. //
  24. // --------------------------------------------------------------------- Macros
  25. //
  26. //
  27. // ---------------------------------------------------------------- Definitions
  28. //
  29. //
  30. // ------------------------------------------------------ Data Type Definitions
  31. //
  32. //
  33. // ----------------------------------------------- Internal Function Prototypes
  34. //
  35. //
  36. // -------------------------------------------------------------------- Globals
  37. //
  38. //
  39. // ------------------------------------------------------------------ Functions
  40. //
  41. class CopyPresentation is Presentation {
  42. var _parameters;
  43. function
  44. create (
  45. parameters
  46. )
  47. /*++
  48. Routine Description:
  49. This routine creates a new presentation layer and initializes this
  50. instance's internal variables to represent it.
  51. Arguments:
  52. parameters - Supplies a dictionary of creation parameters.
  53. Return Value:
  54. None.
  55. --*/
  56. {
  57. _parameters = parameters.copy();
  58. this.type = "copy";
  59. return;
  60. }
  61. function
  62. destroy (
  63. )
  64. /*++
  65. Routine Description:
  66. This routine destroys the presentation layer represented by this
  67. instance.
  68. Arguments:
  69. None.
  70. Return Value:
  71. None.
  72. --*/
  73. {
  74. return;
  75. }
  76. function
  77. load (
  78. parameters
  79. )
  80. /*++
  81. Routine Description:
  82. This routine initializes this instance to reflect the presentation
  83. identified by the given parameters.
  84. Arguments:
  85. parameters - Supplies a dictionary of parameters.
  86. Return Value:
  87. None.
  88. --*/
  89. {
  90. _parameters = parameters;
  91. this.type = "copy";
  92. return;
  93. }
  94. function
  95. save (
  96. )
  97. /*++
  98. Routine Description:
  99. This routine returns the dictionary of state and identification needed
  100. to restore information about this presentation layer by other instances
  101. of this class.
  102. Arguments:
  103. None.
  104. Return Value:
  105. Returns a dictionary of parameters to save describing this instance.
  106. --*/
  107. {
  108. return _parameters;
  109. }
  110. function
  111. addFiles (
  112. controlDirectory,
  113. realm,
  114. files,
  115. conffiles,
  116. root
  117. )
  118. /*++
  119. Routine Description:
  120. This routine adds a set of files into the environment.
  121. Arguments:
  122. controlDirectory - Supplies the directory containing the control and
  123. initial data of the package.
  124. realm - Supplies the realm being operated on.
  125. files - Supplies the files to add.
  126. conffiles - Suppiles the dictionary of files not to clobber if they
  127. exist, or to copy directly if they do not.
  128. root - Supplies the root directory to install to.
  129. Return Value:
  130. None.
  131. --*/
  132. {
  133. var dest;
  134. var destdir = realm.containment.outerPath(root);
  135. var srcfile;
  136. var srcdir = controlDirectory + "/data";
  137. if (destdir.endsWith("/")) {
  138. destdir = destdir[0..-1];
  139. }
  140. //
  141. // First create all the directories.
  142. //
  143. for (file in files) {
  144. srcfile = "/".join([srcdir, file]);
  145. if (isdir(srcfile)) {
  146. mkdir("/".join([destdir, file]));
  147. }
  148. }
  149. //
  150. // Now copy all the files.
  151. //
  152. for (file in files) {
  153. srcfile = "/".join([srcdir, file]);
  154. if (isdir(srcfile)) {
  155. continue;
  156. }
  157. dest = "/".join([destdir, file]);
  158. if ((conffiles.get(dest) != null) && (exists(dest))) {
  159. if (config.getKey("core.verbose")) {
  160. Core.print("Skipping pre-existing configuration file: %s" %
  161. dest);
  162. }
  163. continue;
  164. }
  165. cptree(srcfile, dest);
  166. }
  167. return;
  168. }
  169. }
  170. //
  171. // Define the globals needed so the module loader can pick up this class.
  172. //
  173. var description = "Copy-based installation";
  174. var presentation = CopyPresentation;
  175. //
  176. // --------------------------------------------------------- Internal Functions
  177. //