summaryrefslogtreecommitdiff
path: root/cfengine/cf.services.file
blob: 20b094b6e826ab835dd7757550ea0aee2ae6fb88 (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. # Append the include lines for the shares definition file
  163. #
  164. AppendIfNoSuchLine "include = /etc/samba/smb-shares-$(site).conf"
  165. DefineClasses "samba_reload"
  166. }
  167. #
  168. # Batch file for mounting shares automatically
  169. #
  170. { /etc/samba/netlogon/logon-$(site).bat
  171. #
  172. # We don't make this file dynamically, but instead we copy the contents
  173. # of a master file, but only if it's newer than the one installed.
  174. #
  175. BeginGroupIfFileIsNewer "/etc/local-COMMON/samba/netlogon/logon-$(site).bat"
  176. AutoCreate
  177. EmptyEntireFilePlease
  178. InsertFile "/etc/local-COMMON/samba/netlogon/logon-$(site).bat"
  179. Append "rem Edited by cfengine $(date)"
  180. FixEndOfLine "dos"
  181. EndGroup
  182. DefineClasses "samba_reload"
  183. }
  184. #
  185. # Check if the shares definitions have changed
  186. #
  187. { /etc/samba/smb-shares.conf
  188. BeginGroupIfFileIsNewer "/etc/local-COMMON/file-$(fqhost).m4"
  189. AutoCreate
  190. EndGroup
  191. DefineClasses "samba_rebuild_shares:samba_reload"
  192. }
  193. lprng::
  194. #
  195. # Printer configuration stuff
  196. #
  197. { /etc/printcap
  198. #
  199. # We don't make the printcap dynamically, but instead we copy the contents
  200. # of a master file, but only if it's newer than the one installed.
  201. #
  202. BeginGroupIfFileIsNewer "/etc/local-COMMON/printcap.$(site)"
  203. EmptyEntireFilePlease
  204. InsertFile "/etc/local-COMMON/printcap.$(site)"
  205. Append "# Edited by cfengine $(date)"
  206. EndGroup
  207. DefineClasses "lprng_reload"
  208. }
  209. samba_reload::
  210. { /etc/samba/smb.conf
  211. LocateLineMatching "^; EDITED BY CFENGINE .*"
  212. ReplaceAll '; EDITED BY CFENGINE .*$' With '; EDITED BY CFENGINE $(date)'
  213. CatchAbort
  214. BeginGroupIfNoMatch "^; EDITED BY CFENGINE .*"
  215. Append '; EDITED BY CFENGINE $(date)'
  216. EndGroup
  217. }
  218. processes:
  219. "smbd" restart "/etc/init.d/samba restart"
  220. "afpd" restart "/etc/init.d/netatalk restart"
  221. shellcommands.shares:
  222. samba_rebuild_shares::
  223. "m4 -DFQDN=$(fqhost) /etc/local-COMMON/samba/smb-shares.conf.m4 > /etc/samba/smb-shares.conf"
  224. shellcommands:
  225. samba_reload::
  226. "/etc/init.d/samba force-reload"
  227. netatalk_reload::
  228. "/etc/init.d/netatalk force-reload"
  229. lprng_reload::
  230. "/etc/init.d/lprng force-reload"
  231. cups_reload::
  232. "/etc/init.d/cups force-reload"