686f63019e72e0e245b69144e2cf9d81a7930bc4
[mirror/dsa-puppet.git] / modules / motd / templates / motd.erb
1 #!/bin/bash
2
3 cat <<EOD
4
5 This device is for authorized users only.  All traffic on this device
6 is monitored and will be used as evidence for prosecutions.  By using
7 this machine you agree to abide by the Debian Machines Usage Policies
8 <URL:http://www.debian.org/devel/dmup>.
9
10 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
11
12 <%=
13 def wrap(s, width=78)
14   #s.gsub(/(.{1,#{width}})(\s+|\Z)/, "\\1\n ")
15   s.split("\n").map{ |x|
16     if (x.length > width) then
17       #x.gsub!(/(.{1,#{width}}) +(?=\S)/, "\\1\n ")
18       x.gsub!(/(.{1,#{width}})( +|\Z)/, "\\1\n ")
19     end
20     x
21   }.join("\n")+"\n"
22 end
23
24 def markup(l)
25   l = l.gsub(/\[\[(.*?)\|(.*?)\]\]/, '\2')
26   l = l.gsub(/\[\[(\*|-)?(.*?)\]\]/, '\2')
27   return l
28 end
29
30 if scope.lookupvar('site::nodeinfo')['ldap'].has_key?('architecture')
31   arch = scope.lookupvar('site::nodeinfo')['ldap']['architecture'][0]
32 else
33   arch = 'unknown'
34 end
35
36 purp = ''
37 if scope.lookupvar('site::nodeinfo').has_key?('nameinfo')
38   purp += " " + wrap(scope.lookupvar('site::nodeinfo')['nameinfo']) + "\n"
39 end
40
41 ninfo = scope.lookupvar('site::nodeinfo')
42
43 extra = 'Welcome to ' + fqdn
44 if (scope.lookupvar('site::nodeinfo')['ldap'].has_key?('purpose'))
45   p = scope.lookupvar('site::nodeinfo')['ldap']['purpose'].clone()
46   entries = ""
47
48   if p.delete('buildd')
49     entries += ", the Debian #{arch} build daemon"
50   end
51   if p.delete('porterbox') or classes.include?("porterbox")
52     entries += ", the Debian #{arch} porterbox"
53   end
54
55   if p.size() > 0
56     entries += (entries == "") ? ", " : ".  Also"
57     entries +="used for the following services:\n"
58     scope.lookupvar('site::nodeinfo')['ldap']['purpose'].sort.each do |l|
59       l = markup(l)
60       entries += "\t#{l}\n"
61     end
62   else
63     entries += ".\n"
64   end
65   extra += entries
66 else
67   extra += "."
68 end
69 purp += " " + wrap(extra) + "\n"
70
71 if (scope.lookupvar('site::nodeinfo')['ldap'].has_key?('physicalHost'))
72   if ninfo['ldap']['physicalHost'][0] =~ /ganeti/
73     phys_host = 'cluster'
74   else
75     phys_host = 'physical host'
76   end
77   purp += wrap(" This virtual server runs on the #{phys_host} #{ninfo['ldap']['physicalHost'][0]}, " +
78                "which is hosted at #{ninfo['hoster']['longname']}."
79                )
80 elsif scope.lookupvar('site::nodeinfo')['hoster']['name']
81   purp += wrap(" This server is hosted at #{ninfo['hoster']['longname']}.")
82 end
83
84
85 vms = []
86 scope.lookupvar('site::allnodeinfo').keys.sort.each do |node|
87   if scope.lookupvar('site::allnodeinfo')[node]['physicalHost'] and scope.lookupvar('site::allnodeinfo')[node]['physicalHost'].include?(fqdn)
88     vms << node
89   end
90 end
91 unless vms.empty?
92   purp += "\nThe following virtual machines run on this system:\n"
93   vms.each do |node|
94     purp += "\t- #{node}"
95     if scope.lookupvar('site::allnodeinfo')[node]['purpose']
96       purp += ":\n"
97       scope.lookupvar('site::allnodeinfo')[node]['purpose'].sort.each do |l|
98         l = markup(l)
99         purp += "\t    " + l + "\n"
100       end
101     else
102       purp += "\n"
103     end
104   end
105 end
106
107
108 if scope.lookupvar('::cluster')
109   purp += "\n This server is a node in ganeti cluster: "
110   purp += scope.lookupvar('::cluster').to_s + ":\n"
111   purp += "\t" + scope.lookupvar('::cluster_nodes').split.sort.map{ |x| x.split('.')[0] }.join(", ") + ".\n"
112
113   purp += ""
114   purp += "\tCurrently the master node is $(cat /var/lib/ganeti/ssconf_master_node).\n"
115   #nodes = scope.lookupvar('::cluster_nodes').sort
116   #nodes.each do |node|
117   #  purp += "\t" + node + "\n"
118   #end
119   #nodes.reject{|node| node.eql?(fqdn)}.each do |node|
120   #  purp += "\t" + node + "\n"
121   #  scope.lookupvar('site::allnodeinfo')[node]['ipHostNumber'].each do |ip|
122   #    purp += "\t\t" + ip + "\n"
123   #  end
124   #end
125 end
126
127
128 if classes.include?("porterbox")
129   purp += "\n " + wrap("Disk space on porter boxes is often limited.  Please respect your fellow porters by cleaning up after yourself and deleting schroots and source/build trees in your ~ as soon as feasible.  DSA reserves the right to recover disk space as necessary.  See <URL:https://dsa.debian.org/doc/schroot/> for a brief tutorial on using schroot.  There may be chroots for architectures other than #{arch} available, please list available chroots to check.")
130 end
131
132 if ninfo['not-bacula-client'] then
133   purp += "\n " + wrap("Note that this host is _NOT_ being backed up.  If you care about your data, run your own backups.")
134 end
135
136 if scope.lookupvar('site::nodeinfo').has_key?('footer')
137   purp += "\n" + wrap(scope.lookupvar('site::nodeinfo')['footer'])
138 end
139
140 purp
141 -%>
142 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
143
144 EOD
145 <%
146 # vim:set et:
147 # vim:set sts=2 ts=2:
148 # vim:set shiftwidth=2:
149 -%>