summaryrefslogtreecommitdiff
path: root/cfengine/cf.services.file
blob: 549f485fa6a54a9f88bc504203967f650ea8ddc6 (plain)
  1. control:
  2.     AddInstallable = ( samba samba_reload netatalk netatalk_reload lprng lprng_reload cups cups_reload )
  3. classes:
  4. #
  5. # Determine if this is a samba server, netatalk server or both, and define
  6. # classes based on that.
  7. #
  8. samba = ( `/usr/bin/test -x /usr/sbin/smbd` )
  9. netatalk = ( `/usr/bin/test -x /usr/sbin/afpd` )
  10. #
  11. # Determine which print system is in use, and define classes based on that.
  12. # We only support lprng and cups
  13. #
  14. lprng = ( `/usr/bin/test -x /usr/sbin/lpd` )
  15. cups = ( `/usr/bin/test -x /usr/sbin/cupsd` )
  16. import:
  17. samba::
  18. #
  19. # Import the shares definition for this site. This is a cfengine file!
  20. #
  21. /etc/local-COMMON/samba/smb-shares-$(site).conf
  22. lprng|cups::
  23. #
  24. # Set up a printershare only if there's some printersoftware installed
  25. #
  26. /etc/local-COMMON/samba/smb-printers.conf
  27. editfiles:
  28. samba.lprng|samba.cups::
  29. { /etc/samba/smb.conf
  30. AppendIfNoSuchLine "include = /etc/samba/smb-printers.conf"
  31. }
  32. samba::
  33. { /etc/samba/smb.conf
  34. #
  35. # Global stuff
  36. #
  37. # Remove share declarations from main smb.conf. It is split
  38. # up in the following files:
  39. # - smb.conf
  40. # - smb-shares-$(site).conf
  41. # - smb-printers.conf
  42. #
  43. # DeleteLinesAfterThisMatching "^\[homes\]$(n)*.*"
  44. # ResetSearch "1"
  45. # CatchAbort
  46. # ResetSearch "1"
  47. #
  48. # Append the include lines for the files decribed above
  49. #
  50. BeginGroupIfFileExists "/etc/local-COMMON/samba/smb-shares-$(site).conf"
  51. AppendIfNoSuchLine "include = /etc/samba/smb-shares-$(site).conf"
  52. EndGroup
  53. ResetSearch "1"
  54. #
  55. # workgroup = $(site)
  56. #
  57. LocateLineMatching "^[;[:blank:]]*workgroup[[:blank:]]*=.*"
  58. BeginGroupIfNoLineMatching '^[[:blank:]]*workgroup[[:blank:]]*=[[:blank:]]*$(site)[[:blank:]]*'
  59. ReplaceLineWith ' workgroup = $(site)'
  60. EndGroup
  61. CatchAbort
  62. BeginGroupIfNoMatch '^[[:blank:]]*workgroup[[:blank:]]*=[[:blank:]]*$(site)[[:blank:]]*'
  63. InsertLine ' workgroup = $(site)'
  64. EndGroup
  65. #
  66. # wins support = yes
  67. #
  68. LocateLineMatching "^[;[:blank:]]*wins support[[:blank:]]*=.*"
  69. BeginGroupIfNoLineMatching "^[[:blank:]]*wins support[[:blank:]]*=[[:blank:]]*yes[[:blank:]]*"
  70. ReplaceLineWith ' wins support = yes'
  71. EndGroup
  72. CatchAbort
  73. BeginGroupIfNoMatch "^[[:blank:]]*wins support[[:blank:]]*=[[:blank:]]*yes[[:blank:]]*"
  74. InsertLine ' wins support = yes'
  75. EndGroup
  76. #
  77. # os level = 65
  78. #
  79. LocateLineMatching "^[;[:blank:]]*os level[[:blank:]]*=.*"
  80. BeginGroupIfNoLineMatching "^[[:blank:]]*os level[[:blank:]]*=[[:blank:]]*65[[:blank:]]*"
  81. ReplaceLineWith ' os level = 65'
  82. EndGroup
  83. CatchAbort
  84. BeginGroupIfNoMatch "^[[:blank:]]*os level[[:blank:]]*=[[:blank:]]*65[[:blank:]]*"
  85. InsertLine ' os level = 65'
  86. EndGroup
  87. #
  88. # domain master = yes
  89. #
  90. LocateLineMatching "^[;[:blank:]]*domain master[[:blank:]]*=.*"
  91. BeginGroupIfNoLineMatching "^[[:blank:]]*domain master[[:blank:]]*=[[:blank:]]*yes[[:blank:]]*"
  92. ReplaceLineWith ' domain master = yes'
  93. EndGroup
  94. CatchAbort
  95. BeginGroupIfNoMatch "^[[:blank:]]*domain master[[:blank:]]*=[[:blank:]]*yes[[:blank:]]*"
  96. InsertLine ' domain master = yes'
  97. EndGroup
  98. #
  99. # local master = yes
  100. #
  101. LocateLineMatching "^[;[:blank:]]*local master[[:blank:]]*=.*"
  102. BeginGroupIfNoLineMatching "^[[:blank:]]*local master[[:blank:]]*=[[:blank:]]*yes"
  103. ReplaceLineWith ' local master = yes'
  104. EndGroup
  105. CatchAbort
  106. BeginGroupIfNoMatch "^[[:blank:]]*local master[[:blank:]]*=[[:blank:]]*yes[[:blank:]]*"
  107. InsertLine ' local master = yes'
  108. EndGroup
  109. #
  110. # logon drive = Z:
  111. #
  112. LocateLineMatching "^[;[:blank:]]*logon drive[[:blank:]]*=.*"
  113. BeginGroupIfNoLineMatching "^[[:blank:]]*logon drive[[:blank:]]*=[[:blank:]]*Z:[[:blank:]]*"
  114. ReplaceLineWith ' logon drive = Z:'
  115. EndGroup
  116. CatchAbort
  117. BeginGroupIfNoMatch "^[[:blank:]]*logon drive[[:blank:]]*=[[:blank:]]*Z:[[:blank:]]*"
  118. InsertLine ' logon drive = Z:'
  119. EndGroup
  120. #
  121. # logon script = logon-$(site).bat
  122. #
  123. LocateLineMatching "^[;[:blank:]]*logon script[[:blank:]]*=.*"
  124. BeginGroupIfNoLineMatching "^[[:blank:]]*logon script[[:blank:]]*=[[:blank:]]*logon-$(site).bat[[:blank:]]*"
  125. ReplaceLineWith ' logon script = logon-$(site).bat'
  126. EndGroup
  127. CatchAbort
  128. BeginGroupIfNoMatch "^[[:blank:]]*logon script[[:blank:]]*=[[:blank:]]*logon-$(site).bat[[:blank:]]*"
  129. InsertLine ' logon script = logon-$(site).bat'
  130. EndGroup
  131. #
  132. # domain logons = yes
  133. #
  134. LocateLineMatching "^[;[:blank:]]*domain logons[[:blank:]]*=.*"
  135. BeginGroupIfNoLineMatching "^[[:blank:]]*domain logons[[:blank:]]*=[[:blank:]]*yes[[:blank:]]*"
  136. ReplaceLineWith ' domain logons = yes'
  137. EndGroup
  138. CatchAbort
  139. BeginGroupIfNoMatch "^[[:blank:]]*domain logons[[:blank:]]*=[[:blank:]]*yes[[:blank:]]*"
  140. InsertLine ' domain logons = yes'
  141. EndGroup
  142. #
  143. # logon home = \\%N\USERPROFILES\%U
  144. #
  145. LocateLineMatching "^[;[:blank:]]*logon home[[:blank:]]*=.*"
  146. BeginGroupIfNoLineMatching "^[[:blank:]]*logon home[[:blank:]]*=[[:blank:]]*[\\][\\]%N[\\]USERPROFILES[\\]%U[[:blank:]]*"
  147. ReplaceLineWith ' logon home = \\%N\USERPROFILES\%U'
  148. EndGroup
  149. CatchAbort
  150. BeginGroupIfNoMatch "^[[:blank:]]*logon home[[:blank:]]*=[[:blank:]]*[\\][\\]%N[\\]USERPROFILES[\\]%U[[:blank:]]*"
  151. InsertLine ' logon home = \\%N\USERPROFILES\%U'
  152. EndGroup
  153. #
  154. # preferred master = yes
  155. #
  156. LocateLineMatching "^[;[:blank:]]*preferred master[[:blank:]]*=.*"
  157. BeginGroupIfNoLineMatching "^[[:blank:]]*preferred master[[:blank:]]*=[[:blank:]]*yes[[:blank:]]*"
  158. ReplaceLineWith ' preferred master = yes'
  159. EndGroup
  160. CatchAbort
  161. BeginGroupIfNoMatch "^[[:blank:]]*preferred master[[:blank:]]*=[[:blank:]]*yes[[:blank:]]*"
  162. InsertLine ' preferred master = yes'
  163. EndGroup
  164. DefineClasses "samba_reload"
  165. }
  166. #
  167. # Batch file for mounting shares automatically
  168. #
  169. { /etc/samba/netlogon/logon-$(site).bat
  170. #
  171. # We don't make this file dynamically, but instead we copy the contents
  172. # of a master file, but only if it's newer than the one installed.
  173. #
  174. BeginGroupIfFileIsNewer "/etc/local-COMMON/samba/netlogon/logon-$(site).bat"
  175. AutoCreate
  176. EmptyEntireFilePlease
  177. InsertFile "/etc/local-COMMON/samba/netlogon/logon-$(site).bat"
  178. Append "rem Edited by cfengine $(date)"
  179. EndGroup
  180. DefineClasses "samba_reload"
  181. }
  182. lprng::
  183. { /etc/samba/smb.conf
  184. #
  185. # printing = lprng
  186. #
  187. ResetSearch "1"
  188. LocateLineMatching "^[;[:blank:]]*printing[[:blank:]]*=.*"
  189. BeginGroupIfNoLineMatching '^[[:blank:]]*printing[[:blank:]]*=[[:blank:]]*lprng[[:blank:]]*'
  190. ReplaceLineWith ' printing = lprng'
  191. EndGroup
  192. CatchAbort
  193. BeginGroupIfNoMatch '^[[:blank:]]*printing[[:blank:]]*=[[:blank:]]*lprng[[:blank:]]*'
  194. InsertLine ' printing = lprng'
  195. EndGroup
  196. DefineClasses "samba_reload"
  197. }
  198. #
  199. # Printer configuration stuff
  200. #
  201. { /etc/printcap
  202. #
  203. # We don't make the printcap dynamically, but instead we copy the contents
  204. # of a master file, but only if it's newer than the one installed.
  205. #
  206. BeginGroupIfFileIsNewer "/etc/local-COMMON/printcap.$(site)"
  207. EmptyEntireFilePlease
  208. InsertFile "/etc/local-COMMON/printcap.$(site)"
  209. Append "# Edited by cfengine $(date)"
  210. EndGroup
  211. DefineClasses "lprng_reload"
  212. }
  213. samba_reload::
  214. { /etc/samba/smb.conf
  215. LocateLineMatching "^; EDITED BY CFENGINE .*"
  216. ReplaceAll '; EDITED BY CFENGINE .*$' With '; EDITED BY CFENGINE $(date)'
  217. CatchAbort
  218. BeginGroupIfNoMatch "^; EDITED BY CFENGINE .*"
  219. Append '; EDITED BY CFENGINE $(date)'
  220. EndGroup
  221. }
  222. processes:
  223. "smbd" restart "/etc/init.d/samba restart"
  224. "afpd" restart "/etc/init.d/netatalk restart"
  225. shellcommands:
  226. samba_reload::
  227. "/etc/init.d/samba force-reload"
  228. netatalk_reload::
  229. "/etc/init.d/netatalk force-reload"
  230. lprng_reload::
  231. "/etc/init.d/lprng force-reload"
  232. cups_reload::
  233. "/etc/init.d/cups force-reload"