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