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