summaryrefslogtreecommitdiff
path: root/cfengine/cf.services.file
blob: 38bd0a04fe7c5f87a727542c2b62108f1585589f (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. 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-$(fqhost).bat
  108. #
  109. LocateLineMatching "^[;[:blank:]]*logon script[[:blank:]]*=.*"
  110. BeginGroupIfNoLineMatching "^[[:blank:]]*logon script[[:blank:]]*=[[:blank:]]*logon-$(fqhost).bat[[:blank:]]*"
  111. ReplaceLineWith ' logon script = logon-$(fqhost).bat'
  112. EndGroup
  113. CatchAbort
  114. BeginGroupIfNoMatch "^[[:blank:]]*logon script[[:blank:]]*=[[:blank:]]*logon-$(fqhost).bat[[:blank:]]*"
  115. InsertLine ' logon script = logon-$(fqhost).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-$(fqhost).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. AutoCreate
  187. BeginGroupIfFileIsNewer "/etc/local-COMMON/samba/netlogon/logon-$(fqhost).bat"
  188. EmptyEntireFilePlease
  189. Append "@echo off"
  190. Append "rem DO NOT EDIT - auto-created by cfengine $(date)"
  191. InsertFile "/etc/local-COMMON/samba/netlogon/logon-$(fqhost).bat"
  192. EndGroup
  193. FixEndOfLine "dos"
  194. }
  195. #
  196. # Check if the shares definitions have changed
  197. #
  198. { /etc/samba/smb-shares.conf
  199. AutoCreate
  200. BeginGroupIfFileIsNewer "/etc/local-COMMON/file-$(fqhost).m4"
  201. EmptyEntireFilePlease
  202. SetLine "# DO NOT EDIT - auto-created by cfengine $(date)"
  203. PrependIfNoLineMatching "^# .* cfengine .*"
  204. RunScript "/etc/local-COMMON/cfengine/script.update_sambashares.sh"
  205. EndGroup
  206. DefineClasses "samba_reload"
  207. }
  208. lprng::
  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.$(fqhost)"
  218. SetLine "# DO NOT EDIT - auto-created by cfengine $(date)"
  219. PrependIfNoLineMatching "^# .* cfengine .*"
  220. EmptyEntireFilePlease
  221. InsertFile "/etc/local-COMMON/printcap.$(fqhost)"
  222. EndGroup
  223. DefineClasses "lprng_reload"
  224. }
  225. samba_reload::
  226. { /etc/samba/smb.conf
  227. LocateLineMatching "^; EDITED BY CFENGINE .*"
  228. ReplaceAll '; EDITED BY CFENGINE .*$' With '; EDITED BY CFENGINE $(date)'
  229. CatchAbort
  230. BeginGroupIfNoMatch "^; EDITED BY CFENGINE .*"
  231. Append '; EDITED BY CFENGINE $(date)'
  232. EndGroup
  233. }
  234. processes:
  235. "smbd" restart "/etc/init.d/samba restart"
  236. "afpd" restart "/etc/init.d/netatalk restart"
  237. shellcommands:
  238. samba_reload::
  239. "/etc/init.d/samba force-reload"
  240. netatalk_reload::
  241. "/etc/init.d/netatalk force-reload"
  242. lprng_reload::
  243. "/etc/init.d/lprng force-reload"
  244. cups_reload::
  245. "/etc/init.d/cups force-reload"